TOOL WIKI · VECTOR & SEARCH
FAISS
Builds indexes for similarity search and clustering of dense vectors.
Jump to a section 10 sections
EXAMPLE USE CASE
Own a small in-process nearest-neighbor index
A policy assistant needs relevant records with source ownership; vector similarity alone does not establish who may read them.
- Input
- Two normalized float32 vectors in one already-authorized partition.
- Expected output
- Index position 0 mapped back to the returns-policy record.
- Success check: The nearest row is index position 0, the returns policy.
- Try a failure: Reorder vectors without updating metadata to see why index positions are not durable document IDs.
Example scope: Actual FAISS index operation. Authentication, metadata joins and durable ID mapping belong to the application.
Preserve source identifiers, version, tenant, and deletion status.
Use the same embedding model and dimensions for indexed records and queries.
indexTo 03 · FAISSOwning the vector index within a custom application or research pipeline. The application supplies metadata storage, authorization, and service operations.
matchesTo 05 · Filter + rankResolve allowed tenants and filters before searching for evidence.
embed queryBack to 02 · Embedding processscopeBack to 03 · FAISSApply 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
Owning the vector index within a custom application or research pipeline. The application supplies metadata storage, authorization, and service operations.
When to consider it
- Owning the vector index within a custom application or research pipeline.
A design decision to make
- The application supplies metadata storage, authorization, and service operations.
Prerequisites and setup
- Python 3.11+ and a fresh scratch directory. Toy vectors avoid embedding-provider calls.
python3 -m venv .venv
source .venv/bin/activate
pip install faiss-cpu numpyTry a small integration
search.py
import faiss
import numpy as np
# One authorized partition; FAISS itself does not authenticate users.
metadata = {0:{"tenant":"a","text":"Returns: 30 days"}, 1:{"tenant":"a","text":"Shipping: 5 days"}}
vectors = np.array([[1.,0.,0.],[0.,1.,0.]], dtype="float32")
faiss.normalize_L2(vectors)
index = faiss.IndexFlatIP(3)
index.add(vectors)
scores, ids = index.search(np.array([[1.,0.,0.]], dtype="float32"), 1)
assert int(ids[0][0]) == 0
print(metadata[int(ids[0][0])], float(scores[0][0]))Run and check the result
python search.py- The nearest row is index position 0, the returns policy.
- Normalized inner product gives cosine similarity here. An index position needs a durable mapping to a source record.
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.
- FAISS is an index library. Provide persistence, metadata joins, access control, concurrency and lifecycle management in the application.
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.