WeaviateEx.GRPC.Services.Search (WeaviateEx v0.7.4)

View Source

gRPC Search service for vector queries.

This module provides high-level functions for performing vector searches against Weaviate using gRPC, including generative search (RAG) support.

Usage

{:ok, channel} = WeaviateEx.GRPC.Channel.connect(config)

{:ok, results} = Search.near_vector(channel, "Article", [0.1, 0.2, ...],
  limit: 10,
  return_properties: ["title", "content"]
)
{:ok, results} = Search.near_text(channel, "Article", "machine learning",
  generative: %{
    single_prompt: "Summarize this article: {content}",
    provider: :openai,
    model: "gpt-4"
  }
)

Summary

Functions

Perform a BM25 keyword search.

Execute a raw SearchRequest.

Perform a hybrid search combining vector and keyword search.

Perform a multimodal image search.

Perform a multimodal media search (audio, video, depth, thermal, IMU).

Perform a search for objects similar to a given object.

Perform a text-based vector search using a text-to-vector model.

Perform a vector similarity search.

Perform a generic search with a filter request map.

Types

search_opts()

@type search_opts() :: [
  limit: non_neg_integer(),
  offset: non_neg_integer(),
  return_properties: [String.t()],
  return_references: [WeaviateEx.Query.QueryReference.t()],
  return_metadata: [atom()],
  filters: map(),
  group_by: WeaviateEx.Query.GroupBy.t(),
  tenant: String.t(),
  certainty: float(),
  distance: float(),
  move_to: map(),
  move_away: map(),
  target_vectors: WeaviateEx.Query.TargetVectors.t(),
  bm25_search_operator: map(),
  max_vector_distance: float(),
  fusion_type: atom(),
  after: String.t(),
  sort: list(),
  autocut: non_neg_integer(),
  generative: WeaviateEx.GRPC.Generative.config()
]

Functions

bm25(channel, collection, query, opts \\ [])

@spec bm25(GRPC.Channel.t(), String.t(), String.t(), search_opts()) ::
  {:ok, struct()} | {:error, WeaviateEx.Error.t()}

Perform a BM25 keyword search.

Options

  • :properties - List of properties to search in

Examples

{:ok, results} = Search.bm25(channel, "Article", "machine learning",
  properties: ["title", "content"],
  limit: 10
)

execute(channel, request, opts \\ [])

@spec execute(GRPC.Channel.t(), struct(), keyword()) ::
  {:ok, struct()} | {:error, WeaviateEx.Error.t()}

Execute a raw SearchRequest.

Useful for complex queries that need full control over the request.

Examples

request = %SearchRequest{
  collection: "Article",
  limit: 10,
  near_vector: %NearVector{vector_bytes: <<...>>}
}
{:ok, results} = Search.execute(channel, request)

hybrid(channel, collection, query, opts \\ [])

@spec hybrid(GRPC.Channel.t(), String.t(), String.t(), search_opts()) ::
  {:ok, struct()} | {:error, WeaviateEx.Error.t()}

Perform a hybrid search combining vector and keyword search.

Options

  • :alpha - Weight between vector (1.0) and keyword (0.0) search
  • :fusion_type - Fusion algorithm (:ranked or :relative_score)
  • :properties - Properties to search for BM25

Examples

{:ok, results} = Search.hybrid(channel, "Article", "machine learning",
  alpha: 0.5,
  limit: 10
)

near_image(channel, collection, near_image, opts \\ [])

@spec near_image(
  GRPC.Channel.t(),
  String.t(),
  WeaviateEx.Query.NearImage.t(),
  search_opts()
) ::
  {:ok, struct()} | {:error, WeaviateEx.Error.t()}

Perform a multimodal image search.

Options

  • :limit - Maximum number of results (default: 10)
  • :offset - Number of results to skip
  • :return_properties - List of property names to return
  • :return_metadata - List of metadata fields (e.g., [:uuid, :distance, :vector])
  • :tenant - Tenant name for multi-tenant collections

near_media(channel, collection, near_media, opts \\ [])

@spec near_media(
  GRPC.Channel.t(),
  String.t(),
  WeaviateEx.Query.NearMedia.t(),
  search_opts()
) ::
  {:ok, struct()} | {:error, WeaviateEx.Error.t()}

Perform a multimodal media search (audio, video, depth, thermal, IMU).

near_object(channel, collection, object_id, opts \\ [])

@spec near_object(GRPC.Channel.t(), String.t(), String.t(), search_opts()) ::
  {:ok, struct()} | {:error, WeaviateEx.Error.t()}

Perform a search for objects similar to a given object.

Examples

{:ok, results} = Search.near_object(channel, "Article", "uuid-of-object",
  limit: 10
)

near_text(channel, collection, query, opts \\ [])

@spec near_text(
  GRPC.Channel.t(),
  String.t(),
  String.t() | [String.t()],
  search_opts()
) ::
  {:ok, struct()} | {:error, WeaviateEx.Error.t()}

Perform a text-based vector search using a text-to-vector model.

Options

  • :move_to - Concepts to move towards
  • :move_away - Concepts to move away from
  • Plus all options from near_vector/4

Examples

{:ok, results} = Search.near_text(channel, "Article", "machine learning",
  limit: 10
)

near_vector(channel, collection, vector, opts \\ [])

@spec near_vector(GRPC.Channel.t(), String.t(), [float()], search_opts()) ::
  {:ok, struct()} | {:error, WeaviateEx.Error.t()}

Perform a vector similarity search.

Options

  • :limit - Maximum number of results (default: 10)
  • :offset - Number of results to skip
  • :return_properties - List of property names to return
  • :return_metadata - List of metadata fields (e.g., [:uuid, :distance, :vector])
  • :tenant - Tenant name for multi-tenant collections
  • :certainty - Minimum certainty threshold (0.0 to 1.0)
  • :distance - Maximum distance threshold

Examples

{:ok, results} = Search.near_vector(channel, "Article", vector,
  limit: 10,
  return_properties: ["title", "content"]
)

search(channel, collection, request, opts \\ [])

@spec search(GRPC.Channel.t(), String.t(), map(), keyword()) ::
  {:ok, struct()} | {:error, WeaviateEx.Error.t()}

Perform a generic search with a filter request map.

This is a lower-level function used by the Debug module for protocol comparison.

Options

  • :metadata - gRPC metadata headers

Examples

request = %{collection: "Article", filters: %{...}, limit: 1}
{:ok, results} = Search.search(channel, "Article", request, metadata: metadata)