Back to Practice

Single-store text_key / index_doc_id

Completion

In this exercise, you will implement the deterministic node ID and collection naming pattern used by the LlamaIndex + Qdrant integration to ensure idempotent re‑runs — the same corpus always creates or upserts the same Qdrant points, never appending duplicates.

You are given a partial scaffold with two functions and a comment placeholder. Your tasks:

  1. Implement _stable_node_ids – assign each TextNode a deterministic UUID5 (based on uuid.NAMESPACE_DNS and a string combining namespace and the node’s original node_id). Overwrite the node’s node_id with the string form of that UUID.

  2. Implement _collection_name – return a string "kg-<sanitized_namespace>-<12_hex_fp>" where the fingerprint is the first 12 hex characters of the SHA‑256 hash of the sorted stable node IDs (use '\x1f' as separator between IDs). Sanitize the namespace by replacing any non‑alphanumeric (except _ and -) character with _, defaulting to "content" if empty.

  3. Explain – provide a short comment (or print) that explains why the in‑memory docstore is left empty by design on this Qdrant path (refer to the real source’s use of text_key and index_doc_id).

Fill in the three # TODO: blanks in the starter code below.

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