liveBook · Manning

FAISS

As explained in Machine Learning Platform Engineering

FAISS is a software library for efficient similarity search and clustering of dense numerical vectors.

FAISS (Facebook AI Similarity Search) indexes numerical vectors for fast similarity search. In a retrieval-augmented generation (RAG) system, it finds document chunks related to a question by meaning rather than exact keywords. A question about updating API credentials can therefore retrieve material about key rotation. section 12.1.3

The workflow is straightforward: load documents, split them into chunks, embed the chunks, and build a FAISS index. At query time, embed the question in the same vector space and retrieve the closest chunks to supply context to the LLM. Retrieval quality matters because it determines what information the LLM sees. section 12.1.3 section 12.2.4

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

Index creation uses LangChain’s FAISS integration: create an embedding wrapper, then pass the document chunks and wrapper to FAISS.from_documents. The wrapper separates embedding-provider code from index construction. section 12.2.4

From Markdown files to a retrieval check

A pipeline recursively loads Markdown files, splits them into overlapping chunks, builds and saves a FAISS index, then runs similarity_search on “How do I rotate encryption keys?” with k=3. Inspecting the returned chunk previews provides a direct check of what retrieval will offer the LLM. section 12.2.4

Listing 12.7 Save/load FAISS vector indexes with persistence
def save_index(vectorstore: FAISS,  #1
    index_path: str = "./DATA/faiss_index"):   #1
    Path(index_path).parent.mkdir( #2
        parents=True, exist_ok=True)   #2
    vectorstore.save_local(index_path)  #3

def load_index( #4
    index_path: str = "./DATA/faiss_index") -> FAISS:   #4
    embeddings = GeminiEmbeddings()  #5
    vectorstore = FAISS.load_local(
        index_path, 
        embeddings, 
        allow_dangerous_deserialization=True  #6
    )
    return vectorstore

The persistence example saves the index locally and reloads it with the embedding wrapper. Its load call explicitly sets allow_dangerous_deserialization=True; account for that setting when deciding how indexes are stored and loaded. section 12.2.4

FAISS is a practical fit for development and moderate-scale production. Applications needing distributed storage and computation, real-time updates or deletions, metadata filtering, or built-in backup and recovery may instead need a dedicated vector database. section 12.1.3

How Machine Learning Platform Engineering covers it

How deep it goes
Shows index creation, local persistence, and a retrieval check through LangChain, but does not detail FAISS indexing algorithms.
Examples
Builds a FAISS index from Markdown chunks and tests similarity_search with an encryption-key rotation question.
What it assumes
Introduces embedding-based retrieval and shows document loading and chunking before index creation; assumes familiarity with Python application code.
What you can do after
Apply it via LangChain to build, save, reload, and test a document-retrieval index.
How it connects
Connects FAISS to text embeddings, document chunking, semantic search, LangChain, and retrieval-augmented generation.

Also explained in

Compare how 4 books explain FAISS →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Machine Learning Platform Engineering. The section links point to the parts of the book it draws on.