Retrieval-Augmented Generation (RAG) with Python

Lesson 4 of 9

Vector Storage

Every chunk now has a vector, but a list of vectors floating around isn't useful on its own, it needs somewhere to live alongside the original text it came from, ready to be searched. This lesson builds a minimal vector store.

Production tools

At real scale (millions of chunks), you'd reach for a dedicated vector database like Pinecone, FAISS, or Weaviate, tools built specifically to store embeddings and run similarity search fast, even across huge datasets, with persistence to disk and metadata filtering built in.

A minimal in-memory version

For this course's scale (a handful of chunks), a plain Python list holding every chunk's text, vector, and metadata together is enough to demonstrate the same core idea:

Pythonshares state with other Python blocks

Storing every chunk from every document

Putting the last three lessons together, every document gets chunked, every chunk gets embedded, and every (chunk, vector) pair gets added to the store along with which document it came from:

Pythonshares state with other Python blocks

Keeping metadata (like which file a chunk came from) alongside the vector is what lets a real RAG system cite its sources later, "according to faq.md, ...", rather than just returning an answer with no way to trace where it came from.

TIP

The core idea a vector database adds beyond "a list with vectors in it" is fast similarity search at scale, techniques like approximate nearest-neighbor indexing that make searching millions of vectors take milliseconds instead of scanning every single one. This course's simple linear scan (next lesson) is correct but wouldn't stay fast forever, which is exactly why those tools exist.

📝 Vector Storage Quiz

Passing score: 70%
  1. 1.Why does the VectorStore keep metadata (like the source filename) alongside each vector?

  2. 2.Pinecone, FAISS, and Weaviate are all examples of dedicated vector database tools.

  3. 3.A key advantage a real vector database adds over a plain list is fast similarity search at ____.