WeaviateEx.Types.Beacon (WeaviateEx v0.7.4)
View SourceUtilities for parsing and building Weaviate beacon URLs.
Beacon URLs are Weaviate's way of referencing objects and have the format:
weaviate://localhost/<uuid>- Simple referenceweaviate://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
Functions
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"
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"}
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"}
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"}
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"}
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