Skip to content

feat: [CMPS-1448] opt-in relative paths and attribute templates for uploads - #255

Draft
bartdegoede-cohere wants to merge 5 commits into
mainfrom
bart/feat/cmps-1448-keep-paths
Draft

bartdegoede-cohere wants to merge 5 commits into
mainfrom
bart/feat/cmps-1448-keep-paths

Conversation

@bartdegoede-cohere

@bartdegoede-cohere bartdegoede-cohere commented Nov 19, 2026 •

Copy link
Copy Markdown

[👾 Bart's BotMan™ · North Code · claude-opus-5-5]

What

Two opt-in UploadOptions fields for the uploads extension (models.py#L182-L208):

  • keep_paths (default False): upload each file under its path relative to the source, such as projects/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 path as a path and derives origin.filename from 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:

  • The same content in two folders (a LICENSE, an empty __init__.py) was one document, which kept the path and URL of whichever file was uploaded first.
  • A moved file kept its ID, so it was skipped as already indexed and kept its old path and a URL that no longer resolves. prune couldn'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" .-> id
Loading
Defaults With keep_paths / templates
Same content in a/ and b/ one document two documents, each with its own path and URL
File moved or renamed skipped as already indexed new document; prune=True deletes the old one
Template changed n/a every document re-uploaded with the new attributes
Existing documents same IDs as before not affected until an upload opts in

Behaviour to know

  • Turning either option on for an index that was uploaded without it re-uploads every file under its new ID. With prune=True, the old documents are deleted.
  • origin.filename is still the base name; Compass derives it from path.
  • Both fields are saved with the job, so upload resume keeps them, and jobs saved without them still load.

Testing

  • Unit tests: keep_paths on 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.
  • Checked against a local Compass: two README.md files from different folders, uploaded with keep_paths=True and a url template. Each search hit had path: alpha/README.md or beta/README.md, origin.filename: README.md, and its own content.url. Through cohere-compass-mcp, the agent sees the path and the URL in retrieved_chunk_fields.

Not in this PR

  • CLI flags for compass upload directory (--keep-paths, --attribute KEY=TEMPLATE), which will be a compass-cli PR once this one is released.
  • MCP citation links built from an attribute.

…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>
@cla-assistant

cla-assistant Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@cla-assistant

cla-assistant Bot commented Nov 19, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

bartdegoede-cohere and others added 4 commits November 20, 2026 15:47
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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant