How ridabayi/cccc works
1. This repo is a procurement copilot split into four main planes: a FastAPI backend, a Streamlit frontend, an offline ingestion/indexing pipeline, and GCP infrastructure definitions. The core product scope is twofold: question answering over procurement documents and invoice analysis against structured procurement data.
2. The backend is the main application boundary. backend/main.py exposes HTTP endpoints for health, document listing, search, ask, analyze, and invoices. The API layer is thin; most behavior is delegated into services and actor-style orchestration classes.
3. The ask/search subsystem is the central RAG path. A query goes through QueryClassifierActor, then retrieval via RetrievalActor, then answer synthesis via AskActor. Retrieval is hybrid: BM25, vector search, and fusion/reranking are all present, with dedicated actors and repositories for each stage.
4. There is a separate LLM gateway boundary. LLMGatewayActor abstracts model access and supports a primary/fallback provider setup, documented as Groq first with Gemini fallback. This keeps model choice and provider resilience outside the business workflow.
5. Retrieval is backed by distinct storage abstractions. backend/repositories/bm25_store.py and vector_store.py encapsulate the two retrieval modes, while document_repository.py handles document metadata. Services such as retrieval_service.py, search_service.py, reranking_service.py, and metadata_filter_service.py compose these stores into user-facing search and ask responses.
6. Invoice analysis is a separate workflow, not just another RAG query. The analysis endpoints and services combine uploaded invoice content with structured reference data through business rules, invoice extraction, response-building, and optional BigQuery access. This path is more deterministic and data-centric than the ask flow.
7. The frontend is a lightweight Streamlit client. It provides pages for chat and invoice analysis, and it talks only to the backend via HTTP through frontend/services/api_client.py. This keeps the UI stateless and decoupled from retrieval, LLM, and storage concerns.
8. The offline data plane lives in data/ and jobs/. Raw procurement documents are stored as markdown and CSV/JSON datasets, then processed by ingestion jobs that parse, chunk, embed, upload, and build indexes. The pipeline is split into reusable steps for document reading, chunking, embedding generation, and upload/index refresh.
9. The repository is designed for hybrid storage and cloud deployment. The README and Terraform indicate GCS for document/artifact storage, BigQuery for structured analytics data, Vertex AI for vector indexing, and Cloud Run for backend/frontend/job deployment. Redis is optional for ask caching.
10. Observability is a first-class backend concern. Middleware captures request context, services emit structured AI and workflow metrics, and the ask workflow records cache usage, retrieval mode, provider choice, latency, and cost estimates. This supports Cloud Logging/Monitoring and benchmark comparison.
11. Evaluation is built into the codebase as a separate subsystem. backend/evaluation/ loads datasets, runs benchmark sweeps across retrieval modes and top-k values, and computes retrieval, generation, grounding, latency, and workflow metrics. Versioned outputs are stored under artifacts/evaluation/.
12. The repo is organized for CI/CD and reproducible infrastructure. GitLab CI runs lint, test, security, build, and deploy steps; Dockerfiles exist for backend, frontend, and ingestion jobs; Terraform modules define the GCP resources. This makes the runtime architecture explicit: local dev, containerized deployment, and managed cloud services.
Main entry points: router.py HTTP routes · retrieval_workflow_service.py Search workflow · main.tf Terraform · ask_workflow_service.py Ask workflow
Components 20
Backend
FastAPI application boundary, orchestration, storage abstractions, and evaluation
- API app · Wires routes, middleware, settings, and service dependencies
backend/main.py - HTTP routes · Health, documents, search, ask, analyze, and invoices endpoints
backend/api/router.py - Ask workflow · Coordinates query classification, retrieval, and answer synthesis
backend/services/ask_workflow_service.py - Search workflow · Composes hybrid retrieval, filtering, reranking, and search responses
backend/services/retrieval_workflow_service.py - Invoice analysis · Combines invoice extraction, business rules, response building, and structured data access
backend/services/analysis_workflow_service.py - LLM gateway · Abstracts primary/fallback model providers for generation and classification
backend/actors/llm_gateway_actor.py - Retrieval actors · Query classification, BM25, vector search, fusion, and retrieval coordination
backend/actors/retrieval_actor.py - Answer builder · Builds final ask responses and manages prompt/answer assembly
backend/services/ask_response_service.py - Search service · User-facing search composition over retrieval and metadata filters
backend/services/search_service.py - BM25 store · Lexical retrieval storage abstraction
backend/repositories/bm25_store.py - Vector store · Vector retrieval storage abstraction
backend/repositories/vector_store.py - Document repo · Document metadata and listing repository
backend/repositories/document_repository.py - Observability · Request context, AI metrics, workflow telemetry, and cost/latency tracking
backend/services/ai_observability_service.py - Evaluation · Dataset loading, sweep execution, metric computation, and report generation
backend/evaluation/benchmark.py
Frontend
Streamlit client for chat and invoice analysis
- Streamlit app · Chat and invoice analysis pages
frontend/app.py - API client · Stateless frontend-to-backend integration
frontend/services/api_client.py
Data & Jobs
Offline corpora, ingestion, embedding, and indexing pipeline
- Procurement data · Markdown documents, metadata, structured tables, and evaluation samples
data/raw/README.md - Ingestion pipeline · Parse, chunk, embed, and upload documents for index refresh
jobs/pipeline/run_pipeline.py - Indexing steps · Reader, chunker, embedding, and upload stages for document processing
jobs/indexing/ingestion/pipeline.py
Infra
GCP deployment and Terraform definitions
- Terraform · Cloud Run, storage, BigQuery, Vertex AI, secrets, IAM, and observability modules
infra/terraform/main.tf
Connections 29
- API app → HTTP routes: serves · Registers API routes and app lifecycle
- API app → Observability: configures · Installs request context and logging/metrics middleware
- HTTP routes → Ask workflow: ask · Ask endpoint delegates to RAG workflow
- HTTP routes → Search workflow: search · Search endpoint delegates to retrieval workflow
- HTTP routes → Invoice analysis: analyze · Analyze and invoice endpoints delegate to invoice workflow
- Ask workflow → Retrieval actors: retrieves · Classifies query and drives hybrid retrieval actors
- Ask workflow → LLM gateway: generates · Uses model gateway for classification and answer synthesis
- Ask workflow → Answer builder: builds · Assembles final answer payload
- Search workflow → Retrieval actors: orchestrates · Coordinates lexical, vector, and fusion retrieval
- Search workflow → Search service: formats · Turns retrieval results into search responses
- Retrieval actors → BM25 store: bm25 · Reads lexical index
- Retrieval actors → Vector store: vector · Reads embedding index
- Search workflow → Document repo: filters · Uses document metadata and document listing
- Search service → Document repo: enriches · Adds document metadata to search results
- Invoice analysis → Document repo: references · Uses structured document and invoice metadata
- Invoice analysis → Procurement data: reads · Consumes uploaded invoice and structured procurement data
- HTTP routes → Observability: tracks · Emits request and workflow telemetry
- Evaluation → Search workflow: benchmarks · Runs retrieval and RAG sweeps
- Evaluation → Observability: measures · Captures latency, cost, and workflow metrics
- Streamlit app → API client: calls · UI talks only through HTTP client
- API client → API app: http · Sends requests to backend API
- Ingestion pipeline → Indexing steps: runs · Executes parsing, chunking, embedding, and upload stages
- Indexing steps → Procurement data: ingests · Processes raw documents and structured inputs
- Indexing steps → Vector store: writes · Publishes embeddings to vector index
- Indexing steps → BM25 store: writes · Refreshes lexical index
- Terraform → API app: deploys · Defines Cloud Run backend runtime
- Terraform → Streamlit app: deploys · Defines Cloud Run frontend runtime
- Terraform → Vector store: provisions · Defines Vertex AI and storage resources
- Terraform → Document repo: provisions · Defines GCS and BigQuery-backed data services