curl -X POST http://localhost:8000/query \
-H "Content-Type: application/json" \
-d '{
"query": "What is the refund policy?",
"max_results": 3,
"use_llm": true
}'
import requests
response = requests.post(
"http://localhost:8000/query",
json={
"query": "What is the refund policy?",
"max_results": 3,
"use_llm": True
}
)
result = response.json()
print(result["answer"])
for source in result["sources"]:
print(f"Source: {source['filename']} (score: {source['relevance_score']})")
const response = await fetch('http://localhost:8000/query', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
query: 'What is the refund policy?',
max_results: 3,
use_llm: true
})
});
const result = await response.json();
console.log(result.answer);
{
"query_id": "123e4567-e89b-12d3-a456-426614174000",
"answer": "According to our documents, the refund policy allows returns within 30 days for all unused products. Refunds are processed within 7 business days to the original payment method. Return shipping costs are the customer's responsibility except for defective products.",
"sources": [
{
"document_id": "doc-123",
"filename": "refund_policy.pdf",
"chunk_index": 2,
"relevance_score": 0.94
},
{
"document_id": "doc-456",
"filename": "terms_conditions.pdf",
"chunk_index": 8,
"relevance_score": 0.87
},
{
"document_id": "doc-123",
"filename": "refund_policy.pdf",
"chunk_index": 3,
"relevance_score": 0.82
}
],
"execution_time_ms": 1234,
"timestamp": "2024-02-17T10:30:45.123Z"
}
{
"query_id": "123e4567-e89b-12d3-a456-426614174001",
"answer": null,
"sources": [
{
"document_id": "doc-123",
"filename": "refund_policy.pdf",
"chunk_index": 2,
"relevance_score": 0.94
}
],
"execution_time_ms": 234,
"timestamp": "2024-02-17T10:31:12.456Z"
}
{
"query_id": "123e4567-e89b-12d3-a456-426614174002",
"answer": "I could not find relevant documents to answer your question.",
"sources": [],
"execution_time_ms": 456,
"timestamp": "2024-02-17T10:32:00.789Z"
}
API Reference
Process Query
Process a user query and return an LLM-generated response
POST
/
query
curl -X POST http://localhost:8000/query \
-H "Content-Type: application/json" \
-d '{
"query": "What is the refund policy?",
"max_results": 3,
"use_llm": true
}'
import requests
response = requests.post(
"http://localhost:8000/query",
json={
"query": "What is the refund policy?",
"max_results": 3,
"use_llm": True
}
)
result = response.json()
print(result["answer"])
for source in result["sources"]:
print(f"Source: {source['filename']} (score: {source['relevance_score']})")
const response = await fetch('http://localhost:8000/query', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
query: 'What is the refund policy?',
max_results: 3,
use_llm: true
})
});
const result = await response.json();
console.log(result.answer);
{
"query_id": "123e4567-e89b-12d3-a456-426614174000",
"answer": "According to our documents, the refund policy allows returns within 30 days for all unused products. Refunds are processed within 7 business days to the original payment method. Return shipping costs are the customer's responsibility except for defective products.",
"sources": [
{
"document_id": "doc-123",
"filename": "refund_policy.pdf",
"chunk_index": 2,
"relevance_score": 0.94
},
{
"document_id": "doc-456",
"filename": "terms_conditions.pdf",
"chunk_index": 8,
"relevance_score": 0.87
},
{
"document_id": "doc-123",
"filename": "refund_policy.pdf",
"chunk_index": 3,
"relevance_score": 0.82
}
],
"execution_time_ms": 1234,
"timestamp": "2024-02-17T10:30:45.123Z"
}
{
"query_id": "123e4567-e89b-12d3-a456-426614174001",
"answer": null,
"sources": [
{
"document_id": "doc-123",
"filename": "refund_policy.pdf",
"chunk_index": 2,
"relevance_score": 0.94
}
],
"execution_time_ms": 234,
"timestamp": "2024-02-17T10:31:12.456Z"
}
{
"query_id": "123e4567-e89b-12d3-a456-426614174002",
"answer": "I could not find relevant documents to answer your question.",
"sources": [],
"execution_time_ms": 456,
"timestamp": "2024-02-17T10:32:00.789Z"
}
Process Query
Main endpoint for querying the RAG system. Performs semantic search in your documents and generates an intelligent response based on the found context.Endpoint
POST /query
Request Body
string
required
The user’s question or query
string
ID of the collection to query (default: all collections)
integer
default:"5"
Maximum number of source documents to retrieve (1-20)
boolean
default:"true"
Use the LLM to generate a response. If false, returns only relevant sources.
object
Metadata filters to refine the search
{
"document_type": "pdf",
"category": "finance"
}
Response
string
Unique query identifier
string
Response generated by the LLM (null if use_llm=false)
array
integer
Execution time in milliseconds
string
ISO 8601 query timestamp
Examples
curl -X POST http://localhost:8000/query \
-H "Content-Type: application/json" \
-d '{
"query": "What is the refund policy?",
"max_results": 3,
"use_llm": true
}'
import requests
response = requests.post(
"http://localhost:8000/query",
json={
"query": "What is the refund policy?",
"max_results": 3,
"use_llm": True
}
)
result = response.json()
print(result["answer"])
for source in result["sources"]:
print(f"Source: {source['filename']} (score: {source['relevance_score']})")
const response = await fetch('http://localhost:8000/query', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
query: 'What is the refund policy?',
max_results: 3,
use_llm: true
})
});
const result = await response.json();
console.log(result.answer);
{
"query_id": "123e4567-e89b-12d3-a456-426614174000",
"answer": "According to our documents, the refund policy allows returns within 30 days for all unused products. Refunds are processed within 7 business days to the original payment method. Return shipping costs are the customer's responsibility except for defective products.",
"sources": [
{
"document_id": "doc-123",
"filename": "refund_policy.pdf",
"chunk_index": 2,
"relevance_score": 0.94
},
{
"document_id": "doc-456",
"filename": "terms_conditions.pdf",
"chunk_index": 8,
"relevance_score": 0.87
},
{
"document_id": "doc-123",
"filename": "refund_policy.pdf",
"chunk_index": 3,
"relevance_score": 0.82
}
],
"execution_time_ms": 1234,
"timestamp": "2024-02-17T10:30:45.123Z"
}
{
"query_id": "123e4567-e89b-12d3-a456-426614174001",
"answer": null,
"sources": [
{
"document_id": "doc-123",
"filename": "refund_policy.pdf",
"chunk_index": 2,
"relevance_score": 0.94
}
],
"execution_time_ms": 234,
"timestamp": "2024-02-17T10:31:12.456Z"
}
{
"query_id": "123e4567-e89b-12d3-a456-426614174002",
"answer": "I could not find relevant documents to answer your question.",
"sources": [],
"execution_time_ms": 456,
"timestamp": "2024-02-17T10:32:00.789Z"
}
Error Codes
Bad Request
Invalid request (missing or incorrect parameters)
Internal Server Error
Server error (LLM unavailable, processing error)
Gateway Timeout
Request timeout (>60 seconds)
Best Practices
Optimize Performance
Optimize Performance
- Adjust
max_resultsaccording to your needs (less = faster) - Use
use_llm=falsefor pure search without generation - Add metadata filters to refine the search
Improve Answer Quality
Improve Answer Quality
- Formulate clear and precise questions
- Use terms specific to your domain
- Increase
max_resultsfor more context (5-10)
Use Metadata Filters
Use Metadata Filters
{
"query": "What is the procedure?",
"metadata_filter": {
"department": "HR",
"year": "2024"
}
}
Handle Errors
Handle Errors
try:
response = requests.post(url, json=data, timeout=60)
response.raise_for_status()
result = response.json()
except requests.Timeout:
print("The request took too long")
except requests.HTTPError as e:
print(f"HTTP Error: {e}")
Limitations
- Timeout: 60 seconds maximum per query
- Query length: 1000 characters maximum
- LLM context: Limited by model’s context window (~2048-4096 tokens)
Technical Notes
Search Process
- Query embedding: Conversion to vector (384 dimensions)
- Vector search: K-nearest neighbors search in Qdrant (cosine similarity)
- Filtering: Application of metadata filters if provided
- Relevance threshold: Only results with score > 0.7 are kept
- Content retrieval: Getting full text of chunks
- LLM generation: Prompt construction and response generation
LLM Prompt Format
Provided context:
Document 1:
[Most relevant chunk content]
Document 2:
[2nd chunk content]
...
Question: [Your question]
Answer the question based ONLY on the context provided above.
If the context does not contain enough information to answer, say so clearly.
Cite the document numbers you use in your answer.
See Also
Upload Documents
Add documents to the system
Collections
Organize your documents

