WeaviateEx.API.Data (WeaviateEx v0.7.4)
View SourceData operations API for CRUD operations on objects.
This module provides a clean, protocol-based API for managing data objects in Weaviate collections with support for:
- Custom UUIDs
- Vector embeddings
- Multi-tenancy
- Consistency levels
- Named vectors (future)
Examples
# Create an object
{:ok, object} = Data.insert(client, "Article", %{
properties: %{"title" => "Hello", "content" => "World"}
})
# Create with custom UUID
{:ok, object} = Data.insert(client, "Article", %{
id: "550e8400-e29b-41d4-a716-446655440000",
properties: %{"title" => "Hello"}
})
# Create with vector
{:ok, object} = Data.insert(client, "Article", %{
properties: %{"title" => "Hello"},
vector: [0.1, 0.2, 0.3]
})
# Get object
{:ok, object} = Data.get_by_id(client, "Article", uuid)
# Update (full replacement)
{:ok, updated} = Data.update(client, "Article", uuid, %{
properties: %{"title" => "Updated"}
})
# Patch (partial update)
{:ok, patched} = Data.patch(client, "Article", uuid, %{
properties: %{"title" => "Patched"}
})
# Delete
{:ok, _} = Data.delete_by_id(client, "Article", uuid)
# Check existence
{:ok, true} = Data.exists?(client, "Article", uuid)
# Validate before insert
{:ok, result} = Data.validate(client, "Article", %{
properties: %{"title" => "Test"}
})
Summary
Functions
Delete an object by its UUID.
Check if an object exists.
Fetch multiple objects by their UUIDs.
Get an object by its UUID.
Insert a new object into a collection.
Patch an object (partial update).
Replace an object entirely (full replacement using PUT).
Update an object (full replacement).
Validate object data without creating it.
Types
Functions
@spec delete_by_id(WeaviateEx.Client.t(), collection_name(), object_id(), opts()) :: {:ok, map()} | {:error, WeaviateEx.Error.t()}
Delete an object by its UUID.
Parameters
client- WeaviateEx clientcollection_name- Name of the collectionid- Object UUIDopts- Options (:tenant,:consistency_level)
Examples
Data.delete_by_id(client, "Article", uuid)
Data.delete_by_id(client, "Article", uuid, tenant: "TenantA")Returns
{:ok, map()}- Empty map on success{:error, Error.t()}- Error if deletion fails
@spec exists?(WeaviateEx.Client.t(), collection_name(), object_id(), opts()) :: {:ok, boolean()}
Check if an object exists.
Parameters
client- WeaviateEx clientcollection_name- Name of the collectionid- Object UUIDopts- Options (:tenant,:consistency_level)
Examples
Data.exists?(client, "Article", uuid)
# => {:ok, true}
Data.exists?(client, "Article", "non-existent")
# => {:ok, false}Returns
{:ok, boolean()}- True if exists, false otherwise
@spec fetch_objects_by_ids( WeaviateEx.Client.t(), collection_name(), [object_id()], opts() ) :: {:ok, [map()]} | {:error, WeaviateEx.Error.t()}
Fetch multiple objects by their UUIDs.
Uses a GraphQL query with ContainsAny filter for efficient batch retrieval.
Parameters
client- WeaviateEx clientcollection_name- Name of the collectionids- List of object UUIDs to fetchopts- Options::return_properties- List of property names to return (default: all):tenant- Tenant name for multi-tenant collections
Examples
ids = ["uuid-1", "uuid-2", "uuid-3"]
{:ok, objects} = Data.fetch_objects_by_ids(client, "Article", ids)
# With specific properties
{:ok, objects} = Data.fetch_objects_by_ids(client, "Article", ids,
return_properties: ["title", "content"]
)
# With tenant
{:ok, objects} = Data.fetch_objects_by_ids(client, "Article", ids,
tenant: "tenant-a"
)Returns
{:ok, list()}- List of matching objects{:error, Error.t()}- Error if query fails
@spec get_by_id(WeaviateEx.Client.t(), collection_name(), object_id(), opts()) :: {:ok, map()} | {:error, WeaviateEx.Error.t()}
Get an object by its UUID.
Parameters
client- WeaviateEx clientcollection_name- Name of the collectionid- Object UUIDopts- Options (:tenant,:consistency_level,:include)
Examples
Data.get_by_id(client, "Article", "550e8400-e29b-41d4-a716-446655440000")
Data.get_by_id(client, "Article", uuid,
tenant: "TenantA",
include: "vector"
)Returns
{:ok, object}- Retrieved object{:error, Error.t()}- Error if not found
@spec insert(WeaviateEx.Client.t(), collection_name(), object_data(), opts()) :: {:ok, map()} | {:error, WeaviateEx.Error.t()}
Insert a new object into a collection.
Parameters
client- WeaviateEx clientcollection_name- Name of the collectiondata- Object data map with:propertiesand optionally:id,:vectoropts- Options (:tenant,:consistency_level)
Examples
Data.insert(client, "Article", %{
properties: %{"title" => "Hello"}
})
Data.insert(client, "Article", %{
id: "550e8400-e29b-41d4-a716-446655440000",
properties: %{"title" => "Hello"},
vector: [0.1, 0.2, 0.3]
}, tenant: "TenantA")Returns
{:ok, object}- Created object with UUID{:error, Error.t()}- Error if creation fails
@spec patch( WeaviateEx.Client.t(), collection_name(), object_id(), object_data(), opts() ) :: {:ok, map()} | {:error, WeaviateEx.Error.t()}
Patch an object (partial update).
This merges changes with existing data.
Parameters
client- WeaviateEx clientcollection_name- Name of the collectionid- Object UUIDdata- Partial object dataopts- Options (:tenant,:consistency_level)
Examples
Data.patch(client, "Article", uuid, %{
properties: %{"title" => "Updated Title"}
})Returns
{:ok, object}- Updated object (retrieved after patch){:error, Error.t()}- Error if patch fails
@spec replace( WeaviateEx.Client.t(), collection_name(), object_id(), object_data(), opts() ) :: {:ok, map()} | {:error, WeaviateEx.Error.t()}
Replace an object entirely (full replacement using PUT).
This is a semantic alias for update/5 that makes the intent clearer.
Use this when you want to replace the entire object with new data.
All existing properties will be replaced with the new data. Properties not included in the new data will be removed.
Parameters
client- WeaviateEx clientcollection_name- Name of the collectionid- Object UUIDdata- Complete object data to replace withopts- Options (:tenant,:consistency_level,:keep_vector)
Examples
Data.replace(client, "Article", uuid, %{
properties: %{"title" => "New Title", "content" => "New Content"}
})
# Replace but keep existing vector
Data.replace(client, "Article", uuid, %{
properties: %{"title" => "New Title"}
}, keep_vector: true)Returns
{:ok, object}- Replaced object{:error, Error.t()}- Error if replace fails
@spec update( WeaviateEx.Client.t(), collection_name(), object_id(), object_data(), opts() ) :: {:ok, map()} | {:error, WeaviateEx.Error.t()}
Update an object (full replacement).
This replaces the entire object with new data.
Parameters
client- WeaviateEx clientcollection_name- Name of the collectionid- Object UUIDdata- New object dataopts- Options (:tenant,:consistency_level)
Examples
Data.update(client, "Article", uuid, %{
properties: %{"title" => "New Title", "content" => "New Content"}
})Returns
{:ok, object}- Updated object{:error, Error.t()}- Error if update fails
@spec validate(WeaviateEx.Client.t(), collection_name(), object_data(), opts()) :: {:ok, map()} | {:error, WeaviateEx.Error.t()}
Validate object data without creating it.
Useful for checking if object data is valid before insertion.
Parameters
client- WeaviateEx clientcollection_name- Name of the collectiondata- Object data to validateopts- Options
Examples
Data.validate(client, "Article", %{
properties: %{"title" => "Test"}
})Returns
{:ok, result}- Validation result{:error, Error.t()}- Validation error