TOOL WIKI · VECTOR & SEARCH
Elasticsearch
Combines document search with vector retrieval and filtering capabilities.
Jump to a section 10 sections
EXAMPLE USE CASE
Add vector recall to an existing search index
A policy assistant needs relevant records with source ownership; vector similarity alone does not establish who may read them.
- Input
- A dense_vector field, policy document and tenant predicate.
- Expected output
- The indexed policy among filtered nearest-neighbor hits.
- Success check: The nearest authorized record is the returns policy; the unrelated tenant never appears.
- Try a failure: An accepted write may need refresh visibility before search; test each state separately.
Example scope: Actual Elasticsearch API integration; match client/server majors and supply a scratch index.
Official reference · Elasticsearch
Preserve source identifiers, version, tenant, and deletion status.
Use the same embedding model and dimensions for indexed records and queries.
An application that needs lexical and semantic search over a shared corpus. Evaluate relevance tuning and index refresh behavior for your data.
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
An application that needs lexical and semantic search over a shared corpus. Evaluate relevance tuning and index refresh behavior for your data.
When to consider it
- An application that needs lexical and semantic search over a shared corpus.
A design decision to make
- Evaluate relevance tuning and index refresh behavior for your data.
Prerequisites and setup
- An existing Elasticsearch deployment and an API key limited to a dedicated scratch index. Match the Python client major version to the service.
python3 -m venv .venv
source .venv/bin/activate
pip install elasticsearch
export ELASTIC_URL="https://YOUR_ELASTIC_ENDPOINT"
export ELASTIC_API_KEY="YOUR_SCOPED_KEY"Try a small integration
search.py
import os
from elasticsearch import Elasticsearch
client = Elasticsearch(os.environ["ELASTIC_URL"], api_key=os.environ["ELASTIC_API_KEY"])
name = "asg-policies"
if not client.indices.exists(index=name):
client.indices.create(index=name, mappings={"properties":{
"tenant":{"type":"keyword"}, "text":{"type":"text"},
"embedding":{"type":"dense_vector","dims":3,"index":True,"similarity":"cosine"}}})
client.index(index=name,id="returns-a",document={"tenant":"a","text":"Returns: 30 days","embedding":[1.,0.,0.]},refresh="wait_for")
client.index(index=name,id="returns-b",document={"tenant":"b","text":"Private policy","embedding":[1.,0.,0.]},refresh="wait_for")
result = client.search(index=name, knn={"field":"embedding","query_vector":[1.,0.,0.],
"k":1,"num_candidates":10,"filter":{"term":{"tenant":"a"}}}, source=["tenant","text"])
assert result["hits"]["hits"][0]["_source"]["tenant"] == "a"
print(result["hits"]["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
- TLS errors require the correct CA trust configuration, not verify_certs=False.
- Refresh visibility, indexing success and search relevance need separate checks.
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.