For AI agents: this page is also available as Markdown at /docs/vector-search.md. Every docs page is: add .md to its URL. llms.txt lists them all.
Vector search
WarpSearch stores vectors next to your documents and searches them with the same filters, facets and paging as text queries. There is no separate vector store to run or keep in sync.
You bring your own embeddings: WarpSearch does not call an embedding model, at ingest or at query time. Compute vectors with the model you prefer and send them as arrays of numbers.
Approximate search does not use an HNSW graph. It uses an inverted-file (IVF) index over quantized codes, read from memory-mapped storage, and rescores every candidate with the stored vector before returning it. Memory use stays low and filtered searches behave well.
Two pages go deeper: Dimensions and storage trade-offs covers how dimension, encoding and index codec decide size, speed and recall, including Matryoshka truncation, and Multi-vector fields covers documents with several vectors.
#Define a vector field
A vector field needs a dimension and a similarity metric. You define it in the collection's schema, when you create the collection or later with PUT /v1/collections/{collection}/schema and the same fields object.
curl -X PUT https://api.warpsearch.io/v1/collections/books \
-H "Authorization: Bearer $WARPSEARCH_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"schema": {
"fields": {
"embedding_v": { "type": "vector", "dims": 768, "metric": "cosine" },
"passages_vs": { "type": "vector", "dims": 768, "metric": "cosine", "multi": true }
}
}
}'
Only the dimension and similarity are expressed. rank_vectors holds several vectors per document:
curl -X PUT https://api.warpsearch.io/compat/es/books \
-H "Authorization: Bearer $WARPSEARCH_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"mappings": {
"properties": {
"embedding_v": { "type": "dense_vector", "dims": 768, "similarity": "cosine" },
"passages_vs": { "type": "rank_vectors", "dims": 768 }
}
}
}'
Only the dimension and space type are expressed:
curl -X PUT https://api.warpsearch.io/compat/opensearch/books \
-H "Authorization: Bearer $WARPSEARCH_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"mappings": {
"properties": {
"embedding_v": { "type": "knn_vector", "dimension": 768,
"method": { "name": "hnsw", "space_type": "cosinesimil" } }
}
}
}'
| Property | Meaning |
|---|---|
type | vector. A field named with the _v suffix is also a vector, but it is storage only until you give it a metric. |
dims | Number of components. Fixes the dimension for every written and queried vector. If you leave it out, the first vector in each segment sets it, so set it explicitly. |
metric | l2, ip (inner product), cosine, hamming (bit vectors, see Smaller encodings) or none (stored, not searchable). |
normalize_on_write | Cosine fields only. On by default: vectors are stored at unit length. Set false to keep the raw vector, in which case candidates are normalized at query time. |
multi | true (or the _vs suffix) lets one document hold several vectors. See Multi-vector fields. |
truncate_dims | Keep only the first N components of each vector, for Matryoshka models. See Fewer dimensions. |
encoding | How the vector column is stored: f32 (default), f16, bf16, int8 or bit. Applies to segments written afterwards. See Smaller encodings. |
keep_original | Also keep the submitted float32 vectors in a separate cold column that searches never read, so the field can be re-encoded later. |
ann | Approximate index settings, see Exact and approximate search. |
The Elasticsearch (dense_vector, rank_vectors) and OpenSearch (knn_vector) mappings cover the dimension and metric only; set the other options in the WarpSearch schema.
Once a field exists, its dims, metric and truncate_dims cannot change (the schema API answers 409 incompatible_schema). encoding and ann settings can change, and apply to segments written afterwards. To use a different dimension or metric, add a new field and reindex.
See Schemas and field types for the rest of the schema.
#Write vectors
A vector is a plain array of numbers. A multi-valued field takes an array of arrays. Send documents to POST /v1/collections/{collection}/documents (or any compatible write API):
{
"id": "b1",
"title_t": "Dune",
"kind_s": "fiction",
"embedding_v": [0.8, 0.1, 0.1],
"passages_vs": [[0.7, 0.2, 0.1], [0.1, 0.8, 0.1]]
}
Integers are fine. Every element must be a finite number that fits in a float32. A NaN, an infinity or a value out of range fails that document. A vector of the wrong length fails too. Cosine vectors with a zero norm have no direction and are skipped. Vector fields are not returned in search results unless you name them in fields. See Ingesting documents.
#Run a kNN query
Send a kNN query to POST /v1/collections/{collection}/search. The search request has no separate vector key: set language: "es" and put a knn section in query. Non-scoring filters go in filters, an array; with language: "es" each entry is an Elasticsearch query object, and they apply inside the vector search. You can also write the search in PostgreSQL syntax with pgvector distance operators (language: "pgsql", see SQL and PostgreSQL).
curl -s https://api.warpsearch.io/v1/collections/books/search \
-H "Authorization: Bearer $WARPSEARCH_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"language": "es",
"query": {
"knn": {
"field": "embedding_v",
"query_vector": [0.75, 0.15, 0.10],
"k": 20,
"num_candidates": 200
}
},
"filters": [{ "term": { "kind_s": "fiction" } }],
"limit": 10,
"fields": ["id", "title_t"]
}'
The same endpoint with language: "pgsql". <=> is cosine distance, <-> L2 and <#> negative inner product; the operator must match the field's metric. LIMIT sets k, and the WHERE conditions filter inside the vector search.
{
"language": "pgsql",
"query": "SELECT id, title_t FROM books WHERE kind_s = 'fiction' ORDER BY embedding_v <=> '[0.75, 0.15, 0.10]' LIMIT 10"
}
curl -s https://api.warpsearch.io/compat/es/books/_search \
-H "Authorization: Bearer $WARPSEARCH_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"knn": {
"field": "embedding_v",
"query_vector": [0.75, 0.15, 0.10],
"k": 20,
"num_candidates": 200,
"filter": { "term": { "kind_s": "fiction" } }
},
"size": 10,
"_source": ["title_t"]
}'
curl -s https://api.warpsearch.io/compat/opensearch/books/_search \
-H "Authorization: Bearer $WARPSEARCH_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"query": {
"knn": {
"embedding_v": {
"vector": [0.75, 0.15, 0.10],
"k": 20,
"filter": { "term": { "kind_s": "fiction" } }
}
}
},
"size": 10,
"_source": ["title_t"]
}'
fq filters apply before the neighbors are chosen:
curl -s -G https://api.warpsearch.io/compat/solr/books/select \
-H "Authorization: Bearer $WARPSEARCH_API_KEY" \
--data-urlencode 'q={!knn f=embedding_v topK=20}[0.75, 0.15, 0.10]' \
--data-urlencode 'fq=kind_s:fiction' \
--data-urlencode 'rows=10' \
--data-urlencode 'fl=id,title_t'
"ANN" is approximate and "kNN" exact. $dist in the response is a distance, so lower is closer:
curl -s https://api.warpsearch.io/compat/turbopuffer/v2/namespaces/books/query \
-H "Authorization: Bearer $WARPSEARCH_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"rank_by": ["embedding_v", "ANN", [0.75, 0.15, 0.10]],
"filters": ["kind_s", "Eq", "fiction"],
"top_k": 10,
"include_attributes": ["title_t"]
}'
k is how many nearest documents the query produces. limit (size in Elasticsearch, rows in Solr) is how many the response returns. A collection is searchable as soon as its vectors are indexed, and until you build approximate indexes every search is exact.
The parameters of the knn section (the same in the WarpSearch and Elasticsearch forms):
| Parameter | Meaning |
|---|---|
field | The vector field. Required. |
query_vector | The query vector, with the field's dimension. Required. |
k | Neighbors to produce. Required, positive. |
exact | true forces a full-precision scan and returns the true top k. Ignores the tuning knobs below. |
similarity | Minimum similarity of a hit. See Similarity thresholds. |
num_candidates | How many candidates are collected before the full-precision rescore. Unset, it is sized from k. It must be at least k. |
ivf.nprobe | How many index lists to scan. 0 or absent means adaptive. |
ivf.min_scan_fraction | A floor on the fraction of vectors scanned, from 0 to 1. 0.001 is 0.1%. |
filter | Query objects applied inside the vector search. On /v1, the request's filters do the same. |
#How scores work
| Metric | Score | Higher means |
|---|---|---|
cosine | Cosine similarity, in the range -1 to 1 | More similar |
ip | The dot product | More similar |
l2 | 1 / (1 + squared distance), in the range 0 to 1 | Closer |
hamming | 1 - differing bits / dims, in the range 0 to 1 | More bits in common |
The scale depends on your embedding model and corpus, so calibrate any cut-off on your own data. The Elasticsearch- and OpenSearch-compatible APIs return these scores as they are, not rescaled to the (1 + cosine) / 2 form Elasticsearch uses, so compare scores across engines with care. The turbopuffer-compatible API reports a distance in $dist instead (cosine_distance is 1 minus the cosine similarity).
#Filter inside the search
Filters apply while neighbors are collected, not after. k: 20 with a filter means twenty filtered neighbors, not twenty minus whatever a later filter removed. If a filter or a multi-vector collapse leaves too few results, an approximate search automatically goes deeper.
Vector queries also compose under boolean clauses and facet buckets, so you can facet over the neighbors a query found. There is no automatic switch to exact search when a very selective filter starves an approximate search. Use exact: true when you need the exact filtered top k.
#Exact and approximate search
Exact search scans the full-precision vector column once per query. It is perfectly accurate and fast for small collections, and it needs no setup.
Approximate search builds an IVF index per segment of your data (a segment is a batch of documents that is indexed together). K-means centroids route a query to a few inverted lists, and each list holds one compact code per vector. Index data stays on memory-mapped storage and is paged in by the operating system, so the index does not need to fit in RAM. Finally, candidates are rescored from the stored full-precision vectors, so returned scores are exact even when candidate selection was approximate.
#Codecs
PQ (product quantization) is the default. RaBitQ is available as an opt-in and needs an explicit "codec": "rabitq".
Set the codec in the field's schema definition:
{
"fields": {
"embedding_v": {
"type": "vector",
"dims": 768,
"metric": "cosine",
"ann": { "codec": "rabitq", "rabitq": { "bits": 1, "query_bits": 4 } }
}
}
}
| Setting | Default | Meaning |
|---|---|---|
codec | pq | pq or rabitq. Omitting it selects PQ, even if you pass rabitq settings. |
nlist | Square root of the vectors in the segment, capped at 4096 | Number of IVF lists. 0 means automatic. |
pq.m | Automatic | Sub-quantizers. Must divide the stored dimension. Automatic picks the largest divisor that leaves at least 4 dimensions each, under a cap. |
pq.bits | 8 | Bits per PQ code, 1 to 8. |
rabitq.bits | 1 | Bits per dimension, 1 to 9. |
rabitq.query_bits | 4 | Bits the query is quantized to while scanning, 0 to 8. 0 scans with the float query. |
A few rules: an ann object replaces the parent's definition instead of merging with it. Changing ann applies to segments built afterwards, not to existing indexes, and a query serves each segment with its own index, so different settings mix freely.
PQ scans faster. RaBitQ offers a different size and recall trade-off. With 1-bit RaBitQ, recall is usually limited by how many lists you probe, so raise ivf.nprobe before raising bits. Code sizes per vector are in What a vector costs.
#When indexes get built
Approximate indexes are built only for fields marked for them, and only by an explicit refresh. Background commits and commit=true on an ingest request do not build them.
- Mark the field. Give it an
annobject in the WarpSearch schema, for example"ann": {"codec": "pq"}(see Codecs). Through the compatible APIs, adense_vectormapped with anindex_optionstype other thanflat, or an OpenSearchknn_vectorwith anivforhnswmethod, marks it too, and turbopuffer vector attributes are marked automatically. - Refresh.
POST /v1/collections/{collection}/refreshcommits pending writes and builds the missing indexes. On the compatible APIs,_refreshdoes the same, and turbopuffer writes build them as part of the write.
After a bulk load made of many small batches, the Elasticsearch-compatible _forcemerge merges them first and then builds. If a build fails, the refresh still commits and answers with a warning, and searches use exact scans. Build parameters such as m or ef_construction in a compatible mapping are not mapped, and a warning says they are ignored.
An index is built per segment, and only when the segment is big enough: about 10,000 vectors for PQ and 8,192 for RaBitQ. Smaller segments stay on exact scan, which is faster than an index at that size. A single query routinely uses indexes for large segments and exact scan for small ones, with the same result contract. Once a segment has an index, later commits carry it forward, and merged segments get fresh indexes when they pass the same thresholds.
#Tune recall and latency
Recall is how many of the true nearest neighbors an approximate search returns. Measure it by running the same query twice, once with "exact": true, and comparing the lists. Everything else about the query is identical, so the exact run is your ground truth.
Recipes, in the order to try them:
- Raise
ivf.nprobe. It scans more lists. Recall and latency both rise. This is the main knob. - Raise
num_candidates. It rescores more candidates at full precision. This helps most when the codes are coarse (smallpq.m, 1-bit RaBitQ) andkis small. - Use more PQ code bytes. A larger
pq.mimproves recall at the cost of scan time and storage. - Try RaBitQ. It stores about as many bytes as PQ at 768 dims with different recall behavior.
- Need a guarantee? Use
exact: true, orivf.min_scan_fraction: 1to probe every list.
The numbers below come from a benchmark on 485,659 Cohere-768 cosine embeddings of Simple English Wikipedia, recall@10 averaged over 200 held-out queries. They used an earlier default probe policy and serial single-query latency on one workstation. Treat them as an illustration of the trade-offs, not as a promise for your data, because recall depends heavily on your embedding model and corpus.
| Codec | nprobe default | 32 | 64 | 128 | Latency at default nprobe |
|---|---|---|---|---|---|
| RaBitQ, 1 to 4 bits | 0.893 | 0.911 | 0.960 | 0.986 | 1.2 ms |
| PQ, 96 bytes per vector | 0.886 | 0.902 | 0.950 | 0.970 | 0.66 ms |
Since that benchmark, the default probe effort has been scaled up with dimension, which lifted recall@10 on 768 to 960 dimension corpora from roughly 0.82 to 0.87 to about 0.95 in RaBitQ measurements. Run your own recall check before you rely on a setting.
#Nearest groups
When each entity (a product, an article) has several vector-bearing documents, collapse on the entity key so repeated near neighbors from one product do not crowd out other products. Add collapse beside the knn section, inside query:
{
"language": "es",
"query": {
"knn": { "field": "embedding_v", "query_vector": [0.75, 0.15, 0.10], "k": 20 },
"collapse": { "field": "product_id_s" }
},
"limit": 10
}
{
"knn": { "field": "embedding_v", "query_vector": [0.75, 0.15, 0.10], "k": 20 },
"collapse": { "field": "product_id_s" },
"size": 10
}
A group's score is its best member's score. Here k counts documents, so a few large groups can leave fewer than k groups; raise k to compensate. A mode where k counts groups exists in the engine but is not yet exposed by the API.
#Similarity thresholds
similarity drops neighbors that are not similar enough. Its value is in the metric's own space, the same way Elasticsearch's knn.similarity works:
| Metric | similarity means | Hit kept when |
|---|---|---|
l2 | Maximum L2 distance (not squared), at least 0 | distance <= similarity |
ip | Minimum dot product | dot >= similarity |
cosine | Minimum cosine similarity | cosine >= similarity |
{
"language": "es",
"query": { "knn": { "field": "embedding_v", "query_vector": [0.75, 0.15, 0.10], "k": 20, "similarity": 0.8 } }
}
With language: "pgsql", a distance bound beside the ordering sets the same threshold: WHERE embedding_v <=> '[0.75, 0.15, 0.10]' < 0.2 ORDER BY embedding_v <=> '[0.75, 0.15, 0.10]' keeps cosine similarities of at least 0.8.
The threshold trims the k nearest documents after rescoring. It does not search further, so you can get fewer than k hits. Trimmed documents are removed from totals, facets and metrics too. To set a cut-off on a combined text and vector score, see the minimum-score options in Searching.
Not supported: radius search without a
k(returning every vector within a distance), and OpenSearchneuralqueries that embed query text for you.
#Parameters in other query languages
The Elasticsearch top-level knn section and knn query, the OpenSearch knn query, the Solr {!knn f=field topK=n} parser and turbopuffer rank_by with "ANN" or "kNN" (exact) all run the same search. Their parameters map onto the WarpSearch knn parameters:
| Client parameter | WarpSearch equivalent |
|---|---|
num_candidates, OpenSearch method_parameters.ef_search | num_candidates. It sizes the rescoring pool but cannot add candidates beyond the lists probed, unlike HNSW. |
rescore_vector.oversample, OpenSearch rescore.oversample_factor | num_candidates of ceil(k x factor) |
OpenSearch method_parameters.nprobes | ivf.nprobe |
similarity | similarity, in the metric's own space |
filter, Solr fq, turbopuffer filters | Applied inside the search |
boost | Boosts the kNN clause in a hybrid query |
The extensions "ivf": {"nprobe": 32} and "exact": true also work inside the Elasticsearch and OpenSearch forms. Query vectors are limited to 8,192 dimensions on every API. For combining kNN with text, see Hybrid search.
#What's coming
Coming soon: faster exact scan kernels that use SIMD instructions, and sparse vectors for learned sparse retrieval such as SPLADE. See Feature status.