Back to Practice

Single-store text_key / index_doc_id

Full

Exercise: Deterministic Qdrant Index with Single-Store Text

Goal

Implement the function build_deduped_qdrant_index(nodes, embed_model, namespace="") that creates a VectorStoreIndex backed by Qdrant, following the pattern from the provided repository source. This ensures that re-running the same corpus upserts existing Qdrant points instead of appending duplicates.

Requirements

  1. Deterministic Node IDs: Assign each node a stable uuid5 ID derived from its text content and the namespace. Do not rely on random or default IDs.
  2. Corpus-Fingerprinted Collection Name: Use _collection_name(nodes, namespace=namespace) as defined in the source (fingerprint = SHA‑256 of sorted node IDs, truncated to 12 hex chars, prefixed with "kg-" and namespace).
  3. QdrantVectorStore Configuration: Create the store with index_doc_id=True and text_key="text".
  4. StorageContext: Use StorageContext.from_defaults(vector_store=...).
  5. Return the index: Return the resulting VectorStoreIndex.
  6. Explain the empty docstore: In a comment (or docstring), explain why index.docstore.docs is intentionally empty on the Qdrant path, referencing the source's design.

Assumptions

  • nodes is a list of TextNode objects with text and embedding attributes already set.
  • embed_model is an embedding model (e.g., from make_embed()).
  • You have access to QdrantVectorStore, StorageContext, VectorStoreIndex, and a _get_qdrant_client() (assume it returns a valid QdrantClient).
  • The _collection_name function is already available (you can reimplement it exactly as in the source).
  • Do not modify the internals of the source’s build_index_from_nodes; write your own function that replicates the pattern.

Starter Code

python

Deliverable

Provide the complete Python implementation of build_deduped_qdrant_index, including all helper logic (deterministic IDs, collection name, Qdrant wiring) and the required explanation.

Your code
Sources
  • roadmap-kg/kg/memory_common.py:920-928
  • roadmap-kg/kg/memory_common.py:931-972
  • roadmap-kg/kg/ground_content.py:519-546