Learn / Frameworks / LangChain / Vector Stores

LangChain · Lesson 8 of 15

Vector Stores

FAISS, Chroma and hosted indexes: persist embeddings and query them.

  • Intermediate
  • 16 min read
  • 3 objectives

Before this lessonLesson 7: Loaders and Splitters

What you will learn

  • Index chunks
  • Similarity search
  • Add metadata filters

Your Progress

0 of 15 lessons 0%

  • Lessons0 / 15
  • Completed0
  • Est. time left~ 4 hours

Create a free account to keep your progress on every device.

A vector store saves embeddings and returns the nearest neighbours of a query vector. FAISS is local and fast; Chroma adds persistence; Pinecone and pgvector are hosted / SQL.

Index and query

from langchain_community.vectorstores import FAISS
from langchain_openai import OpenAIEmbeddings

emb = OpenAIEmbeddings(model="text-embedding-3-small")
store = FAISS.from_documents(chunks, emb)
store.save_local("index")

later = FAISS.load_local("index", emb, allow_dangerous_deserialization=True)
hits = later.similarity_search("How do refunds work?", k=4)
for h in hits:
    print(h.metadata.get("source"), h.page_content[:120])

Metadata filters

hits = store.similarity_search("refunds", k=4, filter={"lang": "en"})

Filters only work if you set metadata when you index. Add source, product, as_of so you can restrict results.

When to use what

  • FAISS: prototypes, single-node, you manage the files.
  • Chroma / pgvector: persistence and filters without a new vendor.
  • Hosted: many writers, huge corpora, SLA.
Up next · Lesson 9LCEL in DepthRunnables, parallel branches, retries and how the pipe operator actually works.