A vector index organizes numerical representations of document chunks so an application can find semantically similar content quickly. In a retrieval-augmented generation (RAG) system, it avoids comparing a query sequentially against potentially millions of document vectors. Retrieved chunks can then become context for an LLM prompt. section 12.2.4 section 12.2.5
Build and use an index as a repeatable pipeline:
- Load source documents and split them into coherent, overlapping chunks; chunk boundaries affect retrieval quality. section 12.2.4
- Embed each chunk with the document embedding operation, then pass the chunks and embedding wrapper to `FAISS.from_documents` to construct the searchable index. section 12.2.4
- Save the index and load it on restart instead of paying the time and API cost of rebuilding it. Use the same embedding model when reconnecting: dimension, normalization, or version differences can cause failures. section 12.2.4 section 12.2.5
- Search the index or expose it as a retriever. Assemble the returned document chunks into context before sending them to the LLM. section 12.2.4 section 12.2.5
Listing 12.6 FAISS vector index creation from document chunks
from langchain_community.vectorstores import FAISS
def create_faiss_index(chunks: List[Document]) -> FAISS: #1
embeddings = GeminiEmbeddings() #2
vectorstore = FAISS.from_documents( #3
chunks, embeddings) #3
return vectorstore #4
The index-creation function shows the key integration point: `FAISS.from_documents(chunks, embeddings)` embeds prepared chunks and returns a searchable vector store. section 12.2.4
Check retrieval before prompt assembly
After indexing the Markdown documents, run `similarity_search("How do I rotate encryption keys?", k=3)` and inspect the three returned chunks. The query-processing step can then invoke a retriever and join returned page contents into prompt context. section 12.2.4 section 12.2.5
Treat the saved index as a deployment artifact alongside embeddings, chunking rules, and retrieval settings. Loading the shown FAISS index enables Python's dangerous deserialization option; secure the index files and consider integrity checks because tampered files can execute code. section 12.1.2 section 12.2.5
Listing 12.9 Persistent FAISS index and LangChain retriever
from langchain_community.vectorstores import FAISS
from index import GeminiEmbeddings
embeddings = GeminiEmbeddings() #1
vector_store = FAISS.load_local(
"DATA/faiss_index",
embeddings=embeddings,
allow_dangerous_deserialization=True #2
)
retriever = vector_store.as_retriever() #3
The loading example reconnects the persisted FAISS index to its embedding wrapper and exposes a LangChain retriever for queries. section 12.2.5







