WeaviateEx.API.References (WeaviateEx v0.7.4)

View Source

Cross-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

Types

data_reference()

@type data_reference() :: %{
  :from_uuid => uuid(),
  :from_property => String.t(),
  :to_uuid => uuid(),
  optional(:target_collection) => String.t()
}

reference_input()

@type reference_input() ::
  uuid() | reference_to_multi() | WeaviateEx.Data.ReferenceToMulti.t()

reference_to_multi()

@type reference_to_multi() :: %{
  target_collection: String.t(),
  uuids: uuid() | [uuid()]
}

uuid()

@type uuid() :: String.t()

Functions

add(client, collection, from_uuid, from_property, to, opts \\ [])

@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 client
  • collection - The source collection name
  • from_uuid - UUID of the source object
  • from_property - Name of the reference property
  • to - Target UUID or multi-target reference
  • opts - 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
})

add_many(client, collection, references, opts \\ [])

@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 client
  • collection - The source collection name
  • references - List of reference specifications
  • opts - 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)

delete(client, collection, from_uuid, from_property, to, opts \\ [])

@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 client
  • collection - The source collection name
  • from_uuid - UUID of the source object
  • from_property - Name of the reference property
  • to - Target UUID or multi-target reference to delete
  • opts - Additional options

Examples

References.delete(client, "Article", source_uuid, "hasAuthor", target_uuid)

replace(client, collection, from_uuid, from_property, references, opts \\ [])

@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 client
  • collection - The source collection name
  • from_uuid - UUID of the source object
  • from_property - Name of the reference property
  • references - List of target UUIDs or multi-target references
  • opts - Additional options

Examples

References.replace(client, "Article", source_uuid, "hasAuthors", [uuid1, uuid2, uuid3])