How mugnihidayah/synapse-instant-document-insight works
Synapse is a FastAPI multimodal document-Q&A service. Its main workflow is API-key-authenticated session creation and upload, optional background ingestion, extraction and chunk storage, then grounded answers with citations; users can also inspect sessions, export history, submit feedback, and review usage. The graph preserves README-documented capabilities such as OCR, hybrid retrieval, agentic tools, and query filters. Some subsystem wiring is documented rather than shown in the sampled source, so uncertain call relationships are omitted.
Main entry points: query.py Query routes · main.py FastAPI application · documents.py Document routes · hybrid_search.py Hybrid search
Components 30
API and sessions
- FastAPI application
src/api/main.py - API key routes
src/api/routes/keys.py - Document routes
src/api/routes/documents.py - Query routes
src/api/routes/query.py - Insights routes
src/api/routes/insights.py - Session service
src/api/session.py - API key auth
src/api/auth.py
Document ingestion
- Async ingestion jobs
src/api/ingestion_jobs.py - Ingestion contract
src/api/ingestion_contract.py - File loaders
src/ingestion/loaders.py - Document chunking
src/ingestion/chunkers.py - Metadata filters
src/ingestion/metadata_filters.py - Original file storage
src/ingestion/file_storage.py
RAG and agents
- Query orchestration
src/api/routes/query.py - History contextualization
src/rag/contextualize.py - Query rewriting
src/rag/query_rewrite.py - Hybrid search
src/rag/hybrid_search.py - Result reranking
src/rag/reranker.py - Retrieval tuning
src/rag/retrieval_utils.py - Grounding checks
src/rag/grounding.py - Answer generation
src/rag/chain.py - Agent orchestration
src/agent/orchestrator.py - Agent tools
src/agent/tools.py - Chat history
src/rag/chat_history.py
Persistence and usage
- Vector storage
src/ingestion/pgvector_store.py - PostgreSQL and pgvector
src/db/connection.py - Database models
src/db/models.py - Usage and quota
src/api/usage.py
Other components
- API client
- LLM and embedding providers
Connections 36
- API client → FastAPI application: sends requests
- FastAPI application → Document routes: dispatches
- FastAPI application → Query routes: dispatches
- FastAPI application → API key routes: dispatches
- FastAPI application → Insights routes: dispatches
- Document routes → API key auth: authenticates
- Query routes → API key auth: authenticates
- Insights routes → API key auth: authenticates
- Document routes → Session service: manages sessions
- Document routes → Original file storage: persists uploads
- Document routes → Async ingestion jobs: schedules ingestion
- Async ingestion jobs → Session service: updates status
- Async ingestion jobs → Ingestion contract: processes payloads
- Ingestion contract → File loaders: extracts content
- Ingestion contract → Document chunking: creates chunks
- Ingestion contract → Vector storage: stores chunks
- File loaders → LLM and embedding providers: uses OCR
- Vector storage → PostgreSQL and pgvector: reads and writes
- API key routes → PostgreSQL and pgvector: stores key records
- Session service → PostgreSQL and pgvector: reads and writes
- Query routes → Session service: loads session
- Query routes → Chat history: loads chat history
- Query routes → History contextualization: contextualizes query
- Query routes → Hybrid search: retrieves documents
- Hybrid search → Vector storage: vector search
- Hybrid search → PostgreSQL and pgvector: keyword search
- Hybrid search → Metadata filters: applies filters
- Query routes → Result reranking: reranks results
- Query routes → Answer generation: generates answer
- Query routes → Grounding checks: checks grounding
- Query routes → Agent orchestration: runs agent mode
- Agent orchestration → Agent tools: executes tools
- Agent orchestration → Hybrid search: retrieves sources
- Answer generation → LLM and embedding providers: requests completion
- Insights routes → Usage and quota: reports usage
- Usage and quota → PostgreSQL and pgvector: reads and writes