A production-oriented AI document intelligence and agentic conversational backend built with FastAPI, Celery, Docling, LangChain, ChromaDB, PostgreSQL, Redis, and multiple AI-driven retrieval and memory systems.
Talk2Docs is an asynchronous, user-isolated document intelligence platform that turns uploaded documents into searchable knowledge and provides grounded AI answers.
It started as a document-processing and RAG backend and evolved into a larger AI system containing:
- Structure-aware document processing
- Multi-index RAG
- Hybrid vector + BM25 retrieval
- Adaptive query transformation
- AI reranking
- Structured source-grounded answers
- Three-tier semantic caching
- Stateful conversations
- Short-term conversational context
- Current-session semantic memory
- Cross-session semantic memory
- Agentic tool selection
- Web search
- Document QA as an internal AI tool
- General intent classification as an internal AI tool
- Asynchronous background processing
- User-isolated storage and retrieval
The system therefore contains two major AI paths:
TALK2DOCS
β
βββββββββββ΄ββββββββββ
β β
βΌ βΌ
DOCUMENT QA CONVO AI
β β
βΌ βΌ
Advanced RAG Agentic AI
β β
βΌ βΌ
Grounded Answers Tools + Memory
- Asynchronous document ingestion
- Docling document parsing
- Structure-aware
HybridChunker - Raw / Summary / Explanation representations
- Per-user ChromaDB storage
- Persistent document lifecycle tracking
- File type, MIME, size and signature validation
- Vector retrieval
- BM25 lexical retrieval
- Hybrid retrieval
- Reciprocal Rank Fusion
- Multi-Query
- HyDE
- Step-Back prompting
- Advanced query translation
- Query decomposition
- Multi-index retrieval
- Cohere encoder reranking
- Source-grounded structured responses
- T1 exact Redis cache
- T2 semantic Redis vector cache
- T3 persistent ChromaDB semantic cache
- Cohere reranking for T3
- Source-version validation
- Asynchronous cache population
- Different cache behavior for AnswerAI and ConvoAI
ConvoAI can dynamically use:
- AnswerAI document search
- Current-session semantic memory
- Global semantic memory
- Web search
- General intent classification
The model decides which tools are required while the application controls the execution loop and tool plumbing.
- FastAPI
- Async SQLAlchemy
- PostgreSQL
- Redis
- Celery
- Nginx
- SlowAPI
- JWT authentication
- Structured logging
- Centralized exception handling
Talk2Docs separates the HTTP lifecycle from expensive AI and document-processing workloads.
CLIENT
β
βΌ
NGINX
β
βΌ
FASTAPI
β
βββββββββββββββββββΌββββββββββββββββββ
β β β
βΌ βΌ βΌ
Authentication Validation Rate Limiting
β β β
βββββββββββββββββββΌββββββββββββββββββ
β
Service Layer
β
ββββββββββββββββ΄βββββββββββββββ
β β
βΌ βΌ
Document Flow Question Flow
β β
βΌ βΌ
Celery Cache / ConvoAI
β β
ββββββββββΌβββββββββ ββββββββββ΄ββββββββββ
β β β β β
βΌ βΌ βΌ βΌ βΌ
Docling BM25 Multi-Index AnswerAI ConvoAI
β β β β β
ββββββββββ΄βββββββββ β βββββββΌββββββ
β β β β β
βΌ β LTM Web Classifier
ChromaDB βββββββββββββββ
β
βΌ
PostgreSQL
The architecture follows a thin-route approach:
Route
β
Service
β
AI / Retrieval / Worker Logic
β
APIResponse
β
Centralized Response / Exception Handling
The document pipeline is asynchronous.
User Upload
β
βΌ
FastAPI Route
β
βΌ
Authentication
β
βΌ
File Validation
β
βββ Filename
βββ Extension
βββ MIME Type
βββ Size
βββ Content
βββ File Signature
β
βΌ
Validated File
β
βΌ
Persistent Storage
β
βΌ
PostgreSQL Document Record
β
βΌ
Celery Task
β
βΌ
Docling Parsing
β
βΌ
HybridChunker
β
βΌ
Raw Chunks
β
βΌ
Embedding Generation
β
βΌ
RAW VDB
β
βΌ
Document = READY
β
ββββββββββββββββββββββββ
βΌ βΌ
Summary Worker Explanation Worker
β β
βΌ βΌ
SUMMARY VDB EXPLANATION VDB
The HTTP request does not wait for expensive parsing, chunking and embedding operations.
Instead, background workers process the document and maintain persistent lifecycle state in PostgreSQL.
Files are validated before entering the processing pipeline.
Validation includes:
- Filename validation
- Extension validation
- MIME type validation
- Maximum file size
- File-content validation
- Signature / magic-byte validation where applicable
- Authentication
- User ownership
The system does not rely solely on:
document.pdf
or:
application/pdf
when actual file-content validation is required.
Talk2Docs uses Celery to isolate expensive background operations from HTTP requests.
The system contains workers for operations such as:
- Document ingestion
- Parsing
- Embedding
- Summary generation
- Explanation generation
- BM25 construction
- Cache population
- Vector-cache population
- Other AI/background operations
Conceptually:
FastAPI
β
βΌ
Celery Queue
β
βββ Ingestion
βββ Embeddings
βββ BM25
βββ Multi-Index
βββ Cache
βββ AI Operations
Workers communicate using serializable payloads rather than passing ORM objects between processes.
This keeps worker execution independent from SQLAlchemy session state.
Talk2Docs maintains multiple representations of the same document knowledge.
RAW CHUNKS
β
ββββββββββββββΌβββββββββββββ
β β β
βΌ βΌ βΌ
RAW VDB SUMMARY VDB EXPLANATION VDB
β β β
β β β
Original Summary Explanation
Content Representation Representation
Each raw chunk maintains a shared chunk_id.
Conceptually:
Raw Chunk
β
βββ chunk_id = document_id_0
β
βββ Summary Representation
β
βββ Explanation Representation
This allows secondary representations to improve retrieval while still resolving results back to the original raw chunk.
Talk2Docs combines semantic and lexical retrieval.
USER QUESTION
β
ββββββββββ΄βββββββββ
β β
βΌ βΌ
Vector Retrieval BM25
β β
ββββββββββ¬βββββββββ
βΌ
Ensemble Retrieval
β
βΌ
Reciprocal Rank Fusion
β
βΌ
Candidate Documents
β
βΌ
Reranking
Captures semantic similarity.
Useful when the question and document express the same idea using different wording.
Captures lexical relevance.
Useful for:
- Exact terminology
- Names
- Identifiers
- Uncommon phrases
- Keyword-heavy questions
The two signals provide:
Semantic Understanding
+
Lexical Precision
BM25 requires corpus-level statistics.
Rebuilding a user-wide BM25 index from scratch for every query would be wasteful.
Talk2Docs therefore maintains a persistent user-scoped BM25 resource.
User
β
βββ Raw VDB
β βββ Document A
β βββ Document B
β βββ Document C
β
βββ Global BM25
βββ Document A chunks
βββ Document B chunks
βββ Document C chunks
The BM25 resource is versioned and persisted.
Redis can be used for the active cached retriever while persistent pickle artifacts provide a durable fallback.
Conceptually:
New Document
β
βΌ
Update Corpus
β
βΌ
Build BM25
β
βΌ
Versioned Artifact
β
βΌ
Redis Cache
For document questions, Talk2Docs does not blindly execute a single retrieval strategy.
The query can be transformed using techniques such as:
User Question
β
βΌ
Query / Intent Classification
β
βββ NONE
βββ MULTI_QUERY
βββ HYDE
βββ STEP_BACK
βββ ADVANCED_TRANSLATION
βββ QUERY_DECOMPOSITION
βββ MULTI_INDEXING
β
βΌ
Retrieval
β
βΌ
Reranking
β
βΌ
AnswerAI
| Technique | Purpose |
|---|---|
| Multi-Query | Generates multiple query formulations to improve recall |
| HyDE | Uses a hypothetical semantic representation for retrieval |
| Step-Back | Retrieves using a broader conceptual question |
| Advanced Translation | Converts the question into retrieval-oriented representations |
| Query Decomposition | Splits complex questions into independently retrievable sub-questions |
| Multi-Index | Searches Raw, Summary and Explanation representations |
Different retrieval techniques can have completely different internal implementations.
However, Talk2Docs deliberately normalizes their output to:
list[LangChainDocument]Therefore:
Multi-Query
HyDE
Step-Back
Translation
Decomposition
Multi-Index
Hybrid Retrieval
β
βΌ
list[LangChainDocument]
β
βΌ
Reranking
β
βΌ
AnswerAI
This creates a stable boundary between retrieval and downstream answer generation.
The retrieval system can evolve without requiring AnswerAI to understand every retrieval implementation.
Retrieval is optimized for recall.
Reranking improves precision.
Retriever
β
βΌ
Candidate Documents
β
βΌ
Cohere Encoder Reranker
β
βββ Candidate 1 β score
βββ Candidate 2 β score
βββ Candidate 3 β score
βββ ...
β
βΌ
Sorted Candidates
β
βΌ
Top-K
Talk2Docs validates reranker output before using it.
Validation includes:
- Schema correctness
- Candidate identity
- Candidate uniqueness
- Candidate completeness
- Score validation
- Ranking validation
AnswerAI is the primary document-grounded answer generation system.
It receives retrieved document context and produces structured output.
User Question
β
βΌ
Cache
β
βββ HIT βββββββββββββββΊ Cached Answer
β
βΌ
Query Classification
β
βΌ
Retrieval Strategy
β
βΌ
Hybrid / Multi-Index Retrieval
β
βΌ
Cohere Reranking
β
βΌ
Top-K Context
β
βΌ
AnswerAI
β
βΌ
Structured Grounded Response
A simplified response structure contains:
class AnswerModel(BaseModel):
answer: str
topic: ShortTopicStr
citations: list[LocationCitation]
answer_summary: str
confidence_score: float
is_meaning_preserved: boolThe result is intended to be:
Human-readable
+
Machine-readable
+
Source-grounded
+
Citation-aware
+
Confidence-aware
Talk2Docs uses a three-tier cache architecture for document-answer workloads.
The architecture was originally developed as part of Talk2Docs and was later extracted into a reusable standalone project:
TriCacheLLM-MMA: https://github.com/mohib-ash/TriCacheLLM_MMA
Origin note: Talk2Docs currently uses the initial version of TriCacheLLM-MMA. The standalone project exists to generalize and evolve the caching architecture beyond Talk2Docs.
Incoming Question
β
βΌ
βββββββββββββββββββ
β T1 Exact Redis β
ββββββββββ¬βββββββββ
β
MISS β HIT
β ββββββββββββββΊ Response
βΌ
βββββββββββββββββββ
β T2 Semantic β
β Redis Vector β
ββββββββββ¬βββββββββ
β
MISS β HIT
β ββββββββββββββΊ Response
βΌ
βββββββββββββββββββ
β T3 Persistent β
β Chroma + Cohere β
ββββββββββ¬βββββββββ
β
MISS β HIT
β ββββββββββββββΊ Response
βΌ
AI Pipeline
Redis stores exact request responses.
Purpose:
- Duplicate request protection
- Very fast repeated requests
- Double-click/retry protection
- Avoiding unnecessary AI execution for identical requests
The question is embedded and searched using a Redis vector index.
Semantically similar questions can reuse a previous answer even when the wording is different.
Question A
"What is GOTEI 13?"
Question B
"Within Soul Society, what purpose does GOTEI 13 serve?"
β
βΌ
Embeddings
β
βΌ
Redis Vector Search
β
βΌ
Similarity Match
β
βΌ
Cached Response
This tier provides a faster semantic cache before falling back to the persistent cache.
The persistent cache VDB provides semantic caching beyond the Redis layer.
Candidates are:
- Retrieved from ChromaDB
- Validated against cache metadata and source versions
- Reranked with Cohere
- Checked against the configured similarity threshold
- Returned when the candidate satisfies the cache policy
Question
β
βΌ
Chroma Similarity Search
β
βΌ
Valid Candidates
β
βΌ
Cohere Reranking
β
βΌ
Threshold Validation
β
βΌ
Cached Response
This gives Talk2Docs a persistent semantic cache that survives beyond the short-lived Redis layers.
Each tier solves a different problem:
| Tier | Technology | Main Purpose |
|---|---|---|
| T1 | Redis Exact | Identical request protection |
| T2 | Redis Vector | Fast semantic reuse |
| T3 | Chroma + Cohere | Persistent semantic reuse |
| Miss | AI Pipeline | Generate a new answer |
The result is a progressive cache strategy:
Fastest
β
βΌ
T1 Exact
β
βΌ
T2 Semantic
β
βΌ
T3 Persistent Semantic
β
βΌ
Full AI Pipeline
β
βΌ
Slowest
The three-tier caching architecture was first built and validated inside Talk2Docs.
After proving the design in the application, the caching system was extracted into a standalone reusable project:
TriCacheLLM-MMA
- PyPI: https://pypi.org/project/TriCacheLLM-MMA/
- GitHub: https://github.com/mohib-ash/TriCacheLLM_MMA
The standalone project turns the Talk2Docs-specific implementation into a reusable caching architecture that can be integrated into other LLM applications.
Talk2Docs therefore serves as the initial production-style integration and validation environment for the architecture, while TriCacheLLM-MMA is its reusable evolution.
Cached answers are not treated as universally valid.
AnswerAI cache entries can contain information such as:
question
response
document IDs
cache policy
citations
provenance
source versions
For document-grounded answers, source versions are checked before reusing cached data.
This prevents an answer generated from an older document version from being blindly reused after the underlying source has changed.
ConvoAI is the stateful conversational AI system within Talk2Docs.
Unlike AnswerAI, ConvoAI is not simply:
Question β Retrieval β Answer
It is an agentic system capable of deciding when external information or stored context is required.
User Message
β
βΌ
ConvoAI
β
βΌ
Tool Selection
β
ββββββββββββββββΌββββββββββββββββ
β β β
βΌ βΌ βΌ
Memory AnswerAI Web Search
β β β
ββββββββββββββββ€ β
β β β
βΌ βΌ βΌ
Current Session Documents Current Facts
LTM
β
βΌ
Global Session LTM
+
General Intent
Classifier
The model decides which tool is appropriate based on the request and available context.
ConvoAI currently has five major tool capabilities.
Used when the user asks about:
- Uploaded documents
- Project-specific knowledge
- Custom document canon
- Indexed content
ConvoAI can invoke AnswerAI internally rather than requiring an external HTTP request.
ConvoAI
β
βΌ
AnswerAI Tool
β
βΌ
Document Retrieval
β
βΌ
Grounded Result
β
βΌ
ConvoAI
Used when relevant information exists earlier in the current conversation but is no longer present in the immediate context.
The current conversation maintains recent context separately.
Current Conversation
β
βββ Latest 5 Q&A
β β
β βββ Recent Context
β
βββ Older Conversation Data
β
βΌ
Current-Session LTM
β
βΌ
Semantic Retrieval
This allows ConvoAI to retrieve older information from the same conversation without repeatedly placing the entire conversation into the prompt.
Global LTM allows ConvoAI to retrieve relevant information from previous conversation sessions.
Conversation A
β
βββ Memory
β
βΌ
Conversation B
β
βββ New Question
β
βΌ
Global LTM Search
β
βΌ
Relevant Information
This allows useful information to persist beyond a single conversation ID.
ConvoAI can use web search when the request depends on current or external information.
Examples:
Latest API version
Current news
Recent events
Current documentation
Real-time facts
The model decides when web search is required rather than blindly searching every question.
Ambiguous or unresolved conversational references can be sent to a general intent classifier.
Examples include:
"What about the other one?"
"No, I meant the thing we discussed earlier."
"Which one was that?"
The classifier helps resolve vague references before ConvoAI produces a final answer.
The model handles tool selection while the application controls the actual execution loop.
Conceptually:
User Message
β
βΌ
ConvoAI Model
β
βΌ
Tool Call?
β
βββββ΄βββββ
β β
NO YES
β β
βΌ βΌ
Answer Execute Tool
β
βΌ
ToolMessage
β
βΌ
ConvoAI Model
β
βΌ
Tool Call?
β
...
β
βΌ
Final Response
The application limits tool execution rounds to prevent uncontrolled tool loops.
The current implementation uses explicit orchestration rather than hiding execution inside a generic agent executor.
This keeps:
- Tool dispatch
- Error handling
- Logging
- Database access
- Async execution
- Internal service calls
under application control.
Talk2Docs separates recent context from semantic long-term memory.
Conversation
β
βββββββββββββ΄ββββββββββββ
β β
βΌ βΌ
Recent Context Semantic Memory
Latest 5 β
Q&A β
β ββββββββ΄βββββββ
β β β
β βΌ βΌ
β Current Session Global
β LTM LTM
β β β
βββββββββββββββββ΄ββββββββββββββ
β
βΌ
ConvoAI
This avoids unnecessarily sending an entire conversation history on every request while still allowing older information to be recovered semantically.
Conversational caching is intentionally different from document-answer caching.
T1 Exact Cache
β
βΌ
Duplicate Protection
ConvoAI does not rely on semantic T2/T3 response caching for normal conversational requests.
The reason is contextual correctness.
Two semantically similar conversational questions can require different answers depending on:
- Previous conversation
- Current topic
- Tool state
- User intent
- Retrieved memory
- Position within the conversation
Therefore ConvoAI uses exact T1 caching primarily for duplicate-request protection.
T1 Exact
β
T2 Semantic Redis
β
T3 Semantic Chroma
β
AI Pipeline
AnswerAI benefits much more directly from semantic response reuse because document-grounded questions can be validated against their source versions.
Talk2Docs distinguishes between:
conversation_id
and:
request_id
Identifies a conversational branch/session.
Identifies an individual API operation and is used for request correlation and tracing.
This distinction allows users to maintain multiple ongoing conversations while individual requests remain independently traceable.
The current system effectively contains two different question pipelines.
USER
β
βΌ
Question Route
β
βΌ
T1 Exact Cache
β
βββββββ΄ββββββ
HIT MISS
β β
βΌ βΌ
Response Cache Classification
β
βΌ
T2 Semantic Redis
β
ββββββββ΄βββββββ
HIT MISS
β β
βΌ βΌ
Response T3 Chroma
β
ββββββββ΄βββββββ
HIT MISS
β β
βΌ βΌ
Response Query Classification
β
βΌ
Retrieval Strategy
β
βΌ
Hybrid Retrieval
β
βΌ
Reranking
β
βΌ
AnswerAI
β
βΌ
Structured Response
β
βΌ
Cache Population
USER
β
βΌ
ConvoAI
β
βΌ
T1 Exact Cache
β
βββββββ΄ββββββ
HIT MISS
β β
βΌ βΌ
Response Recent Context
β
βΌ
Agentic Tool Selection
β
ββββββββββββββββββββββΌββββββββββββββββββββ
β β β
βΌ βΌ βΌ
Current LTM AnswerAI Web Search
β β β
ββββββββββββββββββββββΌββββββββββββββββββββ
β
βΌ
General Classifier
when required
β
βΌ
Tool Execution
β
βΌ
Final Response
Talk2Docs has been benchmarked at the retrieval-pipeline level.
Current retrieval benchmarks were performed against a single indexed document and should not be interpreted as final large-scale production benchmarks.
| Technique | Retriever + Classifier | Retrieval Strategy | Reranker | Total |
|---|---|---|---|---|
| Step-Back | 739.50 ms | 826.49 ms | 1258.61 ms | 2.825 s |
| HyDE | 801.31 ms | 1503.64 ms | 807.36 ms | 3.112 s |
| Advanced Translation | 739.19 ms | 471.04 ms | 1129.38 ms | 2.340 s |
| Query Decomposition | 902.63 ms | 721.46 ms | 673.91 ms | 2.298 s |
| Multi-Index | 658.66 ms | 2760.05 ms | 645.60 ms | 4.064 s |
The three cache tiers have also been tested independently:
T1 Exact Redis
β
βββ PASS
T2 Semantic Redis
β
βββ PASS
T3 Chroma + Cohere
β
βββ PASS
The T3 validation specifically confirmed:
Chroma similarity search
β
Valid candidates
β
Cohere reranking
β
Cache hit
Talk2Docs uses authenticated, user-scoped access throughout the system.
Security mechanisms include:
- JWT authentication
- OAuth2PasswordBearer
- Redis-backed sessions
- Session revocation
- User ban support
- User-scoped PostgreSQL queries
- User-scoped vector databases
- Rate limiting
- File validation
- File signature validation
- Upload size limits
- Centralized exception handling
Document access is scoped using authenticated user identity rather than trusting arbitrary user-provided identifiers.
Conceptually:
Authenticated User
+
Request ID
+
Resource ID
β
Authorized Resource
Talk2Docs uses SlowAPI for API-level rate limiting.
Example:
@limiter.limit("3/minute")Rate limiting protects sensitive endpoints against excessive requests.
Uploads are asynchronous, so clients can monitor processing status.
Example endpoint:
GET /upload_worker/{task_id}/{request_id}
The endpoint combines transient Celery state with persistent PostgreSQL document state.
Example:
{
"worker": {
"status": "processing",
"task_id": "...",
"state": "STARTED"
},
"document": {
"status": "PROCESSING",
"failure_reason": null
},
"multi_index": {
"doc_id": 42,
"summary_status": "PROCESSING",
"explanation_status": "PENDING"
}
}This prevents transient worker state from being confused with persistent document state.
I also have a conversiaon_id pooling endpoint which fron-end is expected to call before invoking convoAi:
@router.get("/convo-id")
async def create_convo_id(user_id: int = Depends(get_user_jwt_payload), db: AsyncSession = Depends(get_db)):
convo_id: str = create_conversation_id(user_id)
request_id = str(uuid.uuid4())
return APIResponse(
success=True,
data={"convo_id": convo_id},
)Internal services use a common response representation:
success
+
data
+
error_code
+
error_message
Conceptually:
APIResponse(
success=True,
data=...,
error_code=None,
error_message=None
)This provides a predictable boundary between:
- Business-level failures
- Validation failures
- AI failures
- Infrastructure failures
- Unhandled application exceptions
AI output is not blindly trusted.
Structured AI responses are validated through Pydantic models.
The general approach is:
AI Output
β
βΌ
Parse
β
βΌ
Validate
β
ββββ΄βββ
β β
PASS FAIL
β β
βΌ βΌ
Use Recovery
β
βΌ
Validate
β
βββ΄ββ
β β
PASS FAIL
β β
βΌ βΌ
Use Error
The same philosophy is applied to:
- Answer generation
- Query classification
- Reranking
- ConvoAI structured output
- Tool results where validation is required
A simplified representation:
Talk2Docs/
β
βββ Ai/
β βββ answer_ai.py
β βββ query_classifier.py
β βββ retry_logic.py
β βββ ai_utils.py
β βββ convo_ai/
β βββ reranker/
β βββ query_construction/
β βββ HYDE/
β βββ multi_query/
β βββ multi_indexing/
β βββ query_decomp/
β βββ step_back/
β βββ advanced_translation/
β
βββ celery_worker/
β βββ celery_app.py
β βββ Tasks/
β βββ Ai_worker/
β βββ embedding_worker.py
β βββ ingestion_worker.py
β βββ chat_worker.py
β
βββ routers/
β βββ Ai/
β βββ auth/
β βββ users/
β
βββ db_tables/
β
βββ vector_db/
β
βββ docling/
β
βββ core/
β βββ Exceptions/
β βββ rate_limiters/
β
βββ utils/
β βββ logging/
β βββ schemas/
β
βββ alembic/
β
βββ nginx/
β
βββ ...
- Python 3.12+
- FastAPI
- Pydantic v2
- SQLAlchemy 2.0 Async
- Alembic
- LangChain
- Sentence Transformers
- ChromaDB
- BM25
- Hybrid Retrieval
- Reciprocal Rank Fusion
- Multi-Query
- HyDE
- Step-Back
- Query Decomposition
- Advanced Query Translation
- Multi-Index Retrieval
- Cohere Encoder Reranking
- Structured Pydantic AI output
- LangChain tool calling
- Agentic tool orchestration
- Semantic current-session memory
- Semantic cross-session memory
- Web search
- Document QA as an internal tool
- General intent classification
- Docling
- HybridChunker
- Content validation
- Signature validation
- Celery
- Redis
- PostgreSQL
- ChromaDB
- Redis
- Persistent BM25 artifacts
- JWT
- OAuth2PasswordBearer
- Redis-backed sessions
- Session revocation
- SlowAPI
- User-scoped retrieval
- Nginx
- Structured logging
- Centralized exception handling
- Celery lifecycle tracking
- Persistent document status tracking
Routes, services, workers, retrieval systems, AI systems and storage have distinct responsibilities.
HTTP
β
Service
β
AI / Retrieval / Database
β
APIResponse
Retrieval strategies can evolve without forcing AnswerAI to understand their internal implementation.
Retrieval Strategy
β
list[LangChainDocument]
β
Reranker
β
AnswerAI
Documents, vector databases, caches and semantic memories are scoped to authenticated users.
User A
βββ Documents
βββ VDBs
βββ Cache
βββ Memory
User B
βββ Documents
βββ VDBs
βββ Cache
βββ Memory
Expensive work is moved away from HTTP request execution whenever possible.
HTTP Request
β
βΌ
FastAPI
β
βΌ
Dispatch
β
βΌ
Celery / Background Task
β
βΌ
Expensive Work
The system does not treat every question as the same type of problem.
A request may require:
Document Retrieval
OR
Recent Conversation Context
OR
Current-Session Memory
OR
Global Memory
OR
Web Search
OR
General Intent Resolution
The goal is to retrieve the right information source, rather than simply retrieving more information.
- FastAPI
- Async SQLAlchemy
- PostgreSQL
- Alembic
- JWT authentication
- OAuth2PasswordBearer
- Redis-backed sessions
- Session revocation
- Celery integration
- Rate limiting
- Centralized exception handling
- Structured logging
- Nginx integration
- File validation
- File persistence
- Document metadata
- Asynchronous upload processing
- Docling parsing
- HybridChunker
- Embedding generation
- Raw ChromaDB indexing
- Document state tracking
- Celery retry handling
- Worker status polling
- Raw VDB
- Summary VDB
- Explanation VDB
- Summary AI
- Explanation AI
- Shared
chunk_id - Multi-index lifecycle tracking
- Background construction
- Summary retrieval
- Explanation retrieval
- Parallel secondary retrieval
- Raw chunk resolution
- Vector retrieval
- BM25 retrieval
- Hybrid retrieval
- Ensemble retrieval
- Reciprocal Rank Fusion
- Multi-Query
- HyDE
- Step-Back
- Advanced translation
- Query decomposition
- Multi-index retrieval
- Common
list[LangChainDocument]retrieval contract - AI reranking
- Reranker validation
- Candidate validation
- Persistent user-scoped BM25
- T1 exact Redis cache
- T2 semantic Redis vector cache
- T3 persistent Chroma semantic cache
- Cohere cache reranking
- Cache source-version validation
- Cache provenance metadata
- Asynchronous cache population
- AnswerAI three-tier caching
- ConvoAI T1-only duplicate protection
- Conversation IDs
- Recent conversational context
- Latest-five Q&A context
- ConvoAI
- Agentic tool selection
- Manual tool execution loop
- AnswerAI tool
- Web search tool
- Current-session semantic LTM
- Global semantic LTM
- General intent classifier tool
- Structured ConvoAI responses
- Tool execution logging
- Document-grounded answers
- Structured Pydantic output
- Source citations
- Verbatim evidence
- Confidence scoring
- Meaning-preservation validation
The core document intelligence, caching, and agentic conversation architecture is now implemented.
The next major feature is tabular document intelligence for CSV and XLSX files.
Unlike normal document QA, tabular questions should not rely on treating rows as ordinary text chunks. Instead, Talk2Docs will understand the table schema, retrieve the relevant structural information, and generate validated Pandas operations against the original file at question time.
The planned architecture is:
Upload
β
βΌ
βββββββββββββββββββββββββββ
β Background Tabular β
β Worker β
β β
β Detect CSV / XLSX β
ββββββββββββββ¬βββββββββββββ
β
βΌ
βββββββββββββββββββββββββββ
β Extract Schema + β
β Metadata β
β β
β β’ Column names β
β β’ Data types β
β β’ Table structure β
β β’ Useful metadata β
ββββββββββββββ¬βββββββββββββ
β
βΌ
Index Schema
β
βΌ
Schema VDB / Index
β
β
Original File Remains
the Source of Truth
β
βΌ
User Question
β
βΌ
Retrieve Relevant
Schema
β
βΌ
Load Original File
at Runtime
β
βΌ
Pandas DataFrame
β
βΌ
βββββββββββββββββββββββββββ
β LLM 1 β
β β
β Question + Schema β
β β β
β Pydantic Output β
β β β
β Pandas Code β
ββββββββββββββ¬βββββββββββββ
β
βΌ
Validation
β
βββββββββββββββΌββββββββββββββ
β β β
βΌ βΌ βΌ
Column Check AST Check Forbidden
vs Schema / Allowed Operations
Code Rules
β β β
βββββββββββββββΌββββββββββββββ
β
βΌ
Isolated Execution
β
βΌ
Execute Pandas Code
Against DataFrame
β
βΌ
Deterministic Result
β
βΌ
βββββββββββββββββββββββββββ
β LLM 2 β
β β
β Original Question β
β + Relevant Schema β
β + Executed Result β
β β β
β Final Natural Language β
β Answer β
βββββββββββββββββββββββββββ
CSV and XLSX files will be preserved after upload.
The VDB will store schema and metadata, not the authoritative table contents.
At question time, the original file will be loaded into a Pandas DataFrame and used for deterministic computation.
Original CSV/XLSX
β
βΌ
Runtime DataFrame
β
βΌ
Validated Pandas Operation
β
βΌ
Deterministic Result
This avoids relying on an LLM to perform arithmetic, filtering, aggregation, or other operations over retrieved text chunks.
The system will first retrieve the relevant table schema.
For example:
Question:
"What was the average salary of employees in the Finance department?"
Retrieved Schema:
employees
βββ employee_id: integer
βββ name: string
βββ department: string
βββ salary: float
βββ joining_date: datetime
The schema gives the model the structural information it needs to generate the Pandas operation.
The first model will receive:
Original Question
+
Relevant Table Schema
and produce structured output through Pydantic.
Conceptually:
Question + Schema
β
βΌ
LLM
β
βΌ
Pydantic Model
β
βΌ
Validated Pandas Code
The model will not directly execute its own output.
Generated Pandas code will pass through a validation layer before execution.
Validation will include:
- Column names must exist in the retrieved schema
- Only permitted operations/functions may be used
- Python AST must satisfy the allowed structure
- Forbidden operations must be rejected
- Unexpected imports or filesystem/network access must be blocked
- Generated code must operate only on the intended DataFrame
The goal is to treat model-generated code as untrusted input.
LLM Generated Code
β
βΌ
Validate
β
ββββββ΄βββββ
β β
Valid Invalid
β β
βΌ βΌ
Execute Reject
Only validated Pandas operations will be executed against the runtime DataFrame.
The execution layer will produce a deterministic result.
DataFrame
+
Validated Pandas Code
β
βΌ
Execution
β
βΌ
Deterministic Result
The LLM does not calculate the result itself.
It asks Pandas to perform the computation and receives the actual result.
The final model will receive:
Original Question
+
Relevant Schema
+
Executed Result
and convert the deterministic result into a natural-language answer.
Question
+
Schema
+
Actual Computed Result
β
βΌ
LLM 2
β
βΌ
Final Answer
This separates computation from explanation.
The first model determines what operation should be performed.
Pandas determines what the actual result is.
The second model determines how that result should be explained to the user.
The important difference between ordinary document QA and tabular QA is that a table often requires computation rather than retrieval.
For example:
"What was the total revenue in Q3?"
should not be answered by hoping the LLM finds a matching sentence in a vector database.
Instead:
Question
β
Schema Retrieval
β
Pandas Code Generation
β
Code Validation
β
Actual DataFrame Execution
β
Deterministic Result
β
Natural Language Answer
This allows Talk2Docs to use RAG for understanding the structure of the data, while using deterministic execution for the actual computation.
After the initial CSV/XLSX pipeline is implemented, the next focus will be:
- Stronger generated-code validation
- Execution sandboxing and resource limits
- Better handling of multiple sheets in XLSX
- Large-file handling
- Schema/version validation
- Better error recovery when generated code fails
- Regression and integration testing
- Performance testing
- Production monitoring and observability
The overall goal is to make tabular QA another first-class workload inside Talk2Docs rather than treating spreadsheets as ordinary text documents.
- Larger multi-document benchmarks
- Load testing
- Expanded regression test suite
- More provider failure/recovery testing
- Expanded observability
- CI/CD
- Production deployment
- Monitoring
- Larger-corpus retrieval benchmarking
- Further model/provider benchmarking
- Retrieval quality evaluation datasets
- More advanced agentic workflows
- Additional tool integrations
- Further memory ranking improvements
- Memory lifecycle optimization
- More sophisticated context compression
- Long-running conversation optimization
- Advanced CSV/XLSX question-answering pipeline
- Tabular-data-specific retrieval
- Additional document formats
Talk2Docs started as a document-processing backend.
It gradually evolved into a system designed around a larger question:
How can an AI application decide what information it actually needs before answering?
The result is no longer simply:
Document
β
Embeddings
β
Vector Search
β
LLM
Instead:
USER
β
βββββββββββββ΄ββββββββββββ
β β
βΌ βΌ
Document QA ConvoAI
β β
βΌ βΌ
Cache Layers Tool Selection
β β
βΌ ββββββββββΌββββββββββ
Query Intelligence β β β
β LTM Web AnswerAI
βΌ β β β
Hybrid Retrieval ββββββββββΌββββββββββ
β β
βΌ βΌ
Reranking Agentic Context
β β
βΌ βΌ
Grounded Answer Structured Response
Talk2Docs is therefore a combination of:
Document Processing
+
Advanced RAG
+
Hybrid Retrieval
+
Multi-Index Retrieval
+
Three-Tier Semantic Caching
+
Conversational Memory
+
Agentic Tool Use
+
Structured AI Responses
MIT License
Built with:
FastAPI Β· Celery Β· Docling Β· LangChain Β· ChromaDB Β· PostgreSQL Β· Redis Β· Pydantic Β· Sentence Transformers Β· Cohere