Skip to content

fix(ai): the rag index keeps each project's chunks apart, deletes a removed file's points before forgetting it, and refills a project its collection lost #1388

Closed

Description

@dan-petty

Refreshed plan (2026-10-17, unblocking review)

This section supersedes any text below that conflicts with it.

Decisions

  • Decision D11 (owner, 2026-10-17): "feat(rag): Index managed repos, exclude private from unscoped search #1389 is split into a CLI ingestion pass now and an Argo cluster lane later (new item)." This item blocks the CLI pass directly, and blocks the cluster lane through feat(rag): Index managed repos, exclude private from unscoped search #1389.
  • Decision D16 (owner, 2026-10-17): "v0.2.38 may go over the cap of 16 for now; unblocking work goes first." This item merges before feat(rag): Index managed repos, exclude private from unscoped search #1389.
  • The intact check and the recorded counts use QdrantClient.count_points, which is exact and raises QdrantClientError. They do not use drift's _count_collection_project_points, because that helper reads a failed count as 0 and would start a full re-embed on every transient error.
  • _safe_delete_points_by_files and its hasattr fallbacks are deleted, and so is delete_points_by_file, whose only caller in src/ is that fallback. The tests that call or fake it (tests/test_rag_qdrant.py:143, tests/test_rag_indexer_retriever.py:73, tests/test_rag_multi_project_indexer.py:66) change with it. The purges call delete_points_by_files(..., wait=True) directly, because the fallback sends unwaited deletes and its False is the swallowed failure this item removes.
  • The payload-index list is a constant in src/devops_cli/config/constants.py beside CONST_RAG_KB_PROJECT, because AGENTS.md puts such lists there. feat(rag): Index managed repos, exclude private from unscoped search #1389's CLI pass appends visibility to it.
  • The knowledge base's project name comes from CONST_RAG_KB_PROJECT in _resolve_indexing_target_metadata and index_knowledge_base, replacing the two "devops-cli-kb" literals, because the project name now feeds every point id.
  • Priority: P2, as the body proposes. The issue has no priority label yet. Its one dependent, feat(rag): Index managed repos, exclude private from unscoped search #1389, has no priority label, so the owner's blocker rule raises nothing.

Scope

Delivery

Acceptance criteria (these add to the criteria below; every criterion below still stands)

  • A count that raises fails the run and re-indexes nothing. A collection that does not exist counts as 0, so a deleted collection triggers the re-index under the criteria below.
  • No delete path sends wait=False. A test asserts that every delete the fake records waited.
  • A test: an existing collection without the payload indexes gets both on the next index run. Today the branch where the dimension matches returns before any index work, and indexing reaches ensure_collection only through upsert_points, so a run that embeds nothing never calls it.

Current references (checked at 3dd7fa6; each line gives the current location, then the body's old citation)

  • Collection names: src/devops_cli/commands/rag.py:84-86 (was :78-79). --include-kb, on by default: rag.py:122-128 (was :115-121).
  • Id: src/devops_cli/ai/rag/chunker.py:779-783, called at :308, :651, :683 and :714 (unchanged). _coerce_point_id: src/devops_cli/ai/rag/qdrant.py:92-102 (was :63-73).
  • Knowledge-base project and relative base: src/devops_cli/ai/rag/indexer.py:344-346, relative path at :351-352 (was :322-324). The second literal is at indexer.py:684. CONST_RAG_KB_PROJECT is at src/devops_cli/config/constants.py:2040.
  • Skip when the cache hash matches: indexer.py:383 (was :361).
  • _safe_delete_points_by_files: indexer.py:203-223, with wait=False at :216 (was :204).
  • _purge_deleted_vectors: scanned projects at indexer.py:236-240 (was :224-227). The cache entry is dropped at :253, before the deletes at :257-258 (was :241 and :245-246).
  • _purge_obsolete_points ignores the result: indexer.py:297-298 (was :285-286).
  • force: empty cache at indexer.py:713 (was :568), deleted-file purge skipped at :737 (was :592), final save at :799 (was :654).
  • _update_incremental_cache: indexer.py:153-175, called per batch at :892 (was :148-170). _load_cache: :623-629 (was :481-487). _save_cache, with Path.write_text and a DEBUG log: :631-636 (was :489-492).
  • delete_points_by_files: qdrant.py:578-633. It filters on file_path and project_name at :598-608, and logs at DEBUG and returns False at :625-633 (was :493-548, :509-523 and :540-548). delete_points_by_file, with wait=False: :635-639.
  • ensure_collection: qdrant.py:348-398, with no payload index. It returns early at :361-362 and :379-381 (was :313-359). Indexing reaches it only from upsert_points (qdrant.py:441). The library store also calls it (src/devops_cli/ai/rag/library_store.py:228).
  • count_points: qdrant.py:522-537, exact. It returns 0 for a collection that is not found (:534-535) and raises otherwise (:537). Drift's per-project count, which returns 0 on an error: src/devops_cli/ai/rag/drift.py:197-214.
  • fix(ai): a rag collection records its embedding model, a mismatch fails instead of wiping the collection, and ranking keeps the cosine score #1066's compatibility check: indexer.py:547, run before indexing at :700-701. The point payload is built at indexer.py:304-330.
  • rag clear: deletes the collections at rag.py:609-610 and removes only the local cache at :619-621 (was :542 and :553).
  • Retriever filter: src/devops_cli/ai/rag/retriever.py:67-83, with project_name at :77-78 (was :63-79). Collections searched: :378-386 (was :277-285).
  • Unchanged: write_json_file at src/devops_cli/output/file_writer.py:202, and test_multi_project_indexing at tests/test_rag_multi_project_indexer.py:25.

Dependencies and order


Problem

WorkspaceIndexer writes every project into the same two collections (<qdrant.collection_prefix>_code and _docs, src/devops_cli/commands/rag.py:78-79). It tells projects apart only by the project_name payload field, and several paths still assume one project per collection.

State on 2026-10-08.

Two projects that share a file path overwrite each other's points, and a default index already does this.

  • A point's id hashes only file_path:start_line:end_line (src/devops_cli/ai/rag/chunker.py:779-783, called at :308, :651, :683 and :714). The project is not part of it. _coerce_point_id keeps a UUID-shaped id as it is (src/devops_cli/ai/rag/qdrant.py:63-73), and a Qdrant upsert replaces the point with the same id.
  • devops ai rag index includes the knowledge base by default (--include-kb, rag.py:115-121). Its files are indexed as project devops-cli-kb, with paths relative to the knowledge-base directory (src/devops_cli/ai/rag/indexer.py:322-324). Both trees have a root README.md.
  • Reproduced offline at 910b823 on 2026-10-08: lines 26-34 of this repository's README.md and of the knowledge base's README.md get the same id, 8579c001-4bfc-f2dc-f156-7773b3c00690. On every default index, whichever is written second replaces the other in the docs collection, and the payload then names the second project.
  • What follows:
    • the first project's cache still lists the file at its hash (indexer.py:361), so it never embeds the file again;
    • when the second project later changes or deletes the file, the delete filtered on its project_name (qdrant.py:493-548) removes the only copy.
  • feat(rag): Index managed repos, exclude private from unscoped search #1389 would put eight repositories into these collections. README.md, LICENSE and pyproject.toml exist in most of them, often with identical first sections.
  • test_multi_project_indexing (tests/test_rag_multi_project_indexer.py:25) indexes two projects whose paths differ, so it doesn't catch this.

A delete that fails is forgotten.

  • _purge_deleted_vectors removes a file's cache entry (indexer.py:241) before it asks for the delete (:245-246), and ignores the result.
  • The delete is sent with wait=False (indexer.py:204). delete_points_by_files logs a failure at DEBUG and returns False (qdrant.py:540-548).
  • So a Qdrant timeout during a purge leaves the deleted file's chunks in the collection for good, and no cache entry is left to retry from.
  • _purge_obsolete_points ignores the result the same way (indexer.py:285-286). If a changed file got shorter, the chunks for its old line ranges stay.

A purge needs a scanned file. Deleted files are looked for only in projects that appear in this run's file_hashes (indexer.py:224-227). If every indexable file of a project is deleted, nothing is purged.

--force drops other projects' cache entries and orphans the points of deleted files.

The cache file is rewritten in place. _save_cache writes with Path.write_text (indexer.py:489-492) after every batch (_update_incremental_cache, :148-170), and logs a failure at DEBUG. A process killed mid-write leaves a truncated file. _load_cache then returns {} (:481-487), and the next run embeds every project again.

A collection that lost a project's points is never refilled.

No payload index.

  • ensure_collection creates a collection without any payload index (qdrant.py:313-359).
  • Deletes filter on file_path and project_name (qdrant.py:509-523), and searches filter on project_name (src/devops_cli/ai/rag/retriever.py:63-79).
  • Qdrant's indexing documentation says "Queries that filter on unindexed fields are not only slower; they can also unnecessarily consume cluster resources", and "Payload indexes should be created before ingesting data".
  • Its multitenancy guide recommends one collection with a keyword index on the tenant field, created with is_tenant=true. The cluster runs Qdrant v1.19.1, and is_tenant needs 1.11 or later.

Acceptance criteria

  • A point's id is uuid.uuid5 over the project name, the relative path and the line range, so two projects never share an id. The hand-formatted digest in _generate_id goes.
  • Deletes are sent with wait=True. delete_points_by_files raises QdrantClientError on failure instead of returning False.
  • _purge_deleted_vectors drops a cache entry only after that file's points are deleted from both collections. _purge_obsolete_points fails the run the same way. A failed run keeps the entries, so the next run retries the delete.
  • When project is given, deleted files are looked for among that project's cache entries, even if the scan found no file.
  • --force for a project:
    • first deletes all of that project's points from both collections, with a waited delete filtered on project_name;
    • then drops only that project's cache entries and embeds it in full.
    • Every other project's entries stay.
  • The cache file is written atomically through write_json_file(..., atomic=True) (src/devops_cli/output/file_writer.py:202). A failed write raises instead of being logged at DEBUG.
  • After a successful run, the indexer records each scanned project's point count per collection (Qdrant count, exact, filtered on project_name). The record goes in a small file beside the cache, written the same way. It does not go in the cache itself, a flat project:path map that the purge splits on :.
  • Before it scans a project, the indexer counts that project's points again. It re-indexes the project as --force does, and logs one INFO line naming the project and the collection, when either:
    • a collection that held points for the project at the last recorded run now holds none; or
    • there is no record yet, the cache lists files for the project, and both collections hold none.
  • WorkspaceIndexer also exposes that check on its own, for example points_intact(project) -> bool, so a caller can run it without scanning a tree. feat(rag): Index managed repos, exclude private from unscoped search #1389 uses it.
  • When ensure_collection creates a collection, it also creates keyword payload indexes on project_name (is_tenant: true) and file_path. On an existing collection it adds whichever index is missing. The list of indexes is one constant that other items can extend.
  • Tests use a fake Qdrant client that keeps points by id and records requests, and a fake embedder. They make no network call, and each runs in under 1 s. All but the last fail on today's code:
    • a tree and the knowledge base, each with a README.md, keep both points for lines 26-34 after one default index;
    • two projects with the same README.md each keep their own point, and deleting the file from one project leaves the other's point;
    • a delete that raises leaves the cache entry, and the next run deletes the points;
    • deleting every file of a project purges all of its points;
    • --force on project A keeps project B's cache entries;
    • a file deleted between two runs, where the second run uses --force, leaves no point for the deleted path;
    • with counts recorded, emptying one of the two collections makes the next run embed every file of the project;
    • with no record, a cache that lists a project's files over two collections that hold no point for it makes the next run embed every file;
    • a cache write that raises halfway leaves the previous file readable;
    • a new collection gets both payload indexes.
  • It says that point ids changed, and that one devops ai rag index <checkout> --force moves an existing index to the new ids.
  • uv run devops ci passes.
  • Pending a person, after merge:
    • Run devops ai rag index <checkout> --force once. It deletes the checkout's and the knowledge base's points and embeds both under the new ids. That also restores the README.md chunk the collision replaced.
    • devops ai rag query "<a phrase from README.md lines 26-34>" --project devops-cli-kb returns the knowledge base's chunk. The same query with --project <checkout's project> returns the checkout's chunk.
    • devops ai rag index <checkout A> --project <a> --no-include-kb, then devops ai rag index <checkout B> --project <b> --no-include-kb, for two checkouts that both have a README.md. devops ai rag query "<a phrase from A's README>" --project <a> returns A's chunk, and the same check for B returns B's.
    • devops ai rag status shows both collections non-empty.

Key questions

  • One collection per repository instead of ids that include the project? Proposed: no.
    • Qdrant's multitenancy guide says "Creating a separate collection for each tenant is rarely the most efficient approach", and "Only create multiple collections when you have a limited number of tenants that need strict isolation."
    • The retriever searches two collections (retriever.py:277-285). Per-repository collections would make every search fan out over two collections per repository.
    • A payload filter plus an is_tenant index is what the guide recommends. feat(rag): Index managed repos, exclude private from unscoped search #1389 explains why private repositories also stay in the shared collections.
  • What happens to points written with the old ids? Proposed: no migration, and no rag clear required (pre-1.0).
    • Every delete filters on project_name and file_path, never on the id (qdrant.py:493-548).
    • So an old-id point is removed when its file changes or is deleted, and it never piles up beside a new-id copy.
    • One rag index --force per checkout moves an index to the new ids at once. The pull request body and the person-run step say so.
  • Isn't counting on every run expensive? Proposed: no. It is two exact count requests per project before a run and two after it, on a field this item indexes. One embedding batch costs far more.
  • Should this item make rag drift and rag status read Qdrant? Proposed: no, fix(ai): the knowledge base is re-indexed whenever the installed knowledge base differs from what its collection holds, and rag status and drift read Qdrant instead of the local cache #1139 does that. Both read per-project counts, and whichever lands second reuses the other's read.
  • Does wait=True slow indexing? Proposed: accept the cost. A purge is one request per 100 files per collection. Waiting for it is what makes "deleted" true before the cache forgets the file.

Strategic alignment

Activity

  1. added
    type/bug
    scope/ai
    on Oct 8, 2026
  2. dan-petty-bot commented on Oct 8, 2026

    @dan-petty-bot
    Collaborator

    Intake placed this item to the backlog: at intake only a critical fix goes into a release; a release start pulls Ready items in, P0 features first.

    • Priority: P1-High. The default indexing path already triggers cross-project data corruption (KB README overwrites repo README), and failed deletes permanently orphan chunks, silently degrading search results for all users.
    • Value: High. Correctness of multi-project RAG search is broken by default, and #1389 will make the collision far worse with eight repositories sharing common file names.
    • Effort: High. Fixes span point-ID generation, delete-confirmation flow, purge scoping, force-index cache handling, and atomic cache writes across at least three modules.
  3. added this to the v0.2.38 milestone on Oct 17, 2026
  4. removed this from the v0.2.38 milestone on Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    scope/aitype/bug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions