Skip to content

About

Production-ready Retrieval-Augmented Generation (RAG) system with semantic search, vector embeddings, and citation-based answer generation.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

9 Commits

Folders and files

Repository files navigation

NovaCart RAG Pipeline

End-to-end retrieval-augmented generation system: ingest documents, semantically search them, and generate grounded, cited answers through an API and a bundled chat UI.

Stages

Stage Module What it does
1 — Ingestion src/loader.py, src/chunker.py, src/embedder.py, src/vectorstore.py, src/ingest.py Load raw files -> normalize into sentences -> chunk -> embed -> store in Chroma (cosine similarity)
2 — Retrieval src/retriever.py Embed a query, run a cosine search against Chroma, optionally filtered by metadata
3 — Generation src/generator.py Build a grounded prompt from retrieved chunks, call Claude, return a cited answer
4 — API src/api.py FastAPI service exposing/query and /health; also serves the bundled UI
UI static/index.html Minimal chat interface — transcript + a "sources" panel showing which chunks backed each answer

src/rag.py glues stages 2 and 3 together (answer_query()), and is what the API calls.

Run locally

pip install -r requirements.txt
cp .env.example .env    # then fill in ANTHROPIC_API_KEY

# Stage 1: ingest whatever's in data/ into Chroma
python -m src.ingest

# Stage 4: start the API (also serves the UI at http://localhost:8000)
uvicorn src.api:app --host 0.0.0.0 --port 8000 --reload

Open http://localhost:8000 for the chat UI, or call the API directly:

curl -X POST http://localhost:8000/query \
  -H "Content-Type: application/json" \
  -d '{"query": "Which refunds were issued for damaged items?", "n_results": 5}'

Optional metadata filter:

curl -X POST http://localhost:8000/query \
  -H "Content-Type: application/json" \
  -d '{"query": "recent shipments", "filters": {"warehouse_id": "WH-02"}}'

Run in Docker

cp .env.example .env    # fill in ANTHROPIC_API_KEY
docker compose up --build

This runs ingestion to completion first, then starts the API on localhost:8000 once ingestion succeeds, with the Chroma index persisted to a named Docker volume shared between both services.

Ingesting real data

Drop files into data/ — .txt/.md (already prose), or .csv/.json/.jsonl (structured records). Structured files get turned into natural-language sentences before embedding (see _TEMPLATERS in src/loader.py) — add a templater function per filename for any new structured source so it embeds as a sentence rather than a raw row/object. All original fields are preserved as Chroma metadata regardless, so they remain filterable.

Design choices

  • Chroma, embedded/local, no external account or API key — self-contained in Docker.
  • all-MiniLM-L6-v2 (local, via sentence-transformers) for embeddings — free, no API key, normalized vectors so cosine == dot product.
  • Cosine similarity, set as the collection's hnsw:space at creation time — this is the actual metric behind "semantic search."
  • Metadata filtering (warehouse_id, source_type, etc.) passes straight into Chroma's where filter at query time.
  • Generation is grounding-only: the system prompt instructs Claude to answer strictly from retrieved passages and say so plainly when they're insufficient, with inline [n] citations mapped back to source chunks — this is what makes it RAG rather than an LLM answering from general knowledge.

Tests

python tests/test_pipeline.py     # Stage 1: load -> chunk -> (fake) embed -> store
python tests/test_rag_api.py      # Stages 2-4: retrieval, generation, and the API — all offline/mocked

Both run fully offline (a deterministic fake embedder stands in for the real model, and the Anthropic HTTP call is mocked), so they don't require downloading a model or a live API key.

About

Production-ready Retrieval-Augmented Generation (RAG) system with semantic search, vector embeddings, and citation-based answer generation.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages