How aakriti0805/chatbot-backend works
This is a railway-maintenance chatbot API with two main workflows: ingest documents and master data for search, and answer questions using document retrieval, master-data SQL, or both. Uploaded and CRIS-sourced files are processed into searchable chunks; master-data synchronization maintains a separate chunk collection. Queries can use conversation history and return source citations. The sampled code confirms the query, retrieval, and CRIS-ingestion paths; some implementation details for chunking, master-data sync, and other routes are inferred only from the tree and route documentation.
Main entry points: query_services.py Query orchestration · document_services.py Document processing · ingest_cris_pdfs.py CRIS ingestion · document_routes.py Document routes
Components 23
API routes
- FastAPI app
app/main.py - Document routes
app/routers/document_routes.py - OCR route
app/routers/ocr_routes.py - Query routes
app/routers/query_routes.py - Master-data route
app/routers/master_data_routes.py
Document ingestion
- Document processing
app/services/document_services.py - Text extraction
app/services/textextraction_service.py - Chunking
app/services/chunking_services.py - CRIS ingestion
app/ingest_cris_pdfs.py
Question answering
- Query orchestration
app/services/query_services.py - Hybrid retrieval
app/services/retrieval_services.py - Text-to-SQL
app/services/sql_query_services.py - Language model
app/services/llm_service.py
Data and indexing
- Master-data sync
app/sync_master_data.py - Embedding model
app/services/embedding_service.py - Data models
app/models.py - Chatbot database
app/database.py
Other components
- Questioner
- Administrator
- CRIS source database
- Railway master database
- Gemini API
- CRIS file hosting
Connections 33
- Questioner → Query routes: asks
- Administrator → Document routes: uploads or syncs
- Questioner → OCR route: requests OCR
- FastAPI app → Document routes: mounts
- FastAPI app → Query routes: mounts
- FastAPI app → OCR route: mounts
- FastAPI app → Master-data route: mounts
- Document routes → Document processing: processes upload
- Document routes → CRIS ingestion: starts ingestion
- Document routes → Chatbot database: reads and writes
- CRIS ingestion → CRIS source database: fetches file links
- CRIS ingestion → CRIS file hosting: downloads files
- CRIS ingestion → Text extraction: extracts pages
- CRIS ingestion → Document processing: processes pages
- OCR route → Text extraction: extracts text
- Document processing → Text extraction: extracts text
- Document processing → Chunking: forms chunks
- Document processing → Embedding model: embeds content
- Document processing → Chatbot database: stores documents and chunks
- Master-data route → Master-data sync: starts sync
- Master-data sync → Railway master database: reads master rows
- Master-data sync → Embedding model: embeds rows
- Master-data sync → Chatbot database: upserts chunks
- Query routes → Query orchestration: answers query
- Query orchestration → Chatbot database: loads and saves history
- Query orchestration → Language model: rewrites and expands
- Query orchestration → Text-to-SQL: tries master-data SQL
- Query orchestration → Hybrid retrieval: searches chunks
- Query orchestration → Language model: generates answer
- Hybrid retrieval → Embedding model: embeds query
- Hybrid retrieval → Chatbot database: searches chunk vectors and keywords
- Text-to-SQL → Language model: plans and summarizes SQL
- Text-to-SQL → Railway master database: executes SQL