WeaviateEx.API.References (WeaviateEx v0.7.4)
View SourceCross-reference operations for Weaviate objects.
Provides CRUD operations for managing relationships between objects.
Examples
# Add a single reference
References.add(client, "Article", source_uuid, "hasAuthor", author_uuid)
# Add a multi-target reference using map
References.add(client, "Article", source_uuid, "relatedTo", %{
target_collection: "Category",
uuids: category_uuid
})
# Add a multi-target reference using ReferenceToMulti struct
ref = ReferenceToMulti.new("Category", category_uuid)
References.add(client, "Article", source_uuid, "relatedTo", ref)
# Delete a reference
References.delete(client, "Article", source_uuid, "hasAuthor", author_uuid)
# Replace all references on a property
References.replace(client, "Article", source_uuid, "hasAuthors", [uuid1, uuid2, uuid3])
# Replace with multi-target references
References.replace(client, "Article", source_uuid, "relatedTo", [
ReferenceToMulti.new("Person", person_uuid),
ReferenceToMulti.new("Organization", org_uuid)
])
# Batch add references
References.add_many(client, "Article", [
%{from_uuid: "article-1", from_property: "hasAuthor", to_uuid: "author-1"},
%{from_uuid: "article-2", from_property: "hasAuthor", to_uuid: "author-2"}
])
Summary
Functions
Add a reference from one object to another.
Add multiple references in batch.
Delete a reference from an object.
Replace all references on a property.
Types
@type reference_input() :: uuid() | reference_to_multi() | WeaviateEx.Data.ReferenceToMulti.t()
@type uuid() :: String.t()
Functions
@spec add( WeaviateEx.Client.t(), String.t(), uuid(), String.t(), reference_input(), keyword() ) :: {:ok, map()} | {:error, WeaviateEx.Error.t()}
Add a reference from one object to another.
Parameters
client- The Weaviate clientcollection- The source collection namefrom_uuid- UUID of the source objectfrom_property- Name of the reference propertyto- Target UUID or multi-target referenceopts- Additional options (tenant, etc.)
Examples
# Single target reference
References.add(client, "Article", source_uuid, "hasAuthor", target_uuid)
# Multi-target reference
References.add(client, "Article", source_uuid, "relatedTo", %{
target_collection: "Category",
uuids: category_uuid
})
@spec add_many(WeaviateEx.Client.t(), String.t(), [data_reference()], keyword()) :: {:ok, map()} | {:error, WeaviateEx.Error.t()}
Add multiple references in batch.
Parameters
client- The Weaviate clientcollection- The source collection namereferences- List of reference specificationsopts- Additional options
Reference specification
Each reference should be a map with:
:from_uuid- UUID of the source object:from_property- Name of the reference property:to_uuid- Target UUID:target_collection- (optional) Target collection for multi-target refs
Examples
references = [
%{from_uuid: "article-1", from_property: "hasAuthor", to_uuid: "author-1"},
%{from_uuid: "article-2", from_property: "hasAuthor", to_uuid: "author-2"}
]
References.add_many(client, "Article", references)
@spec delete( WeaviateEx.Client.t(), String.t(), uuid(), String.t(), reference_input(), keyword() ) :: {:ok, map()} | {:error, WeaviateEx.Error.t()}
Delete a reference from an object.
Parameters
client- The Weaviate clientcollection- The source collection namefrom_uuid- UUID of the source objectfrom_property- Name of the reference propertyto- Target UUID or multi-target reference to deleteopts- Additional options
Examples
References.delete(client, "Article", source_uuid, "hasAuthor", target_uuid)
@spec replace( WeaviateEx.Client.t(), String.t(), uuid(), String.t(), [reference_input()], keyword() ) :: {:ok, map()} | {:error, WeaviateEx.Error.t()}
Replace all references on a property.
This removes all existing references and sets the new ones.
Parameters
client- The Weaviate clientcollection- The source collection namefrom_uuid- UUID of the source objectfrom_property- Name of the reference propertyreferences- List of target UUIDs or multi-target referencesopts- Additional options
Examples
References.replace(client, "Article", source_uuid, "hasAuthors", [uuid1, uuid2, uuid3])