WeaviateEx.TenantClient (WeaviateEx v0.7.4)
View SourceFluent 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:
insert/3- Insert a single objectquery/2- List/query objectsget/2- Get a single object by IDupdate/3- Update an objectdelete/2- Delete an objectbatch_insert/3- Batch insert multiple objectsnear_vector/3- Vector similarity searchnear_text/3- Text-based searchhybrid/3- Hybrid searchbm25/3- Keyword search
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
@type t() :: %WeaviateEx.TenantClient{ client: WeaviateEx.Client.t(), collection: String.t() | nil, tenant: String.t() }
Functions
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)
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
)
@spec client(t()) :: WeaviateEx.Client.t()
Returns the underlying client.
Examples
client = TenantClient.client(tenant_client)
Sets the collection for subsequent operations.
Examples
tenant_client = tenant_client
|> TenantClient.collection("Articles")
Returns the collection name.
Examples
"Articles" = TenantClient.collection_name(tenant_client)
Deletes an object within the tenant scope.
Examples
:ok = TenantClient.delete(tenant_client, "uuid-123")
Gets an object by ID within the tenant scope.
Examples
{:ok, object} = TenantClient.get(tenant_client, "uuid-123")
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
)
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"})
Performs text-based vector search within the tenant scope.
Examples
{:ok, results} = TenantClient.near_text(tenant_client, "machine learning", limit: 5)
Performs vector similarity search within the tenant scope.
Examples
{:ok, results} = TenantClient.near_vector(tenant_client, [0.1, 0.2, ...], limit: 5)
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)
Replaces an object within the tenant scope.
Examples
{:ok, result} = TenantClient.replace(tenant_client, "uuid-123", %{title: "Replaced"})
Returns the tenant name.
Examples
"tenant_A" = TenantClient.tenant_name(tenant_client)
Updates an object within the tenant scope.
Examples
{:ok, result} = TenantClient.update(tenant_client, "uuid-123", %{title: "Updated"})
@spec with_tenant(WeaviateEx.Client.t(), String.t()) :: t()
Creates a tenant-scoped client wrapper.
Examples
tenant_client = TenantClient.with_tenant(client, "tenant_A")