- Use Ollama for embeddings and LLM generation.
- Use ChromaDB (Chroma) for persistence and similarity search.
- Run a minimal RAG round trip with one in-memory document.
Prerequisites / context
- A
data/folder with Project Gutenberg text files (optional for this tiny demo). Example sources: Project Gutenberg. - Ollama running locally. Start it with
ollama serveif not running. - Two Ollama models available locally: an embedding model and an LLM model (examples below).
Different versions of the Ollama Python client or model endpoints may expect either
prompt= or input= when calling ollama.embeddings(...). The demo code below tries both to remain compatible across versions.When you re-run the demo, Chroma’s
add() may raise an exception if the same id already exists in the collection. The demo handles this by catching the error and continuing — this is safe for quick iterations.- Helper functions for embeddings and generation that handle Ollama client variations.
- A Chroma collection getter using a persistent path and cosine similarity.
- Two subcommands:
init(quick environment checks) anddemo(index one tiny document, retrieve, and answer a question).
- Run the init check:
- Run the tiny RAG demo:
- Ollama (local) can produce embeddings and generate text for grounding answers.
- ChromaDB persists embeddings and returns semantically similar documents.
- Minimal RAG flow: query → embed → retrieve → LLM (grounded on retrieved context) → answer.
- Chunk and ingest larger documents from the
data/folder with overlap-aware chunking. - Improve prompt engineering and retrieval strategies (e.g., hybrid search, reranking).
- Evaluate retrieval accuracy and build hallucination mitigation strategies.
- Consider model selection and latency trade-offs for production deployments.