Embedding vectors define which documents a retrieval pipeline considers similar to a question. An explicit model prevents an index from silently using an unintended hosted provider and keeps document and query vectors in the same vector space.
The Settings.embed_model property supplies the process-wide default to LlamaIndex components created afterward. A direct embed_model= argument on VectorStoreIndex.from_documents() instead limits a different model to one index without changing that default.
The API-free smoke test uses a deterministic BaseEmbedding implementation so its winning document can be checked without credentials or a model download. Keep llama-index-core installed in the active Python environment, then replace KeywordEmbedding with the application's chosen embedding integration.
Steps to set a LlamaIndex embedding model:
- Create embedding_model_check.py with the imports and deterministic embedding adapter.
- embedding_model_check.py
from typing import List from llama_index.core import Document, Settings, VectorStoreIndex from llama_index.core.embeddings import BaseEmbedding class KeywordEmbedding(BaseEmbedding): @classmethod def class_name(cls) -> str: return "KeywordEmbedding" def _vector(self, text: str) -> List[float]: lowered = text.lower() refund_signal = 1.0 if any( term in lowered for term in ("refund", "support", "handbook") ) else 0.0 release_signal = 1.0 if any( term in lowered for term in ("release", "deployment", "calendar") ) else 0.0 return [refund_signal, release_signal, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] def _get_text_embedding(self, text: str) -> List[float]: return self._vector(text) def _get_query_embedding(self, query: str) -> List[float]: return self._vector(query) async def _aget_query_embedding(self, query: str) -> List[float]: return self._get_query_embedding(query)
The adapter maps refund and release vocabulary onto separate vector dimensions only to make the selection predictable. A production embedding integration implements the same BaseEmbedding contract.
- Extend embedding_model_check.py below the class with its process-wide default and two input documents.
embed_model = KeywordEmbedding() Settings.embed_model = embed_model documents = [ Document(text="Refund policy questions belong to the support handbook."), Document(text="Release approvals are tracked in the deployment calendar."), ]
Components created before the Settings.embed_model assignment retain the dependencies selected during their construction.
- Append the index construction and retrieval check below the documents list.
index = VectorStoreIndex.from_documents(documents) retriever = index.as_retriever(similarity_top_k=1) results = retriever.retrieve("Where are refund policy questions documented?") query_embedding = embed_model.get_query_embedding("refund policy") print(f"configured_embedding={Settings.embed_model.class_name()}") print(f"query_embedding_dimensions={len(query_embedding)}") print(f"top_source={results[0].node.get_content()}")
A persisted vector store requires the same model family and dimensions because vectors from incompatible models cannot be compared meaningfully.
- Run the completed script from the directory containing embedding_model_check.py.
$ python embedding_model_check.py configured_embedding=KeywordEmbedding query_embedding_dimensions=8 top_source=Refund policy questions belong to the support handbook.
The model name confirms the configured default, and the final line proves that the index embedded both documents and ranked the matching source for the query.
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.