LangChain Mastery

Course Content

LangChain Mastery

7 sections · 109 lessons

How do you save and load a vector store in LangChain?


What you need to know

Three kinds of persistence

KindExamplesSaveLoad
In-memory onlyInMemoryVectorStoredump(path) to a fileInMemoryVectorStore.load(path, embedding)
Local filesFAISS, ChromaFAISS: save_local; Chroma: automaticReopen with the same embedding
Serverpgvector, Qdrant, PineconeAutomatic on writeReconnect with URL and collection name

FAISS

Python
from langchain_community.vectorstores import FAISSvs = FAISS.from_documents(chunks, embeddings)vs.save_local("indexes/hr_faiss")        # writes index.faiss + index.pklvs = FAISS.load_local(    "indexes/hr_faiss", embeddings,    allow_dangerous_deserialization=True,)

index.faiss holds the vectors; index.pkl holds the documents and id mapping, saved with Python pickle. Unpickling a file from an untrusted source can run arbitrary code. That is why LangChain makes you opt in with the flag. Only load indexes your own pipeline built.

Chroma

Python
from langchain_chroma import Chromavs = Chroma(    collection_name="hr_policies",    embedding_function=embeddings,    persist_directory="./chroma",)

The same constructor creates the collection the first time and reopens it later.

What to store with the index

A small index_meta.json next to the index: embedding model and version, vector dimensions, chunk_size, chunk_overlap, splitter, and the date built. Check it at startup.

A real-life example

A travel-booking company runs its "visa rules" assistant on 8 small pods. Each pod used to rebuild a FAISS index from 3,000 PDFs at startup — about 6 minutes and around 40,000 embedding calls per restart, multiplied by 8 pods.

They move indexing to a nightly job. The job builds the FAISS index once, calls save_local, writes index_meta.json, and uploads the folder to object storage. Pods download and load_local in about 4 seconds. At startup each pod compares index_meta.json with its configured embedding model and refuses to start on a mismatch.

A year later, as the corpus reaches millions of chunks and several services need it, they move to pgvector. There is no save or load step any more; the nightly job writes straight into Postgres.

Follow-up questions to expect

  • "Why does FAISS need that dangerous flag?" — Because part of the saved index is a pickle, and loading a pickle can execute code. The flag makes you confirm you trust the file.
  • "How do you update a saved FAISS index?" — Load it, add_documents or delete(ids=...), then save_local again; for frequent changes, use a server store.
  • "Can two processes write the same local Chroma directory?" — Not safely at scale. Run Chroma as a server, or use a real database.