Vector Search
Vector search enables semantic search across your data sources using Cloudflare Vectorize.
Overview
Features:
- Semantic similarity matching
- Fast nearest-neighbor search
- Automatic embedding generation
- Cross-source search
How It Works
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ Query │────▶│ Generate │────▶│ Search │
│ Input │ │ Embedding │ │ Vectorize │
└──────────────┘ └──────────────┘ └──────┬───────┘
│
▼
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ Return │◀────│ Retrieve │◀────│ Find Top │
│ Results │ │ Content │ │ Matches │
└──────────────┘ └──────────────┘ └──────────────┘Searching
Via Dashboard
- Navigate to Context
- Enter search query
- View ranked results
Via API
bash
curl "https://your-domain.com/api/agents/{id}/sources/search?query=how+to+reset+password"Response:
json
{
"results": [
{
"id": "chunk-123",
"source_id": "source-456",
"content": "To reset your password, go to Settings...",
"score": 0.92,
"metadata": {
"source_name": "User Guide",
"page": 15
}
},
{
"id": "chunk-124",
"content": "Password reset emails are sent within 5 minutes...",
"score": 0.85
}
]
}Search Parameters
Basic Search
json
{
"query": "how to integrate API",
"limit": 10
}Filtered Search
json
{
"query": "installation guide",
"filter": {
"source_id": "source-123",
"metadata.category": "technical"
},
"limit": 5
}Threshold Search
json
{
"query": "error handling",
"min_score": 0.7,
"limit": 20
}Embeddings
Model
Using Cloudflare Workers AI:
- Model:
@cf/baai/bge-base-en-v1.5 - Dimensions: 768
- Metric: Cosine similarity
Generation
Embeddings are generated automatically:
typescript
const embedding = await env.AI.run(
'@cf/baai/bge-base-en-v1.5',
{ text: content }
)Vectorize Configuration
Index Settings
toml
[[vectorize]]
binding = "VECTORIZE"
index_name = "agents-dashboard-embeddings"Index properties:
- Dimensions: 768
- Metric: cosine
- Max vectors: Based on plan
Search Strategies
Semantic Search
Natural language queries:
"How do I cancel my subscription?"
"What are the payment options?"Keyword + Semantic
Combine exact and semantic:
json
{
"query": "refund policy",
"keywords": ["cancel", "money back"],
"boost_keywords": 0.3
}Multi-Query
Search with variations:
json
{
"queries": [
"password reset",
"forgot password",
"change password"
],
"merge": "union"
}Integration
With Chat
Automatic RAG in conversations:
typescript
// Agent automatically searches relevant context
const context = await searchSources(query)
const response = await generateWithContext(query, context)With Workflows
json
{
"type": "search-sources",
"data": {
"query": "{{input.question}}",
"limit": 3
},
"output": "search_results"
}With Tools
Enable as an agent tool:
json
{
"name": "search_knowledge",
"description": "Search the knowledge base",
"parameters": {
"query": {
"type": "string",
"description": "Search query"
}
}
}Performance
Optimization Tips
- Limit results: Request only needed results
- Use filters: Narrow search scope
- Cache common queries: Store frequent searches
- Batch queries: Combine related searches
Metrics
Monitor search performance:
- Query latency
- Result relevance
- Cache hit rate
Best Practices
1. Quality Content
Better content = better results:
- Clear, well-written text
- Proper structure
- Consistent terminology
2. Appropriate Chunk Size
Balance context and precision:
json
{
"chunking": {
"max_size": 500,
"overlap": 50
}
}3. Metadata Filtering
Use metadata for precision:
json
{
"filter": {
"metadata.product": "pro",
"metadata.version": "2.0"
}
}4. Score Thresholds
Filter low-quality matches:
json
{
"min_score": 0.75
}5. Regular Updates
Keep embeddings current:
- Refresh on content changes
- Re-index periodically
Troubleshooting
Poor Results
- Check source content quality
- Verify chunking settings
- Adjust score thresholds
- Review search queries
Slow Searches
- Reduce result limit
- Add filters
- Check index health
- Consider caching
Missing Content
- Verify source is indexed
- Check processing status
- Ensure content is chunked
- Validate embeddings exist
API Reference
See Sources API for complete endpoint documentation.