Skip to content
derpx06Notes on systems, models & learning
4. Embeddings & Vector Stores · lesson 34 of 68 · 1 min · January 10, 2026

Persisting & Reloading Indexes

Saving your work. Avoiding expensive re-computation.

Calculating embeddings costs time (GPU cycles) and money (API credits). If you re-embed your PDF every time you restart the script, you are burning money. You must Persist (save) the index.

  • In-Memory: vectorstore = Chroma.from_documents(...).

    • Fastest.
    • Dies when script ends.
    • Good for testing.
  • Persistent: vectorstore = Chroma(persist_directory="./db").

    • Saves to disk.
    • Reloads instantly on next run.

In production, you separate Ingestion from Querying.

Script A (Ingestion): Run nightly. Reads docs -> Embeds -> Save to ./db.

Script B (FastAPI): Run continuously. Loads ./db -> Serves queries.

persist_reload.py
# Script A: Write
db = Chroma(persist_directory="./chroma_db", embedding_function=model)
db.add_documents(docs)

# Script B: Read
db = Chroma(persist_directory="./chroma_db", embedding_function=model)
# No embedding happens here! Instant load.

Treat your Vector Store like a database, not a temporary variable. Persist to disk (or cloud) so your app starts instantly.

Key Intuition: "Compute once, query forever."