How hermes-erm/polyvault-rag works
Purpose and entry points
Poly-vault is a multimodal retrieval-augmented generation (RAG) service: it ingests supported files, converts and semantically chunks content, indexes embeddings, then answers questions only from retrieved context. The FastAPI application starts from src/app/main.py; HTTP routes live in src/app/api.py; its minimal browser client is src/app/static/index.html.
API and application boundary
src/app/main.py creates the FastAPI app, mounts static content, and registers API routing. src/app/api.py exposes upload, document listing/deletion, vector reset, retrieval, and answer-generation endpoints. src/dependencies.py is the composition boundary that creates/reuses pipeline services and database sessions; model selection is centralized here.
Ingestion pipeline
Uploads enter through src/app/api.py and are handled asynchronously by src/rag_system/document_processor.py. The processor persists source/intermediate files under pipeline/staging/ and records lifecycle state—staging, embedding, indexed, or failed—through src/rag_system/model.py. It uses Docling to normalize PDF, DOCX, images, CSV, XLSX, and Markdown into Markdown; BlingFire sentence segmentation and semantic grouping produce chunks.
Persistence and indexing
src/rag_system/model.py owns the SQLAlchemy/SQLite document-pipeline metadata model and repository operations. src/rag_system/retriever.py owns ChromaDB collection operations: chunk embedding, metadata association, similarity lookup, per-document vector deletion, and full reset. The SQLite row and Chroma vectors must remain coordinated: document deletion and reset remove both metadata and embeddings.
Retrieval and answer generation
For /query/search, src/app/api.py delegates query embedding and candidate retrieval to src/rag_system/retriever.py. Retrieved chunks are reranked by Cohere before being passed to src/rag_system/generator.py. The generator calls Gemini with a RAG prompt that constrains answers to supplied context. /query/retrieve exposes the retrieval stage without answer generation.
Runtime dependencies and external services
The Python/FastAPI runtime packages services in Dockerfile and dependencies in requirements.txt. Core local persistence is SQLite plus persistent ChromaDB storage; staging/processed pipeline directories are pipeline/staging/ and pipeline/processed/. External model/service dependencies are Docling, BlingFire, MiniLM embeddings, Cohere reranking, and Gemini generation; Cohere and Gemini credentials come from environment variables.
Deployment control flow
.github/workflows/aws-ecs-deploy.yml runs on pushes to main, builds the Dockerfile image, pushes it to Amazon ECR, renders an ECS task definition, and deploys it to ECS. The deployed task is reached through an AWS Network Load Balancer and stable Elastic IP; deployment routing depends on target health checks. The service currently has no API authentication, so network exposure is the primary protection boundary.
Main entry points: document_processor.py Document processor · api.py HTTP API · retriever.py Vector retriever · main.py FastAPI app
Components 20
Application
- Browser client
src/app/static/index.html - FastAPI app
src/app/main.py - HTTP API · Upload, document, reset, retrieval, and answer endpoints.
src/app/api.py - Service composition · Creates shared services, sessions, and selected models.
src/dependencies.py
Ingestion pipeline
- Document processor · Normalizes uploads and produces semantic chunks.
src/rag_system/document_processor.py - Staging files
- Processed files
Persistence & retrieval
- Document metadata · Tracks pipeline lifecycle and document records.
src/rag_system/model.py - SQLite
- Vector retriever · Embeds chunks, manages vectors, and performs similarity lookup.
src/rag_system/retriever.py - ChromaDB
Model services
- Docling · Converts supported source formats to Markdown.
- BlingFire
- MiniLM embeddings
- Cohere reranker · Credentials are supplied through environment variables.
- RAG generator · Builds a context-constrained prompt.
src/rag_system/generator.py - Gemini · Credentials are supplied through environment variables.
Deployment
- ECS deploy workflow · Builds, publishes, renders, and deploys on pushes to main.
.github/workflows/aws-ecs-deploy.yml - Container image
Dockerfile - ECR → ECS → NLB · Health-checked ECS tasks are exposed through the Network Load Balancer and Elastic IP.
Connections 23
- Browser client → FastAPI app: HTTP
- FastAPI app → HTTP API: registers routes
- FastAPI app → Browser client: mounts static client
- HTTP API → Service composition: resolves services
- HTTP API → Document processor: upload
- Document processor → Staging files: persists source files
- Document processor → Processed files: writes intermediates
- Document processor → Docling: normalizes content
- Document processor → BlingFire: segments and groups
- Document processor → Document metadata: updates lifecycle
- Document metadata → SQLite: stores records
- Document processor → Vector retriever: indexes chunks
- Vector retriever → MiniLM embeddings: embeds chunks and queries
- Vector retriever → ChromaDB: stores and searches vectors
- HTTP API → Vector retriever: retrieve/search
- Vector retriever → Cohere reranker: reranks candidates
- HTTP API → RAG generator: answer request
- Vector retriever → RAG generator: retrieved context
- RAG generator → Gemini: RAG prompt
- HTTP API → Document metadata: list/delete/reset · Deletion and reset coordinate metadata with vectors.
- ECS deploy workflow → Container image: builds image
- ECS deploy workflow → ECR → ECS → NLB: pushes and deploys
- ECR → ECS → NLB → FastAPI app: runs container