Arcana.Graph.GraphStore behaviour (Arcana v2.0.1)

Copy Markdown View Source

Behaviour and dispatch module for graph storage backends.

Arcana supports swappable graph storage:

  • :ecto (default) - PostgreSQL via Ecto
  • :memory - In-memory storage for testing
  • Custom module implementing this behaviour

Configuration

# config/config.exs

# Use Ecto/PostgreSQL (default)
config :arcana, :graph_store, :ecto

# With options
config :arcana, :graph_store, {:ecto, repo: MyApp.Repo}

# Custom module
config :arcana, :graph_store, MyApp.CustomGraphStore

Summary

Callbacks

Deletes all graph data for the given chunk IDs.

Deletes all graph data for a collection.

Finds all entities in a collection.

Finds entities related to the given entity within the specified depth.

Retrieves a single community by ID.

Retrieves community summaries for a collection.

Retrieves a single entity by ID.

Retrieves mentions for an entity with chunk context.

Retrieves a single relationship by ID.

Retrieves all relationships for an entity.

Lists communities with optional filtering and pagination.

Lists entities with optional filtering and pagination.

Lists relationships with optional filtering and pagination.

Persists community data for a collection.

Persists entities to the graph store.

Persists entity mentions (links between entities and chunks).

Persists relationships between entities.

Searches for chunks related to the given entity names.

Searches for entities by embedding similarity.

Functions

Returns the configured graph store backend.

Deletes graph data for the given chunk IDs using the configured backend.

Deletes all graph data for a collection using the configured backend.

Finds entities using the configured backend.

Finds related entities using the configured backend.

Gets a single community by ID using the configured backend.

Gets community summaries using the configured backend.

Gets a single entity by ID using the configured backend.

Gets mentions for an entity using the configured backend.

Gets a single relationship by ID using the configured backend.

Gets relationships for an entity using the configured backend.

Lists communities using the configured backend.

Lists entities using the configured backend.

Lists relationships using the configured backend.

Persists communities using the configured backend.

Persists entities using the configured backend.

Persists entity mentions using the configured backend.

Persists relationships using the configured backend.

Searches for chunks using the configured backend.

Searches for entities by embedding similarity using the configured backend.

Callbacks

delete_by_chunks(chunk_ids, opts)

@callback delete_by_chunks(chunk_ids :: [binary()], opts :: keyword()) ::
  :ok | {:error, term()}

Deletes all graph data for the given chunk IDs.

Removes mentions referencing these chunks, and cleans up orphaned entities (entities with no remaining mentions).

delete_by_collection(binary, opts)

@callback delete_by_collection(binary(), opts :: keyword()) :: :ok | {:error, term()}

Deletes all graph data for a collection.

Removes all entities, relationships, mentions, and communities associated with the collection.

find_entities(binary, opts)

@callback find_entities(binary(), opts :: keyword()) :: [map()]

Finds all entities in a collection.

get_community(community_id, opts)

@callback get_community(community_id :: binary(), opts :: keyword()) ::
  {:ok, map()} | {:error, :not_found}

Retrieves a single community by ID.

get_community_summaries(binary, opts)

@callback get_community_summaries(binary(), opts :: keyword()) :: [map()]

Retrieves community summaries for a collection.

get_entity(binary, opts)

@callback get_entity(binary(), opts :: keyword()) :: {:ok, map()} | {:error, :not_found}

Retrieves a single entity by ID.

get_mentions(binary, opts)

@callback get_mentions(binary(), opts :: keyword()) :: [map()]

Retrieves mentions for an entity with chunk context.

Returns mentions with associated chunk text for display.

get_relationship(relationship_id, opts)

@callback get_relationship(relationship_id :: binary(), opts :: keyword()) ::
  {:ok, map()} | {:error, :not_found}

Retrieves a single relationship by ID.

get_relationships(binary, opts)

@callback get_relationships(binary(), opts :: keyword()) :: [map()]

Retrieves all relationships for an entity.

Returns relationships where the entity is either source or target.

list_communities(opts)

@callback list_communities(opts :: keyword()) :: [map()]

Lists communities with optional filtering and pagination.

Options

  • :collection_id - Filter by collection (nil for all)
  • :level - Filter by hierarchy level
  • :search - Search in summary
  • :limit - Maximum results (default: 50)
  • :offset - Pagination offset (default: 0)

Returns communities with entity counts.

list_entities(opts)

@callback list_entities(opts :: keyword()) :: [map()]

Lists entities with optional filtering and pagination.

Options

  • :collection_id - Filter by collection (nil for all)
  • :type - Filter by entity type
  • :search - Search in entity name
  • :limit - Maximum results (default: 50)
  • :offset - Pagination offset (default: 0)

Returns entities with aggregated counts (mention_count, relationship_count).

list_relationships(opts)

@callback list_relationships(opts :: keyword()) :: [map()]

Lists relationships with optional filtering and pagination.

Options

  • :collection_id - Filter by collection (nil for all)
  • :type - Filter by relationship type
  • :search - Search in entity names or type
  • :strength - Filter by strength (:strong, :medium, :weak)
  • :limit - Maximum results (default: 50)
  • :offset - Pagination offset (default: 0)

Returns relationships with source/target entity names.

persist_communities(binary, list, opts)

@callback persist_communities(binary(), [map()], opts :: keyword()) ::
  :ok | {:error, term()}

Persists community data for a collection.

persist_entities(binary, list, opts)

@callback persist_entities(binary(), [map()], opts :: keyword()) ::
  {:ok, map()} | {:error, term()}

Persists entities to the graph store.

Returns a map of entity names to their assigned IDs.

persist_mentions(list, map, opts)

@callback persist_mentions([map()], map(), opts :: keyword()) :: :ok | {:error, term()}

Persists entity mentions (links between entities and chunks).

persist_relationships(list, map, opts)

@callback persist_relationships([map()], map(), opts :: keyword()) ::
  :ok | {:error, term()}

Persists relationships between entities.

search(list, arg2, opts)

@callback search([String.t()], [binary()] | nil, opts :: keyword()) :: [map()]

Searches for chunks related to the given entity names.

Returns scored chunk results.

search_by_embedding(list, arg2, opts)

@callback search_by_embedding([float()], [binary()] | nil, opts :: keyword()) :: [map()]

Searches for entities by embedding similarity.

Returns entities whose description embeddings are most similar to the query embedding, sorted by similarity descending.

Functions

backend()

Returns the configured graph store backend.

delete_by_chunks(chunk_ids, opts \\ [])

Deletes graph data for the given chunk IDs using the configured backend.

delete_by_collection(collection_id, opts \\ [])

Deletes all graph data for a collection using the configured backend.

find_entities(collection_id, opts \\ [])

Finds entities using the configured backend.

get_community(community_id, opts \\ [])

Gets a single community by ID using the configured backend.

get_community_summaries(collection_id, opts \\ [])

Gets community summaries using the configured backend.

get_entity(entity_id, opts \\ [])

Gets a single entity by ID using the configured backend.

get_mentions(entity_id, opts \\ [])

Gets mentions for an entity using the configured backend.

get_relationship(relationship_id, opts \\ [])

Gets a single relationship by ID using the configured backend.

get_relationships(entity_id, opts \\ [])

Gets relationships for an entity using the configured backend.

list_communities(opts \\ [])

Lists communities using the configured backend.

list_entities(opts \\ [])

Lists entities using the configured backend.

list_relationships(opts \\ [])

Lists relationships using the configured backend.

persist_communities(collection_id, communities, opts \\ [])

Persists communities using the configured backend.

persist_entities(collection_id, entities, opts \\ [])

Persists entities using the configured backend.

persist_mentions(mentions, entity_id_map, opts \\ [])

Persists entity mentions using the configured backend.

persist_relationships(relationships, entity_id_map, opts \\ [])

Persists relationships using the configured backend.

search(entity_names, collection_ids, opts \\ [])

Searches for chunks using the configured backend.

search_by_embedding(query_embedding, collection_ids, opts \\ [])

Searches for entities by embedding similarity using the configured backend.