Back to Practice

In-process embeddings (FastEmbed)

Completion
rag

Implement a function build_embed_model() that returns an in-process FastEmbed embedding model (bge-small, 384-dim) with process-level caching, mimicking the make_embed() function from the repository. Use a module-level dictionary _EMBED_CACHE keyed by the model name from the EMBED_MODEL environment variable (default "BAAI/bge-small-en-v1.5"). If the model is already cached, return it directly. Otherwise, instantiate a FastEmbedEmbedding from llama_index.embeddings.fastembed with the model name and optional threads (read from EMBED_THREADS as integer if set) and cache_dir (from EMBED_CACHE_DIR). Store it in the cache and return it.

Then implement embed_texts(texts: List[str]) -> List[List[float]] that uses the built model to embed a list of text strings into 384-dimensional vectors via get_text_embedding_batch. The starter code has two # TODO: gaps: one for the cache lookup/store, and one for constructing the FastEmbedEmbedding with the optional kwargs.

Your code
Sources
  • roadmap-kg/kg/llm.py:156-200
  • roadmap-kg/kg/ground_content.py:264-308
  • roadmap-kg/kg/memory_common.py:577-606