Repository navigation
feat: [CMPS-1448] opt-in relative paths and attribute templates for uploads - #255
Draft
bartdegoede-cohere wants to merge 5 commits into
Draft
bartdegoede-cohere wants to merge 5 commits into
bartdegoede-cohere wants to merge 5 commits into
Conversation
…ploads
UploadOptions gains keep_paths, which uploads each file under its path
relative to the source instead of only its name, and attribute_templates,
which adds per-file attributes built from {relative_path} and {name}.
Both default to today's behaviour and are saved with the job for resume.
Co-authored-by: North Code <noreply@cohere.com>
|
|
Co-authored-by: North Code <noreply@cohere.com>
Co-authored-by: North Code <noreply@cohere.com>
…D when opted in With keep_paths or attribute_templates set, a document's ID now also covers its relative path and rendered attributes. The same content in two folders becomes two documents instead of one that keeps only the first path, and a moved file or a changed template uploads a new document that prune can replace the old one with. With neither option set, IDs are unchanged. Co-authored-by: North Code <noreply@cohere.com>
Co-authored-by: North Code <noreply@cohere.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
[👾 Bart's BotMan™ · North Code · claude-opus-5-5]
What
Two opt-in
UploadOptionsfields for the uploads extension (models.py#L182-L208):keep_paths(defaultFalse): upload each file under its path relative to the source, such asprojects/search/README.md, instead of only its name.attribute_templates(default{}): per-file document attributes built from the file's{relative_path}and{name}, for example{"url": "https://github.com/org/repo/blob/main/{relative_path}"}. Templates may only use those two bare fields; anything else is rejected when the options are built.When either is set, the path and the rendered attributes become part of the document ID (
identity.py#L17-L45). With the defaults, nothing changes: base name, no attributes, and the same document IDs as before.Why
Directory uploads send only the base name, so documents with the same name from different folders can't be told apart, and nothing in a result points back to the source file. Compass already treats
pathas a path and derivesorigin.filenamefrom it.The document ID was content plus parser options only. That was fine while the only per-file data was the base name, but not once each document carries its own path and URL:
LICENSE, an empty__init__.py) was one document, which kept the path and URL of whichever file was uploaded first.prunecouldn't catch it, since the ID was still in the source.How the document ID is built
flowchart LR bytes["file content<br/>(SHA-256)"] --> id(["document ID"]) parser["parser_config"] --> id path["relative path"] -. "keep_paths=True" .-> id attrs["rendered attributes"] -. "attribute_templates set" .-> idkeep_paths/ templatesa/andb/prune=Truedeletes the old oneBehaviour to know
prune=True, the old documents are deleted.origin.filenameis still the base name; Compass derives it frompath.upload resumekeeps them, and jobs saved without them still load.Testing
keep_pathson and off, templates rendered per file, template validation, a JSON round trip, options saved without the new fields, document IDs unchanged without the options (pinned to the previous formula), and the same content in two folders becoming one or two documents depending on the options.README.mdfiles from different folders, uploaded withkeep_paths=Trueand aurltemplate. Each search hit hadpath: alpha/README.mdorbeta/README.md,origin.filename: README.md, and its owncontent.url. Throughcohere-compass-mcp, the agent sees the path and the URL inretrieved_chunk_fields.Not in this PR
compass upload directory(--keep-paths,--attribute KEY=TEMPLATE), which will be a compass-cli PR once this one is released.