Vector Stores
You have chunks. You have embeddings. Now you need a place to keep them and search them.
A vector store saves each chunk together with its vector. Ask it a question and it finds the closest chunks.
Think of a library that files books by meaning instead of by title. Ask about foxes and the fox books are already on the shelf in front of you.
Start with the in memory store
InMemoryVectorStore keeps everything in Python memory. Nothing to install. Perfect for learning.
You hand the store an embedding model. The store uses it to turn every chunk and every question into a vector.
Add documents
add_documents embeds each Document and files it away. The metadata is kept next to each vector.
Search by meaning
similarity_search embeds your question and returns the k closest Documents.
The question never says fox. The fox chunk still comes first because the meaning is close.
k=2 means give me the two best matches. Start small. More chunks means more text for the model to read.
See how close the matches are
Each result comes with a score. For this store a higher score means closer. Other stores may flip that, so check the docs.
Scores help you throw away weak matches. If nothing is close, say so instead of guessing.
Chroma: a store that saves to disk
The in memory store forgets everything when your program stops. Chroma writes to a folder so you embed once and search forever.
from_documents builds and fills the store in one step. persist_directory is where it lives on disk.
FAISS: fast and local
FAISS is a search library from Meta. It is very fast and runs fully on your machine.
Same methods as before. save_local and load_local put the index on disk and bring it back.
Which store to pick
InMemoryVectorStore: learning, tests, tiny data
Chroma: small to medium projects, saves to a folder, easy
FAISS: lots of vectors, very fast, local only
Pinecone, Qdrant, pgvector: big apps in production, hosted or in your database
They all share the same methods. Swap one for another and the rest of your code stays the same.
Remember: a vector store is a library filed by meaning. add_documents puts chunks in, similarity_search pulls the closest ones out.
Test yourself
Three quick questions made just for this lesson. Earn 10 XP per correct answer.