WeaviateEx.Client (WeaviateEx v0.7.4)
View SourceWeaviateEx client with hybrid gRPC/HTTP support.
The client uses:
- gRPC for data operations (search, batch, aggregate, tenants)
- HTTP for schema operations (collections management)
This hybrid approach is necessary because Weaviate's gRPC API doesn't include schema management operations.
Usage
# Connect to local Weaviate
{:ok, client} = WeaviateEx.Client.connect(base_url: "http://localhost:8080")
# Connect to Weaviate Cloud
{:ok, client} = WeaviateEx.Client.connect(
base_url: "https://my-cluster.weaviate.network",
api_key: "your-api-key"
)
# Use the client
{:ok, results} = WeaviateEx.Query.near_text(client, "Article", "machine learning")
# Disconnect when done
:ok = WeaviateEx.Client.disconnect(client)
Summary
Functions
Close the client and release all connections.
Check if client has been closed.
Connect to a Weaviate instance.
Disconnect the client.
Execute a GraphQL query against Weaviate.
Get the gRPC channel from the client.
Check if the client has an active gRPC connection.
Build gRPC metadata from client config.
Create a new client without establishing connections.
Make an HTTP request using the configured protocol.
Get client statistics.
Get current client status.
Execute a function with an auto-managed client.
Types
@type t() :: %WeaviateEx.Client{ config: WeaviateEx.Client.Config.t(), grpc_channel: GRPC.Channel.t() | nil, protocol_impl: module(), state: WeaviateEx.Client.State.t() }
Functions
@spec close(t()) :: :ok
Close the client and release all connections.
This marks the client as closed and disconnects any active connections. Once closed, a client cannot be reused - create a new client instead.
Examples
:ok = Client.close(client)
Check if client has been closed.
Examples
false = Client.closed?(client)
Client.close(client)
true = Client.closed?(client)
@spec connect(keyword()) :: {:ok, t()} | {:error, WeaviateEx.Error.t()}
Connect to a Weaviate instance.
Establishes both gRPC channel (for data operations) and HTTP client (for schema operations).
Options
:base_url- HTTP base URL (default: "http://localhost:8080"):grpc_host- gRPC host (default: derived from base_url):grpc_port- gRPC port (default: 50051, or 443 for HTTPS):api_key- API key for authentication:auth- Authentication config (WeaviateEx.Auth) for API key, bearer token, or OIDC:timeout- Connection timeout in milliseconds (default: 30000):skip_grpc- Skip gRPC connection (use HTTP only):skip_init_checks- Skip meta/version/gRPC health checks (default: false):connection- Connection pool settings (WeaviateEx.Config.Connectionor keyword list):proxy- Proxy settings (WeaviateEx.Config.Proxy, keyword list, or:env)
Examples
{:ok, client} = WeaviateEx.Client.connect(
base_url: "http://localhost:8080",
api_key: "secret-key"
)
@spec disconnect(t()) :: :ok
Disconnect the client.
Closes the gRPC channel if one is established.
Examples
:ok = WeaviateEx.Client.disconnect(client)
@spec graphql(t(), String.t()) :: WeaviateEx.Protocol.response()
Execute a GraphQL query against Weaviate.
Used for queries that require GraphQL features not available in gRPC, such as generative search.
Examples
{:ok, response} = WeaviateEx.Client.graphql(client, "{ Get { Article { title } } }")
@spec grpc_channel(t()) :: GRPC.Channel.t() | nil
Get the gRPC channel from the client.
Returns nil if no gRPC channel is established.
Examples
channel = WeaviateEx.Client.grpc_channel(client)
Check if the client has an active gRPC connection.
Examples
true = WeaviateEx.Client.grpc_connected?(client)
Build gRPC metadata from client config.
Includes authorization header if API key is set.
Examples
metadata = WeaviateEx.Client.grpc_metadata(client)
Create a new client without establishing connections.
This is a lightweight alternative to connect/1 that doesn't establish
the gRPC channel upfront. Useful for testing or when you need to
configure the client before connecting.
Examples
{:ok, client} = WeaviateEx.Client.new(
base_url: "http://localhost:8080",
api_key: "secret-key"
)
@spec request( t(), WeaviateEx.Protocol.method(), WeaviateEx.Protocol.path(), WeaviateEx.Protocol.body(), WeaviateEx.Protocol.opts() ) :: WeaviateEx.Protocol.response()
Make an HTTP request using the configured protocol.
Used for schema/collection operations which don't have gRPC equivalents.
Examples
{:ok, response} = WeaviateEx.Client.request(client, :get, "/v1/schema", nil, [])
@spec stats(t()) :: WeaviateEx.Client.State.t()
Get client statistics.
Returns state information including request counts, error counts, and timestamps.
Examples
stats = Client.stats(client)
IO.puts("Requests: #{stats.request_count}")
@spec status(t()) :: WeaviateEx.Client.State.status()
Get current client status.
Returns one of:
:initializing- Client is being set up:connected- Client is connected and ready:disconnected- Client is disconnected but not closed:closed- Client has been closed and cannot be reused
Examples
:connected = Client.status(client)
Execute a function with an auto-managed client.
Creates a client, executes the function, and ensures cleanup even if the function raises an error.
Examples
result = Client.with_client([base_url: url], fn client ->
WeaviateEx.Objects.list(client, "Article")
end)