Vector examples
Start by writing an embedding, then choose the distance metric recommended by the model that produced it. The maintenance recipes cover index coverage, repair and compression.
- Store sample-1Write the complete three-value vector into learning.sample.
- Search with the same valuesKeep dimension and metric identical to the write.
- Check the returned IDLook for sample-1 before moving to model-generated embeddings.
Try a complete small example
This uses three made-up numbers to check the write-and-search flow. It does not demonstrate the meaning of text. Use the tenant-scoped connection from the connection notes, and keep learning.sample separate from collections using a different dimension or metric.
First save one vector:
curl --fail-with-body -X POST "https://$OC_HOST/v1/tenants/$OC_TENANT/vector/learning.sample/put" \
-H "Authorization: Bearer $OC_TOKEN" -H "Content-Type: application/json" \
-d '{"id":"sample-1","embedding":[1.0,0.0,0.0],"dim":3,"metric":"cosine"}'Then search with the same three values:
curl --fail-with-body -X POST "https://$OC_HOST/v1/tenants/$OC_TENANT/vector/learning.sample/topk" \
-H "Authorization: Bearer $OC_TOKEN" -H "Content-Type: application/json" \
-d '{"query":[1.0,0.0,0.0],"k":1,"dim":3,"metric":"cosine"}'Look for sample-1 in the result. k: 1 asks for at most one match. The dimension and metric agree in both requests. Next, use a real embedding from your chosen model; the model supplies the numbers, while the database stores and compares them.
Search by similarity
- Store one embedding — An embedding is a list of numbers that represents an item for similarity search.
- Attach filters to an embedding — Store small metadata fields beside an embedding so a search can be restricted to matching items.
- Find similar vector directions — Cosine similarity compares vector direction rather than magnitude.
- Find the nearest points — L2 is Euclidean distance: the straight-line distance between vectors.
- Search by dot product — Dot product compares both direction and magnitude.
- Compare speed and retrieval quality — Fast mode searches a narrower part of the index.
- Search within matching metadata — Combine similarity with exact metadata filters.
- Remove vectors from an index — Delete embeddings that are no longer needed.
- Group vectors for IVF search — IVF divides vectors into groups around representative points called centroids.
- Check IVF coverage and balance — Inspect whether stored vectors are covered by the index and whether one partition contains too many entries.
- Check and repair the search graph — HNSW links nearby vectors in a graph.
- Build a compressed vector index — IVF-PQ represents vector groups with compact codes.
- Combine dense and sparse matches — Dense embeddings capture similarity.
Before adapting a recipe
Use a test database, load the named sample data, and check the expected result. Read each page’s limits before changing the query. See connection and SDK notes.