Search API
Perform semantic search across your indexed pages using three different approaches: path-based suggestions, query-based semantic search, or RAG retrieval for LLMs.
Overview
The Search API provides three endpoints for finding relevant content:
- Suggest - Path-based search with spell correction and path sanitization
- Semantic Search - Query-based search using natural language queries
- Retrieve - RAG retrieval API that returns full document content with citations and metadata
The suggest and semantic-search endpoints return suggestions with similarity scores and support metadata filtering and metadata return, while the retrieve endpoint is designed for RAG systems and returns full document content.
Important: All endpoints must be called from your server, never from the browser. Your API keys must remain private on your server. The typical architecture is:
Browser → Your Application Server → deadend.ai APISuggest (Path-based Search)
Endpoint: POST /v1/suggest
Purpose: Retrieve suggestions based on a URL path (same as original search-api implementation)
Authentication: Required (Bearer token)
Request
curl -X POST https://api.deadend.ai/v1/suggest \
-H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{
"path": "/products/blue-widget",
"limit": 3,
"options": {
"excludeUrls": ["/products/old-widget"],
"searchThreshold": 0.7
}
}'Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
path | string | Yes | The URL path to search for |
limit | number | No | Max results to return (default: 3) |
options | object | No | Additional search options |
Options Object
| Parameter | Type | Description |
|---|---|---|
excludeUrls | string[] | URLs to exclude from results |
searchThreshold | number | Min similarity score (0.0-1.0, default: 0.7) |
filters | object | Metadata filters to apply before vector search. Filters are applied to customMetadata fields (e.g., {"category": "Electronics"} filters by customMetadata.category). Multiple filters are combined with AND logic. Note: When filters are present, the search cache is bypassed to ensure accurate filtered results. |
Response (200 OK)
{
"suggestions": [
{
"url": "/products/blue-widget-v2",
"title": "Blue Widget V2",
"score": 0.92,
"metadata": {
"category": "Electronics",
"in_stock": true,
"price_range": "premium"
}
}
],
"search_id": "a1b2c3d4-e5f6-a7b8-c9d0-e1f2a3b4c5d6"
}Response Fields
| Field | Type | Description |
|---|---|---|
suggestions | array | Array of suggestion objects |
url | string | URL path of the suggested page |
title | string | Title of the suggested page |
score | number | Vector similarity score (0.0 to 1.0) |
metadata | object | Custom metadata object (optional, omitted if no metadata exists, from customMetadata field) |
search_id | string | Unique identifier for this search (used for click tracking) |
Features
- Path sanitization and spell correction
- Vector similarity search
- Configurable result limit and threshold
- Metadata filtering - Filter results by custom metadata fields before vector search
- Metadata in response - Receive metadata fields in search results for display context
Semantic Search (Query-based Search)
Endpoint: POST /v1/semantic-search
Purpose: Perform semantic search using a natural language query
Authentication: Required (Bearer token)
Request
curl -X POST https://api.deadend.ai/v1/semantic-search \
-H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{
"query": "blue widget products",
"limit": 3,
"options": {
"excludeUrls": ["/products/old-widget"],
"searchThreshold": 0.7
}
}'Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
query | string | Yes | The natural language search query |
limit | number | No | Max results to return (default: 3) |
options | object | No | Additional search options |
Options Object
| Parameter | Type | Description |
|---|---|---|
excludeUrls | string[] | URLs to exclude from results |
searchThreshold | number | Min similarity score (0.0-1.0, default: 0.7) |
filters | object | Metadata filters to apply before vector search. Filters are applied to customMetadata fields (e.g., {"category": "Electronics"} filters by customMetadata.category). Multiple filters are combined with AND logic. Note: When filters are present, the search cache is bypassed to ensure accurate filtered results. |
Response (200 OK)
{
"suggestions": [
{
"url": "/products/blue-widget-v2",
"title": "Blue Widget V2",
"score": 0.92,
"metadata": {
"category": "Electronics",
"in_stock": true,
"price_range": "premium"
}
}
],
"search_id": "a1b2c3d4-e5f6-a7b8-c9d0-e1f2a3b4c5d6"
}Response Fields
| Field | Type | Description |
|---|---|---|
suggestions | array | Array of suggestion objects |
url | string | URL path of the suggested page |
title | string | Title of the suggested page |
score | number | Vector similarity score (0.0 to 1.0) |
metadata | object | Custom metadata object (optional, omitted if no metadata exists, from customMetadata field) |
search_id | string | Unique identifier for this search (used for click tracking) |
Features
- Direct query processing (no path sanitization)
- Vector similarity search
- Same options as suggest endpoint
- Metadata filtering - Filter results by custom metadata fields before vector search
- Metadata in response - Receive metadata fields in search results for display context
Retrieve (RAG Retrieval API)
Endpoint: POST /v1/retrieve
Purpose: Retrieval API for RAG (Retrieval-Augmented Generation) systems. Returns full document content with citations and metadata, designed for building AI chatbots, support agents, or internal search tools.
Authentication: Required (Bearer token)
Request
curl -X POST https://api.deadend.ai/v1/retrieve \
-H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{
"query": "What is the return policy for items bought on sale?",
"top_k": 3,
"filters": {
"category": "Support",
"in_stock": true
}
}'Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
query | string | Yes | Natural language query string |
top_k | number | No | Number of documents to retrieve (default: 3) |
filters | object | No | Metadata filters to apply before vector search. Filters are applied to customMetadata fields (e.g., {"category": "Support"} filters by customMetadata.category) |
Response (200 OK)
{
"documents": [
{
"id": "page_id_123",
"url": "https://example.com/support/returns",
"title": "Return Policy | Example Co",
"content": "Our return policy is 30 days... Sale items are final sale...",
"score": 0.91,
"metadata": {
"category": "Support"
}
},
{
"id": "page_id_456",
"url": "https://example.com/support/faq",
"title": "Frequently Asked Questions",
"content": "How do I make a return? You can visit our returns portal...",
"score": 0.85,
"metadata": {
"category": "Support"
}
}
]
}Response Fields
| Field | Type | Description |
|---|---|---|
documents | array | Array of retrieved documents |
id | string | Page ID (MongoDB ObjectID as string) |
url | string | Full URL of the page |
title | string | Page title (if available) |
content | string | Full extracted text content from the page (from extractedText field) |
score | number | Vector similarity score (0.0 to 1.0) |
metadata | object | Custom metadata object (if available, from customMetadata field) |
Features
- Natural language query processing
- Filtered vector search with metadata pre-filtering
- Returns full document content (not just URLs/titles)
- Includes similarity scores for ranking
- Supports custom metadata filtering for scoped searches
Use Cases
- Building AI chatbots that need context from your indexed content
- Creating support agents that search your knowledge base
- Internal search tools that return full content snippets
- RAG systems that need citations and source documents
Error Responses
400 Bad Request: Missingqueryparameter or invalid request body401 Unauthorized: Invalid or missing API key403 Forbidden: Rate limit exceeded500 Internal Server Error: Vectorization or database errors
Metadata Filtering and Return Support
Both /v1/suggest and /v1/semantic-search endpoints now support metadata filtering and metadata return, bringing feature parity with the /v1/retrieve endpoint.
Metadata Filtering
You can filter search results by custom metadata fields using the options.filters parameter. Filters are applied before vector search for optimal performance, and multiple filters are combined with AND logic (all must match).
How It Works:
- Filter keys map to
customMetadata.<key>in MongoDB (e.g.,{"category": "Electronics"}filters bycustomMetadata.category) - Filters are applied before vector search for optimal query performance
- Multiple filters are combined with AND logic (all must match)
Example Request with Filters:
curl -X POST https://api.deadend.ai/v1/suggest \
-H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{
"path": "/products",
"limit": 5,
"options": {
"filters": {
"category": "Electronics",
"in_stock": true,
"price_range": "premium"
}
}
}'Metadata in Response
Search results now include metadata when available. The metadata field is optional and will be omitted if no metadata exists for a page.
Example Response with Metadata:
{
"suggestions": [
{
"url": "/products/laptop",
"title": "Gaming Laptop",
"score": 0.95,
"metadata": {
"category": "Electronics",
"brand": "TechCorp",
"in_stock": true,
"price_range": "premium"
}
}
],
"search_id": "a1b2c3d4-e5f6-a7b8-c9d0-e1f2a3b4c5d6"
}Cache Behavior
Important: When filters are present in the request, the search cache is bypassed. This ensures that filtered results are always accurate and not served from potentially unfiltered cached results.
- Without filters: Cache is checked first (fast path, ~10ms)
- With filters: Cache is skipped, full vector search is performed
Backward Compatibility
✅ Fully backward compatible:
- Existing requests without
filterscontinue to work unchanged filtersfield is optionalmetadatafield in response is optional (omitted if not present)- No breaking changes to existing API contracts
Comparison with /v1/retrieve
| Feature | /v1/suggest | /v1/semantic-search | /v1/retrieve |
|---|---|---|---|
| Metadata Filtering | ✅ Yes (in options.filters) | ✅ Yes (in options.filters) | ✅ Yes (in filters) |
| Metadata in Response | ✅ Yes | ✅ Yes | ✅ Yes |
| Full Content Return | ❌ No (URL/title only) | ❌ No (URL/title only) | ✅ Yes |
| Path Sanitization | ✅ Yes | ❌ No | ❌ No |
Understanding Similarity Scores
Scores indicate semantic relevance:
| Score Range | Relevance | Use Case |
|---|---|---|
| 0.9 - 1.0 | Excellent | Nearly exact matches |
| 0.8 - 0.9 | Very Good | Highly relevant results |
| 0.7 - 0.8 | Good | Relevant, recommended threshold |
| 0.6 - 0.7 | Moderate | Somewhat relevant |
| < 0.6 | Low | May be unrelated |
Recommended threshold: 0.7 for most use cases
Example Usage
cURL Examples
Suggest Endpoint:
curl -X POST https://api.deadend.ai/v1/suggest \
-H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{
"path": "/products/blue-widget",
"limit": 3
}'Suggest Endpoint with Metadata Filtering:
curl -X POST https://api.deadend.ai/v1/suggest \
-H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{
"path": "/products",
"limit": 5,
"options": {
"filters": {
"category": "Electronics",
"in_stock": true
}
}
}'Semantic Search Endpoint:
curl -X POST https://api.deadend.ai/v1/semantic-search \
-H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{
"query": "blue widget products",
"limit": 3
}'Semantic Search Endpoint with Metadata Filtering:
curl -X POST https://api.deadend.ai/v1/semantic-search \
-H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{
"query": "wireless headphones",
"limit": 3,
"options": {
"filters": {
"category": "Electronics",
"in_stock": true,
"price_range": "mid"
}
}
}'Retrieve Endpoint (RAG):
curl -X POST https://api.deadend.ai/v1/retrieve \
-H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{
"query": "What is the return policy?",
"top_k": 3,
"filters": {
"category": "Support"
}
}'Error Responses
See the Error Handling Guide for detailed error codes and examples.
Common errors include:
400 Bad Request- Missing or invalid parameters (e.g., missingpath,query, or invalid request body)401 Unauthorized- Invalid API key403 Forbidden- Plan not set or insufficient permissions429 Too Many Requests- Rate limit exceeded500 Internal Server Error- Server error (vectorization or database errors)
Next Steps
- Pages & Content API - Index your content
- Authentication - Get your API keys
- Error Handling - Handle errors gracefully