AI Chat API (RAG)
Query your contracts, knowledge base, and documents using AI-powered retrieval-augmented generation.
Endpoints
| Method | Path | Description |
|---|---|---|
POST | /chat/send | Send a message |
GET | /chat/history | Get conversation history |
POST | /chat/sync-contracts | Sync contracts to vector store |
GET | /chat/stats | Get RAG system stats |
Send Message
POST /api/v1/chat/send{
"message": "What are the termination clauses in our Acme NDA?",
"conversation_id": "optional-conv-uuid",
"stream": true
}| Field | Type | Required | Description |
|---|---|---|---|
message | string | ✅ | Your question |
conversation_id | string | — | Continue existing conversation |
stream | boolean | — | Enable SSE streaming (default: true) |
Streaming Response (Server-Sent Events):
data: {"type": "chunk", "content": "The Acme NDA contains"}
data: {"type": "chunk", "content": " a 30-day termination clause"}
data: {"type": "chunk", "content": " in Section 7.2."}
data: {"type": "citations", "sources": [{"title": "NDA - Acme Corp", "page": 4, "relevance": 0.89}]}
data: {"type": "done", "conversation_id": "conv-uuid"}The AI searches across 3 collections: your contracts, knowledge base documents, and uploaded user documents — all scoped to your organization.
How RAG Works
User Question
↓
Embed with text-embedding-3-large (3072 dims)
↓
Search Qdrant (3 collections × org_id filter)
↓
Filter by relevance score ≥ 0.35
↓
Deduplicate overlapping chunks
↓
Build context (max 28,000 chars)
↓
GPT-5.1 generates answer with citations
↓
Stream response via SSEGet Conversation History
GET /api/v1/chat/history?conversation_id=conv-uuidResponse:
{
"conversation_id": "conv-uuid",
"messages": [
{
"role": "user",
"content": "What are the termination clauses in our Acme NDA?",
"timestamp": "2026-03-08T12:00:00Z"
},
{
"role": "assistant",
"content": "The Acme NDA contains a 30-day termination clause...",
"citations": [
{
"title": "NDA - Acme Corp",
"page": 4,
"section": "Section 7.2",
"relevance": 0.89
}
],
"timestamp": "2026-03-08T12:00:03Z"
}
]
}Sync Contracts
Index all organization contracts into the vector store for AI search.
POST /api/v1/chat/sync-contracts⚠️
This endpoint re-indexes all contracts. Use after bulk uploads or when first setting up.
RAG Stats
GET /api/v1/chat/stats{
"collections": {
"contracts_kb": {"vectors": 1250, "status": "green"},
"knowledge_base": {"vectors": 340, "status": "green"},
"user_documents": {"vectors": 89, "status": "green"}
},
"models": {
"primary": "gpt-5.1",
"mini": "gpt-5-mini",
"premium": "gpt-5.4",
"fallback": "claude-sonnet-4-20250514",
"embedding": "text-embedding-3-large"
},
"config": {
"embedding_dim": 3072,
"min_relevance_score": 0.35,
"max_context_chars": 28000
}
}