TL;DR
Typesense is an open-source search engine designed for speed — written in C++, it delivers sub-millisecond search results with typo tolerance, faceting, and geo-search out of the box.
What Is Typesense?
Typesense is developer-friendly search:
- Blazing fast — single-digit millisecond searches
- C++ engine — optimized from the ground up for search
- Typo tolerance — finds results despite spelling errors
- Geo-search — location-based filtering and sorting
- Vector search — built-in semantic/hybrid search
- Curation — pin/hide specific results
- Free — GPL-3, or Typesense Cloud
Quick Start
# Docker
docker run -p 8108:8108 \
-v /tmp/typesense-data:/data \
typesense/typesense:latest \
--data-dir /data \
--api-key=YOUR_API_KEY
Create Collection and Index
import Typesense from "typesense";
const client = new Typesense.Client({
nodes: [{ host: "localhost", port: 8108, protocol: "http" }],
apiKey: "YOUR_API_KEY",
});
// Create collection (schema)
await client.collections().create({
name: "products",
fields: [
{ name: "name", type: "string" },
{ name: "description", type: "string" },
{ name: "price", type: "float" },
{ name: "category", type: "string", facet: true },
{ name: "rating", type: "float" },
{ name: "in_stock", type: "bool", facet: true },
{ name: "location", type: "geopoint" },
],
default_sorting_field: "rating",
});
// Index documents
await client.collections("products").documents().import([
{
name: "MacBook Pro 16",
description: "Powerful laptop for professionals",
price: 2499,
category: "Laptops",
rating: 4.8,
in_stock: true,
location: [37.7749, -122.4194],
},
{
name: "iPhone 15 Pro",
description: "Premium smartphone with titanium design",
price: 1199,
category: "Phones",
rating: 4.7,
in_stock: true,
location: [37.7749, -122.4194],
},
]);
Search
// Basic search (typo-tolerant)
const results = await client
.collections("products")
.documents()
.search({
q: "macbok", // typo — still finds MacBook!
query_by: "name,description",
});
// Search with filters and facets
const filtered = await client
.collections("products")
.documents()
.search({
q: "laptop",
query_by: "name,description",
filter_by: "price:<2000 && in_stock:true",
sort_by: "rating:desc",
facet_by: "category",
per_page: 10,
});
// Geo search — find products near a location
const nearby = await client
.collections("products")
.documents()
.search({
q: "*",
query_by: "name",
filter_by: "location:(37.78, -122.41, 10 km)",
sort_by: "location(37.78, -122.41):asc",
});
Vector/Semantic Search
// Create collection with vector field
await client.collections().create({
name: "docs",
fields: [
{ name: "title", type: "string" },
{ name: "content", type: "string" },
{
name: "embedding",
type: "float[]",
embed: {
from: ["title", "content"],
model_config: {
model_name: "ts/all-MiniLM-L12-v2",
},
},
},
],
});
// Hybrid search (keyword + semantic)
const results = await client
.collections("docs")
.documents()
.search({
q: "how to deploy to production",
query_by: "title,content,embedding",
});
Typesense vs Alternatives
| Feature | Typesense | Meilisearch | Algolia | Elasticsearch |
|---|---|---|---|---|
| Language | C++ | Rust | N/A | Java |
| Latency | <5ms | <50ms | <50ms | 100-500ms |
| Typo tolerance | Yes | Yes | Yes | Plugin |
| Vector search | Built-in | Planned | Yes | Yes |
| Geo-search | Yes | Yes | Yes | Yes |
| Curation | Yes | No | Yes | No |
| Free tier | Self-host | Self-host | 10K searches | Self-host |
Resources
Need to search scraped web data? My Apify tools extract data from any website — index it in Typesense for blazing-fast search. Questions? Email spinov001@gmail.com
Top comments (0)