WeaviateEx.GRPC.Channel (WeaviateEx v0.7.4)

View Source

Manages gRPC channel connections to Weaviate server.

This module provides functions for establishing, managing, and disconnecting gRPC channels to Weaviate's gRPC endpoint.

Usage

config = %{
  grpc_host: "localhost",
  grpc_port: 50051,
  api_key: "your-api-key"
}

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

# Use the channel for RPC calls...

:ok = WeaviateEx.GRPC.Channel.disconnect(channel)

Summary

Functions

Builds gRPC metadata from config.

Establishes a gRPC channel connection to the Weaviate server.

Checks if a channel is connected.

Disconnects a gRPC channel.

Types

config()

@type config() :: %{
  :grpc_host => String.t(),
  :grpc_port => non_neg_integer(),
  :api_key => String.t() | nil,
  optional(:tls) => boolean(),
  optional(:max_message_size) => non_neg_integer(),
  optional(:auth) => WeaviateEx.Auth.t() | nil,
  optional(:token_manager) => GenServer.server() | nil,
  optional(:additional_headers) => map(),
  optional(:connection) => WeaviateEx.Config.Connection.t() | nil,
  optional(:proxy) => WeaviateEx.Config.Proxy.t() | nil
}

Functions

build_metadata(config)

@spec build_metadata(config() | map() | keyword()) :: map()

Builds gRPC metadata from config.

Adds authorization header if API key is present. Includes additional_headers with lowercased keys. Accepts either a map or keyword list.

Examples

%{"authorization" => "Bearer key"} = Channel.build_metadata(%{api_key: "key"})
%{"authorization" => "Bearer key"} = Channel.build_metadata(api_key: "key")
%{} = Channel.build_metadata(%{api_key: nil})

# With additional headers (keys are lowercased for gRPC)
config = %{api_key: "key", additional_headers: %{"X-OpenAI-Api-Key" => "sk-123"}}
metadata = Channel.build_metadata(config)
# => %{"authorization" => "Bearer key", "x-openai-api-key" => "sk-123"}

connect(config, opts \\ [])

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

Establishes a gRPC channel connection to the Weaviate server.

Options

  • :timeout - Connection timeout in milliseconds (default: 30000)

Examples

{:ok, channel} = Channel.connect(%{grpc_host: "localhost", grpc_port: 50051, api_key: nil})
{:error, error} = Channel.connect(%{grpc_host: "invalid", grpc_port: 50051, api_key: nil})

connected?(channel)

@spec connected?(GRPC.Channel.t()) :: boolean()

Checks if a channel is connected.

Examples

true = Channel.connected?(channel)

disconnect(channel)

@spec disconnect(GRPC.Channel.t()) :: :ok

Disconnects a gRPC channel.

Examples

:ok = Channel.disconnect(channel)