Search¶
Advanced search capabilities including vector similarity, geographic, and full-text search.
Overview¶
ORMDB provides three types of advanced search beyond standard filters:
| Search Type | Index | Use Case |
|---|---|---|
| Vector Search | HNSW | Semantic similarity, embeddings, recommendations |
| Geo Search | R-tree | Location-based queries, proximity search |
| Full-Text Search | Inverted Index | Text content search, document retrieval |
Vector Search¶
Find similar items using HNSW (Hierarchical Navigable Small World) k-nearest neighbor search.
Basic Usage¶
With Distance Threshold¶
Limit results to vectors within a maximum distance:
Using SearchFilter Types¶
Geographic Search¶
Find entities based on geographic location using R-tree spatial indexing.
Radius Search¶
Find entities within a radius from a center point:
Bounding Box Search¶
Find entities within a rectangular region:
Polygon Search¶
Find entities within an arbitrary polygon:
K-Nearest Geographic Search¶
Find the k nearest entities to a point:
Full-Text Search¶
Search text content using BM25 ranking with an inverted index.
Basic Text Search¶
Find documents matching search terms:
With Minimum Score¶
Filter results by relevance score:
Phrase Search¶
Search for exact phrases:
Boolean Search¶
Advanced search with must/should/must_not terms:
Combining Search with Other Filters¶
Search filters can be combined with regular filters using AND:
// Find nearby active restaurants
const results = await client.query("Restaurant", {
filter: {
and: [
{
geo_within_radius: {
field: "location",
center_lat: 37.7749,
center_lon: -122.4194,
radius_km: 5.0,
},
},
{ field: "status", op: "eq", value: "active" },
{ field: "rating", op: "ge", value: 4.0 },
],
},
});
# Find nearby active restaurants
results = client.query("Restaurant",
filter={
"and": [
{
"geo_within_radius": {
"field": "location",
"center_lat": 37.7749,
"center_lon": -122.4194,
"radius_km": 5.0,
}
},
{"field": "status", "op": "eq", "value": "active"},
{"field": "rating", "op": "ge", "value": 4.0},
]
})
ORM Adapter Examples¶
Prisma¶
// Vector search
const similar = await prisma.product.findMany({
where: {
embedding: { vectorSearch: { queryVector: [...], k: 10 } },
},
});
// Geo search
const nearby = await prisma.restaurant.findMany({
where: {
location: { geoRadius: { lat: 37.7749, lon: -122.4194, radiusKm: 5 } },
},
});
// Text search
const articles = await prisma.article.findMany({
where: {
content: { textMatch: { query: "rust programming" } },
},
});
Drizzle¶
import { vectorSearch, geoWithinRadius, textMatch } from "@ormdb/client/drizzle";
// Vector search
const similar = await db
.select()
.from(products)
.where(vectorSearch(products.embedding, queryVector, 10));
// Geo search
const nearby = await db
.select()
.from(restaurants)
.where(geoWithinRadius(restaurants.location, 37.7749, -122.4194, 5.0));
// Text search
const articles = await db
.select()
.from(articles)
.where(textMatch(articles.content, "rust programming"));
SQLAlchemy¶
from ormdb.sqlalchemy import vector_search, geo_within_radius, text_match
# Vector search
stmt = select(Product).where(
vector_search(Product.embedding, query_vector, k=10)
)
# Geo search
stmt = select(Restaurant).where(
geo_within_radius(Restaurant.location, 37.7749, -122.4194, 5.0)
)
# Text search
stmt = select(Article).where(
text_match(Article.content, "rust programming")
)
Django¶
from ormdb.django import register_lookups
register_lookups()
# Vector search
Product.objects.filter(
embedding__vector_search={'query_vector': [...], 'k': 10}
)
# Geo search
Restaurant.objects.filter(
location__geo_radius={'lat': 37.7749, 'lon': -122.4194, 'radius_km': 5}
)
# Text search
Article.objects.filter(content__text_match='rust programming')
Best Practices¶
- Index appropriate fields - Ensure vector, geo, and text fields have the correct index type
- Use distance thresholds - For vector search, set
max_distanceto filter irrelevant results - Limit k appropriately - Start with smaller k values and increase as needed
- Combine with filters - Use standard filters to narrow down search space before expensive operations
- Consider pagination - Use
limitandoffsetfor large result sets
Next Steps¶
- Filtering - Standard filter operators
- Query API - Complete query reference
- Performance - Query optimization tips