Back to Practice

Persistent embedding cache

Worked

You are studying the persistent embedding cache from the LlamaIndex + Qdrant codebase. The function cached_text_embeddings (defined in the repository source) implements a per-text SQLite cache keyed by sha256(model + text), with vectors stored as packed float32 blobs. A critical detail is the float32 round‑trip: when a new text is embedded (a miss), the vector is converted to array.array('f') and back to list before being stored in the in‑memory cached dict. This ensures that the float32‑quantised values returned from a cache hit are bit‑identical to those from a fresh embed – eliminating any precision asymmetry between misses and hits.

Your task: write a Python function embed_texts_via_cache that takes a list of texts and an embed_model (a LlamaIndex embedding object with get_text_embedding_batch), optional namespace, cache_path, and verbose, and returns the list of embeddings by calling cached_text_embeddings. Your implementation must use the exact function signature and logic from the real code. Include a concise comment explaining the float32 round‑trip (you may quote the source’s own comment). The starter code below provides the skeleton.

Your code
Sources
  • roadmap-kg/kg/memory_common.py:643-685
  • roadmap-kg/kg/memory_common.py:757-804
  • roadmap-kg/kg/ground_content.py:264-308