Repository navigation
Closed
Labels
Description
Summary
Add a new endpoint to the RAG service that returns the full (or paginated) text content of an indexed document. Currently, the RAG service only exposes chunk-level search — there is no way for agents or workflows to retrieve the complete text of a specific document.
Motivation
Several advanced use cases require reasoning over full documents rather than top-k chunks:
- Drafting new documents based on existing templates/precedents
- Comparing multiple documents end-to-end
- Systematic document review (e.g., due diligence reports)
The existing rag_search tool returns relevance-ranked chunks (top_k=10), which is great for Q&A but insufficient when complete document structure matters.
Proposed API
GET /api/v1/documents/{doc_id}/content
Query Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
page_start |
int | 1 | Start page (1-indexed) |
page_end |
int | null | End page (inclusive). If null, return from page_start to end |
team_id |
string | required | Tenant scoping |
Response
{
"document_id": "...",
"title": "...",
"content": "...",
"page_range": { "start": 1, "end": 10 },
"total_pages": 50,
"truncated": false,
"total_chars": 45000
}Implementation Notes
- Cap single response at ~50K chars to prevent LLM context overflow
- Set
truncated: truewhen content exceeds the cap - Two possible implementation strategies:
- Option A: Reassemble from stored chunks in order (fast, but may have gaps at chunk boundaries)
- Option B: Re-extract from the original file stored in object storage (accurate, supports native page ranges for PDFs)
- Must respect multi-tenant isolation (
team_idfiltering) - Consider adding a
total_pagesfield to document metadata during ingestion to support pagination
Acceptance Criteria
- New endpoint returns document content with pagination support
- Response capped at ~50K chars with
truncatedflag - Multi-tenant isolation enforced
- Returns 404 for non-existent documents
- Integration tests covering: normal retrieval, page ranges, truncation, access control
Activity
feat(rag): add document content retrieval endpoint
feat(rag): add document content retrieval endpoint