WeaviateEx.TenantClient (WeaviateEx v0.7.4)

View Source

Fluent API for tenant-scoped operations.

Provides a Python-like with_tenant experience for multi-tenant collections, enabling clean and readable tenant-scoped data operations.

Usage

# Create a tenant-scoped client
tenant_client = client
  |> WeaviateEx.TenantClient.with_tenant("tenant_A")
  |> WeaviateEx.TenantClient.collection("Articles")

# Perform operations scoped to the tenant
{:ok, object} = TenantClient.insert(tenant_client, %{title: "Hello World"})
{:ok, objects} = TenantClient.query(tenant_client, limit: 10)

Pipelining

The module supports a fluent pipeline style:

client
|> TenantClient.with_tenant("customer_123")
|> TenantClient.collection("Documents")
|> TenantClient.insert(%{content: "Document content"})

All Operations

All standard data operations are available:

Summary

Functions

Batch inserts objects within the tenant scope.

Performs BM25 keyword search within the tenant scope.

Returns the underlying client.

Sets the collection for subsequent operations.

Returns the collection name.

Deletes an object within the tenant scope.

Gets an object by ID within the tenant scope.

Performs hybrid search within the tenant scope.

Inserts an object within the tenant scope.

Performs text-based vector search within the tenant scope.

Performs vector similarity search within the tenant scope.

Queries/lists objects within the tenant scope using GraphQL Get query.

Replaces an object within the tenant scope.

Returns the tenant name.

Updates an object within the tenant scope.

Creates a tenant-scoped client wrapper.

Types

t()

@type t() :: %WeaviateEx.TenantClient{
  client: WeaviateEx.Client.t(),
  collection: String.t() | nil,
  tenant: String.t()
}

Functions

batch_insert(tc, objects, opts \\ [])

@spec batch_insert(t(), [map()], keyword()) :: {:ok, [map()]} | {:error, term()}

Batch inserts objects within the tenant scope.

All objects will have the tenant added automatically.

Examples

objects = [%{properties: %{title: "Doc 1"}}, %{properties: %{title: "Doc 2"}}]
{:ok, results} = TenantClient.batch_insert(tenant_client, objects)

bm25(tc, query_text, opts \\ [])

@spec bm25(t(), String.t(), keyword()) :: {:ok, [map()]} | {:error, term()}

Performs BM25 keyword search within the tenant scope.

Options

  • :properties - Properties to search in (optional)

Examples

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

client(tenant_client)

@spec client(t()) :: WeaviateEx.Client.t()

Returns the underlying client.

Examples

client = TenantClient.client(tenant_client)

collection(tc, coll)

@spec collection(t(), String.t()) :: t()

Sets the collection for subsequent operations.

Examples

tenant_client = tenant_client
  |> TenantClient.collection("Articles")

collection_name(tenant_client)

@spec collection_name(t()) :: String.t() | nil

Returns the collection name.

Examples

"Articles" = TenantClient.collection_name(tenant_client)

delete(tc, id, opts \\ [])

@spec delete(t(), String.t(), keyword()) :: :ok | {:ok, map()} | {:error, term()}

Deletes an object within the tenant scope.

Examples

:ok = TenantClient.delete(tenant_client, "uuid-123")

get(tc, id, opts \\ [])

@spec get(t(), String.t(), keyword()) :: {:ok, map()} | {:error, term()}

Gets an object by ID within the tenant scope.

Examples

{:ok, object} = TenantClient.get(tenant_client, "uuid-123")

hybrid(tc, query_text, opts \\ [])

@spec hybrid(t(), String.t(), keyword()) :: {:ok, [map()]} | {:error, term()}

Performs hybrid search within the tenant scope.

Combines vector similarity and keyword (BM25) search.

Options

  • :alpha - Weight between vector (1.0) and keyword (0.0) search (default: 0.5)
  • :properties - Properties to search for BM25

Examples

{:ok, results} = TenantClient.hybrid(tenant_client, "machine learning",
  alpha: 0.7,
  limit: 10
)

insert(tc, object, opts \\ [])

@spec insert(t(), map(), keyword()) :: {:ok, map()} | {:error, term()}

Inserts an object within the tenant scope.

The tenant is automatically added to the object.

Examples

{:ok, result} = TenantClient.insert(tenant_client, %{title: "Hello World"})

near_text(tc, concepts, opts \\ [])

@spec near_text(t(), String.t() | [String.t()], keyword()) ::
  {:ok, [map()]} | {:error, term()}

Performs text-based vector search within the tenant scope.

Examples

{:ok, results} = TenantClient.near_text(tenant_client, "machine learning", limit: 5)

near_vector(tc, vector, opts \\ [])

@spec near_vector(t(), [float()], keyword()) :: {:ok, [map()]} | {:error, term()}

Performs vector similarity search within the tenant scope.

Examples

{:ok, results} = TenantClient.near_vector(tenant_client, [0.1, 0.2, ...], limit: 5)

query(tc, opts \\ [])

@spec query(
  t(),
  keyword()
) :: {:ok, [map()]} | {:error, term()}

Queries/lists objects within the tenant scope using GraphQL Get query.

Options

  • :limit - Maximum number of results (default: 25)
  • :fields - Fields to return

Examples

{:ok, objects} = TenantClient.query(tenant_client, limit: 10)

replace(tc, id, object, opts \\ [])

@spec replace(t(), String.t(), map(), keyword()) :: {:ok, map()} | {:error, term()}

Replaces an object within the tenant scope.

Examples

{:ok, result} = TenantClient.replace(tenant_client, "uuid-123", %{title: "Replaced"})

tenant_name(tenant_client)

@spec tenant_name(t()) :: String.t()

Returns the tenant name.

Examples

"tenant_A" = TenantClient.tenant_name(tenant_client)

update(tc, id, updates, opts \\ [])

@spec update(t(), String.t(), map(), keyword()) :: {:ok, map()} | {:error, term()}

Updates an object within the tenant scope.

Examples

{:ok, result} = TenantClient.update(tenant_client, "uuid-123", %{title: "Updated"})

with_tenant(client, tenant)

@spec with_tenant(WeaviateEx.Client.t(), String.t()) :: t()

Creates a tenant-scoped client wrapper.

Examples

tenant_client = TenantClient.with_tenant(client, "tenant_A")