Search API
Search across your indexed documents using the Search API.
Search Documents
Endpoint
POST /v1/search
Request Body
{
"query": "How do I configure the database?",
"collections": ["col_abc123"],
"limit": 10,
"filters": {
"topics": ["engineering"],
"dateRange": {
"start": "2024-01-01",
"end": "2024-12-31"
}
}
}
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
query | string | Yes | Search query |
collections | string[] | No | Collection IDs to search |
limit | number | No | Max results (default: 10, max: 100) |
offset | number | No | Pagination offset |
filters | object | No | Filter criteria |
rerank | boolean | No | Enable reranking (default: true) |
Filters Object
| Field | Type | Description |
|---|---|---|
topics | string[] | Filter by topics |
departments | string[] | Filter by departments |
languages | string[] | Filter by languages |
dateRange | object | Date range filter |
sources | string[] | Filter by connector IDs |
Response
{
"data": {
"results": [
{
"id": "doc_xyz789",
"title": "Database Configuration Guide",
"content": "To configure the database...",
"score": 0.95,
"metadata": {
"source": "Confluence",
"collection": "Engineering Docs",
"createdAt": "2024-03-15T10:00:00Z"
},
"highlights": [
"To <mark>configure</mark> the <mark>database</mark>..."
]
}
],
"total": 42,
"facets": {
"topics": [
{ "value": "database", "count": 15 },
{ "value": "configuration", "count": 12 }
]
}
},
"meta": {
"requestId": "req_abc123",
"took": 145
}
}
Example Usage
cURL
curl -X POST https://api.zensearch.ai/v1/search \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"query": "database configuration",
"limit": 5
}'
JavaScript
const results = await client.search({
query: 'database configuration',
collections: ['col_abc123'],
limit: 5,
filters: {
topics: ['engineering']
}
});
Python
results = client.search(
query="database configuration",
collections=["col_abc123"],
limit=5,
filters={"topics": ["engineering"]}
)
Advanced Search
Hybrid Search
Enable both semantic and keyword search:
{
"query": "error code ERR_CONNECTION_REFUSED",
"hybridSearch": true,
"hybridWeight": 0.7
}
Query Expansion
Enable automatic query expansion:
{
"query": "login issues",
"queryExpansion": true
}
Error Responses
| Code | Description |
|---|---|
| 400 | Invalid request parameters |
| 401 | Authentication required |
| 403 | Insufficient permissions |
| 429 | Rate limit exceeded |
Next Steps
- Chat API - Conversational search
- Documents API - Document management