How sajib2019/python-rag- works
This is a FastAPI RAG service: clients submit text or supported files, documents are queued and processed into searchable chunks, and question requests retrieve hybrid results, generate an answer, and return citations. The graph also preserves the documented health/metrics, optional external-search, and provider capabilities. Source evidence is incomplete for several modules, so those relationships are included only where the README or sampled callers support them.
Main entry points: main.py FastAPI app · ingestion.py Ingestion worker · resources.py Resource wiring · search.py Hybrid search
Components 23
HTTP API
- FastAPI app
app/main.py - Auth and throttling
app/api/dependencies.py - Document routes
app/api/routes/documents.py - Query route
app/api/routes/query.py - Health and metrics
app/api/routes/health.py - Request and response models
app/schemas
Document Ingestion
- Document service
app/services/documents.py - Extract and chunk
app/services/ingestion.py - Ingestion worker
app/workers/ingestion.py
Retrieval and Answers
- RAG query service
app/services/retrieval.py - Hybrid search
app/services/search.py - Embedding and LLM providers
app/integrations/providers.py
Shared Runtime
- Redis job queue
- PostgreSQL and pgvector
- SQL repository
app/db/repository.py - Resource wiring
app/resources.py - Runtime settings
app/core/config.py - Request middleware
app/core/middleware.py - HTTP error handlers
app/core/exceptions.py - OpenTelemetry
app/core/telemetry.py
Other components
- API client
- Qdrant and Elasticsearch
- OpenAI-compatible API
Connections 34
- API client → FastAPI app: sends requests
README.md - FastAPI app → Document routes: mounts routes
app/main.py - FastAPI app → Query route: mounts routes
app/main.py - FastAPI app → Health and metrics: mounts routes
app/main.py - FastAPI app → Request middleware: installs middleware
app/main.py - FastAPI app → HTTP error handlers: registers handlers
app/main.py - Document routes → Auth and throttling: requires authorization
README.md - Query route → Auth and throttling: requires authorization
app/api/routes/query.py - Document routes → Document service: calls service
README.md - Query route → RAG query service: calls service
app/api/routes/query.py - Document routes → Request and response models: validates and returns
app/api/routes/documents.py - Query route → Request and response models: validates and returns
app/api/routes/query.py - Health and metrics → PostgreSQL and pgvector: checks readiness
README.md - Health and metrics → Redis job queue: checks readiness
README.md - Document service → Redis job queue: queues ingestion
README.md - Ingestion worker → Redis job queue: dispatches queued jobs
app/workers/ingestion.py - Ingestion worker → Extract and chunk: cleans and chunks
app/workers/ingestion.py - Ingestion worker → SQL repository: reads and updates documents
app/workers/ingestion.py - Ingestion worker → Embedding and LLM providers: embeds chunks
app/workers/ingestion.py - Ingestion worker → Hybrid search: syncs indexed document
app/workers/ingestion.py - Extract and chunk → PostgreSQL and pgvector: chunks persisted by worker
README.md - RAG query service → Embedding and LLM providers: embeds and generates
app/services/retrieval.py - RAG query service → Hybrid search: runs hybrid retrieval
app/services/retrieval.py - RAG query service → Request and response models: builds response models
app/services/retrieval.py - Hybrid search → SQL repository: uses PostgreSQL search
README.md - Hybrid search → Qdrant and Elasticsearch: uses optional backend
README.md - Embedding and LLM providers → OpenAI-compatible API: calls configured provider
app/integrations/providers.py - Resource wiring → SQL repository: constructs
app/resources.py - Resource wiring → Hybrid search: constructs
app/resources.py - Resource wiring → Embedding and LLM providers: configures providers
app/resources.py - Resource wiring → OpenTelemetry: configures telemetry
app/resources.py - FastAPI app → Resource wiring: opens shared resources
app/main.py - FastAPI app → Runtime settings: loads settings
app/main.py - Request middleware → Health and metrics: exposes metrics behavior
README.md