- Store and retrieve vectors using
PointStruct,points.upsert, andpoints.search. - Control search behaviour with distance metrics, score thresholds,
SearchParams, and pagination. - Fetch and count points using
points.getandvde.get_vector_count.
- Embed — Convert text, images, or audio into dense numerical vectors using a model.
- Store — Insert vectors with metadata into a collection.
- Search — Encode a query into the same vector space and find the nearest neighbors.
- Score — Rank results by distance (cosine, dot product, or Euclidean).
Environment setup
Run this command to install the two packages the tutorial depends on.Step 1: Import and configure
Run this cell to import the SDK classes, set the server address and collection name, and load the embedding model. The two helper functions at the bottom are used throughout the tutorial to convert text into vectors.Expected output
The cell prints the configured server address and confirms the embedding model loaded successfully with its dimensionality.Step 2: Create a collection
Run this cell to create the collection that all subsequent steps will use. If the collection already exists,get_or_create returns without error.
Key parameters
The following parameters are passed tocollections.get_or_create() to define the collection structure.
Distance metrics
Actian VectorAI DB supports four distance metrics. The choice is made at collection creation time and cannot be changed afterwards.
Most text embedding models produce normalized vectors, making cosine the standard choice. The other metrics are useful in specialized scenarios covered later in this tutorial.
Expected output
A single confirmation line prints once the collection is created (or already exists).Step 3: Embed and store vectors
Run this cell to embed all ten sample documents and store them as points in the collection. Each point has an integer ID, a 384-dimensional vector, and a payload containing the original text plus topic and difficulty metadata.How it works
The ingestion pipeline converts raw text into vectors and stores them with metadata in a single batch operation.embed_texts()converts each document’s text into a 384-dimensional float vector usingall-MiniLM-L6-v2.PointStruct(id, vector, payload)packages the ID, vector, and metadata together.points.upsert()inserts (or updates) the points in the collection.vde.flush()persists vectors to disk immediately.
Expected output
The count confirms all ten documents were stored successfully.Step 4: Run a basic similarity search
Run this cell to search the collection using a natural-language query. The function embeds the query string and returns the five most similar documents, each with its ID, cosine score, topic, and a text preview.How it works
The search follows a three-step flow: encode, retrieve, rank.- The query text is embedded into the same 384-dim vector space as the stored documents.
points.search()finds the nearest vectors by cosine similarity.- Results are returned as scored point objects, ranked by score (highest first for cosine).
Key parameters
The following parameters are accepted bypoints.search().
Expected output
The five closest documents are printed in score order. The top result is about neural networks, followed by transformers and machine learning — demonstrating that the search captured semantic relationships rather than exact keyword overlap.Limit is a maximum, not a guarantee. The number of results returned depends on how many points score above the internal threshold. Scores also reflect the specific model and dataset — do not compare absolute score values across different collections or embedding models.Step 5: Understanding scores
The score value returned by each search result depends on the distance metric configured on the collection.Cosine similarity
For cosine distance — the metric used in this tutorial — scores represent the cosine similarity between normalized vectors. When both the stored vectors and query vectors are unit-normalized (as produced byall-MiniLM-L6-v2), scores range from 0 to 1 and are interpreted as follows.
Comparing queries
Run this cell to issue three different queries against the collection and compare their score distributions. Each query will return three results with scores that reflect how closely the corpus matches that particular topic.Expected output
Each query surfaces a different set of top results. The scores shift noticeably between topics, confirming that semantic relevance drives the ranking rather than surface-level word matching.Step 6: Tune search accuracy with SearchParams
SearchParams controls how the HNSW index is traversed at query time. Adjusting these values lets you trade search speed for recall accuracy.
Run this cell to compare the results of three search modes — low-effort approximate, high-effort approximate, and exact brute-force — against the same query.
SearchParams reference
All fields are optional. OmittingSearchParams entirely uses the collection’s default HNSW configuration.
QuantizationSearchParams is not supported in VectorAI DB 1.0.0 and raises UnimplementedError. Use SearchParams(exact=True) for brute-force ground-truth search, or omit params entirely to use the default HNSW approximate search.On small collections (10 vectors), all three
SearchParams modes — hnsw_ef=64, hnsw_ef=256, and exact=True — return identical results. The HNSW approximation only diverges from exact search at larger scale (thousands of vectors or more).Step 7: Score threshold — filter low-confidence results
score_threshold discards results below a minimum similarity score server-side before they are returned. Run this cell to see how raising the threshold progressively narrows the result set for a deep-learning query.
When to use score thresholds
Choose a threshold based on how strictly the results need to match the query intent. Appropriate threshold values depend on your model and dataset — always calibrate by observing your actual score distributions rather than using fixed values.Expected output
The result counts drop as the threshold rises. Withall-MiniLM-L6-v2 on this 10-document corpus, the neural networks query scores 0.70 at the top — so threshold 0.6 returns one result.
Step 8: Pagination with offset and limit
For large result sets, retrieve results in pages. Run this cell to walk through three pages of results for a programming query, with three results per page.points.search(offset=...) is not supported in VectorAI DB 1.0.0 and raises 501 NOT_IMPLEMENTED. The workaround is to fetch the full result set in one call and slice into pages in Python.How pagination works
The full result set is fetched in one call and sliced in Python. Results are ranked by similarity score before slicing.Expected output
Three labeled pages print in sequence, each showing a different slice of the ranked result set.Step 9: Retrieve points by ID
points.get retrieves specific points by their IDs without performing any vector similarity search. Run this cell to fetch points 0, 4, and 6 and print their topic and text.
Parameters
The following parameters control whatpoints.get() returns alongside the point IDs.
Expected output
The three requested points are returned with their payload metadata. No vector data is included becausewith_vectors is set to False.
Step 10: Count points
points.count is not supported in VectorAI DB 1.0.0. Use vde.get_vector_count() for the total and points.scroll() with Python sum() for filtered counts.
points.count() raises UnimplementedError in VectorAI DB 1.0.0 regardless of the exact flag. Use the scroll-based workaround below.Expected output
Step 11: Batch search — multiple queries in one call
search_batch and SearchRequest are not available in the VectorAI DB 1.0.0 SDK. Run searches sequentially as a workaround.
SearchRequest and search_batch raise ImportError in VectorAI DB 1.0.0. Use sequential points.search() calls instead. When search_batch becomes available in a future SDK version, it will send up to 100 searches in a single gRPC round-trip.Step 12: The universal query endpoint
points.query is a more powerful alternative to points.search. It supports vector search, payload ordering, server-side fusion, random sampling, and multistage prefetch — all through a single endpoint.
Vector search via points.query
Run this cell to perform a standard nearest-neighbour search usingpoints.query. It produces the same ranked results as points.search but makes the full query feature set available.
Payload-sorted retrieval
OrderBy and Direction raise ValidationError in VectorAI DB 1.0.0 and are not supported.OrderBy object instead of a vector tells the endpoint to skip similarity computation entirely.
Multi-stage prefetch
PrefetchQuery raises ValidationError in VectorAI DB 1.0.0 and is not supported.How prefetch works
Prefetch executes the filtered subsearches first, then merges their results for a final reranking pass.- In the first stage, the engine fetches candidates matching the machine learning topic filter.
- In the second stage, the engine fetches candidates matching the deep learning topic filter.
- In the final stage, the top-level query reranks the merged candidate pool by similarity.
Step 13: Return vectors with results
Settingwith_vectors=True includes the raw embedding vectors in the response alongside the payload and score. Run this cell to search for “machine learning” and print the dimensionality and first five values of each returned vector.
When to return vectors
Returning vectors increases response size significantly — each 384-dim float vector adds approximately 1.5 KB per result — so only enable this when needed.Selective payload with WithPayloadSelector
Instead ofwith_payload=True (which returns all payload fields), use WithPayloadSelector to include or exclude specific fields.
Expected output
Each result includes the full 384-dimensional vector. The dimensionality confirms the vector is present, and the first five values show a sample of its contents.Step 14: Combine search with filters
Filters restrict which points are considered during similarity search. The filter is evaluated server-side before ranking, so only matching points are scored. Run this cell to search by topic and by difficulty level separately.Expected output
The first search returns only machine learning documents, and the second returns only beginner-level documents, regardless of topic.Step 15: Collection cleanup
Run this cell to flush any pending writes to disk and confirm the vector count. Uncomment the delete lines to remove the collection entirely once finished.Expected output
The vector count confirms nothing was lost during the session, and the flush line confirms all data is persisted to disk.Complete API reference
The following tables summarize the methods, parameters, and distance metrics covered in this tutorial.Core search methods
The primary methods for running vector similarity searches are listed below.Retrieval and counting
The following methods fetch points by ID and count collection contents.Search parameters
All search methods accept the following parameters to control retrieval behaviour.Distance metrics
The metric must be set at collection creation time and cannot be changed afterwards.Next steps
Now that you can embed, store, search, and tune vector queries, explore the following tutorials to add more capabilities to your search pipeline.- Predicate filters — Master the full Filter DSL with all field types and operators.
- Similarity search fundamentals — Explore search parameters, score thresholds, and pagination.
- Use open-source embedding models — Choose the right model for production.
- Optimizing retrieval quality — Tune HNSW parameters and search settings.