TOOL WIKI · VECTOR & SEARCH
Typesense
Supports application search including keyword and vector-based retrieval.
Jump to a section 10 sections
EXAMPLE USE CASE
Add filtered vector retrieval to product search
A policy assistant needs relevant records with source ownership; vector similarity alone does not establish who may read them.
- Input
- A collection schema, policy vector and tenant filter_by expression.
- Expected output
- The returns policy hit with embeddings excluded from the response.
- Success check: The nearest authorized record is the returns policy; the unrelated tenant never appears.
- Try a failure: Check filtered result IDs and an empty authorized partition before showing source text.
Example scope: Actual Typesense service integration; this query tests vector recall rather than a complete hybrid-ranking evaluation.
Official reference · Typesense
Preserve source identifiers, version, tenant, and deletion status.
Use the same embedding model and dimensions for indexed records and queries.
indexTo 03 · TypesenseProduct-facing search that needs multiple relevance signals. Use a representative query set to tune ranking and evaluate filtering.
matchesTo 05 · Filter + rankResolve allowed tenants and filters before searching for evidence.
embed queryBack to 02 · Embedding processApply resource permissions and select the evidence that supports this task.
evidenceTo 06 · Agent contextReturn source text and identifiers, not a vector distance presented as factual certainty.
Result or stopping point
Product-facing search that needs multiple relevance signals. Use a representative query set to tune ranking and evaluate filtering.
When to consider it
- Product-facing search that needs multiple relevance signals.
A design decision to make
- Use a representative query set to tune ranking and evaluate filtering.
Prerequisites and setup
- A TLS-enabled Typesense endpoint and a key limited to a scratch collection.
- Use a search-only scoped key in browser-facing applications; this ingest example needs a server-side write key.
python3 -m venv .venv
source .venv/bin/activate
pip install typesense
export TYPESENSE_HOST="YOUR_HOST_WITHOUT_SCHEME"
export TYPESENSE_API_KEY="YOUR_SCOPED_KEY"Try a small integration
search.py
import os
import typesense
from typesense.exceptions import ObjectAlreadyExists
client = typesense.Client({"nodes":[{"host":os.environ["TYPESENSE_HOST"],"port":443,"protocol":"https"}],
"api_key":os.environ["TYPESENSE_API_KEY"],"connection_timeout_seconds":5})
try:
client.collections.create({"name":"asg-policies","fields":[
{"name":"tenant","type":"string","facet":True},{"name":"text","type":"string"},
{"name":"embedding","type":"float[]","num_dim":3}]})
except ObjectAlreadyExists:
pass
collection = client.collections["asg-policies"]
collection.documents.upsert({"id":"returns-a","tenant":"a","text":"Returns: 30 days","embedding":[1.,0.,0.]})
collection.documents.upsert({"id":"returns-b","tenant":"b","text":"Private policy","embedding":[1.,0.,0.]})
result = collection.documents.search({"q":"*","vector_query":"embedding:([1,0,0], k:5)",
"filter_by":"tenant:=a","per_page":1,"exclude_fields":"embedding"})
assert result["hits"][0]["document"]["tenant"] == "a"
print(result["hits"])Run and check the result
python search.py- The nearest authorized record is the returns policy; the unrelated tenant never appears.
- Change the query vector or tenant filter and inspect the returned IDs, metadata and score ordering.
Common failures
- Dimension mismatch: align the stored vectors and queries with the same embedding model.
- An empty result may be a correct filter outcome; do not retry without the tenant constraint.
Production decisions
- Use embeddings from one named model/version with a fixed dimension and distance metric. The three-value vectors here demonstrate mechanics, not semantic quality.
- Enforce authenticated tenant/resource filters outside model control. Test filtered recall, deletion, backups, index rebuilds and p95 latency on realistic data.
Keep exploring
Explore the same layer
Compare candidates on your own workload. This entry describes a product’s role; it is not a claim that products in the category are interchangeable.