WeaviateEx.Types.Beacon (WeaviateEx v0.7.4)

View Source

Utilities for parsing and building Weaviate beacon URLs.

Beacon URLs are Weaviate's way of referencing objects and have the format:

  • weaviate://localhost/<uuid> - Simple reference
  • weaviate://localhost/<collection>/<uuid> - Reference with target collection

Multi-target references (properties that can point to multiple collections) require the collection to be specified in the beacon.

Examples

# Parse a beacon
Beacon.parse("weaviate://localhost/Person/uuid-123")
# => %{collection: "Person", uuid: "uuid-123"}

# Build a beacon
Beacon.build("uuid-123", "Person")
# => "weaviate://localhost/Person/uuid-123"

# Create beacon map for API
Beacon.to_map("uuid-123", "Person")
# => %{"beacon" => "weaviate://localhost/Person/uuid-123"}

Summary

Functions

Builds a beacon URL from a UUID and optional collection.

Extracts the collection name from a beacon URL.

Extracts the UUID from a beacon URL.

Parses a Weaviate beacon URL.

Creates a beacon map suitable for the Weaviate API.

Checks if a string is a valid Weaviate beacon URL.

Types

parsed()

@type parsed() :: %{collection: String.t() | nil, uuid: String.t()}

Functions

build(uuid, collection \\ nil)

@spec build(String.t(), String.t() | nil) :: String.t()

Builds a beacon URL from a UUID and optional collection.

Examples

Beacon.build("uuid-123")
# => "weaviate://localhost/uuid-123"

Beacon.build("uuid-123", "Person")
# => "weaviate://localhost/Person/uuid-123"

extract_collection(beacon)

@spec extract_collection(String.t()) :: {:ok, String.t()} | {:error, String.t()}

Extracts the collection name from a beacon URL.

Only succeeds for beacons that include a collection.

Examples

Beacon.extract_collection("weaviate://localhost/Person/uuid-123")
# => {:ok, "Person"}

Beacon.extract_collection("weaviate://localhost/uuid-123")
# => {:error, "No collection in beacon"}

extract_uuid(beacon)

@spec extract_uuid(String.t()) :: {:ok, String.t()} | {:error, String.t()}

Extracts the UUID from a beacon URL.

Examples

Beacon.extract_uuid("weaviate://localhost/Person/uuid-123")
# => {:ok, "uuid-123"}

Beacon.extract_uuid("invalid")
# => {:error, "Invalid beacon URL: invalid"}

parse(beacon)

@spec parse(String.t()) :: parsed()

Parses a Weaviate beacon URL.

Extracts the collection (if present) and UUID from a beacon URL.

Examples

Beacon.parse("weaviate://localhost/Person/uuid-123")
# => %{collection: "Person", uuid: "uuid-123"}

Beacon.parse("weaviate://localhost/uuid-123")
# => %{collection: nil, uuid: "uuid-123"}

to_map(uuid, collection \\ nil)

@spec to_map(String.t(), String.t() | nil) :: map()

Creates a beacon map suitable for the Weaviate API.

Examples

Beacon.to_map("uuid-123")
# => %{"beacon" => "weaviate://localhost/uuid-123"}

Beacon.to_map("uuid-123", "Person")
# => %{"beacon" => "weaviate://localhost/Person/uuid-123"}

valid?(arg1)

@spec valid?(String.t()) :: boolean()

Checks if a string is a valid Weaviate beacon URL.

Examples

Beacon.valid?("weaviate://localhost/Person/uuid-123")
# => true

Beacon.valid?("https://example.com")
# => false