WeaviateEx.Query.NearVector (WeaviateEx v0.7.4)
View SourceNear vector query configuration builders.
This module provides functions for building near_vector queries, including support for single vectors, multiple vectors, and per-target named vector configurations.
Single Vector Query
# Standard vector search
vector = [0.1, 0.2, 0.3, ...]
NearVector.single(vector)List of Vectors Query
# Query with multiple vectors (averaged or combined)
vectors = [vector1, vector2, vector3]
NearVector.list_of_vectors(vectors)Per-Target Vectors Query
# Different vectors for different named vector spaces
NearVector.per_target(%{
"title_vector" => title_vec,
"content_vector" => content_vec
})These can be used with the Query module:
Query.new("Article")
|> Query.near_vector(NearVector.per_target(%{"title" => vec}))
|> Query.execute(client)
Summary
Functions
Create a query with a list of vectors.
Create a query with different vectors for different target vector spaces.
Create a single vector query.
Convert a near vector configuration to API format.
Create a weighted multi-target vector query.
Types
Functions
Create a query with a list of vectors.
Used for multi-vector search patterns where you want to query with multiple vectors over a single vector space. The server may average or otherwise combine these vectors.
Parameters
vectors- A list of vectors (each vector is a list of floats)
Options
:certainty- Minimum certainty threshold:distance- Maximum distance threshold
Examples
vectors = [vec1, vec2, vec3]
NearVector.list_of_vectors(vectors)
# With certainty
NearVector.list_of_vectors(vectors, certainty: 0.7)
@spec per_target( target_vectors(), keyword() ) :: map()
Create a query with different vectors for different target vector spaces.
Used with collections that have multiple named vectors. Allows you to provide a different query vector for each named vector space.
Parameters
targets- A map of named vector names to their respective query vectors
Options
:certainty- Minimum certainty threshold (applied to all targets):distance- Maximum distance threshold (applied to all targets):combination_method- How to combine results (:sum,:average,:minimum,:manual)
Examples
NearVector.per_target(%{
"title_vector" => title_embedding,
"content_vector" => content_embedding
})
NearVector.per_target(%{
"image" => image_vec,
"text" => text_vec
}, combination_method: :average)
Create a single vector query.
Parameters
vector- A list of floats representing the query vector
Options
:certainty- Minimum certainty threshold (0.0 to 1.0):distance- Maximum distance threshold
Examples
NearVector.single([0.1, 0.2, 0.3])
NearVector.single(vector, certainty: 0.8)
Convert a near vector configuration to API format.
Examples
config = NearVector.single([0.1, 0.2])
NearVector.to_api(config)
# => %{"vector" => [0.1, 0.2]}
Create a weighted multi-target vector query.
Allows specifying weights for each target vector space.
Parameters
weighted_targets- A list of tuples:{vector_name, vector, weight}
Options
:certainty- Minimum certainty threshold:distance- Maximum distance threshold
Examples
NearVector.weighted_targets([
{"title_vector", title_vec, 0.7},
{"content_vector", content_vec, 0.3}
])