Arcana (Arcana v3.0.1)

Copy Markdown View Source

RAG (Retrieval Augmented Generation) library for Elixir.

Arcana provides document ingestion, embedding, and vector search capabilities that you can embed into any Phoenix/Ecto application.

Usage

# Ingest a document
{:ok, document} = Arcana.ingest("Your text content", repo: MyApp.Repo)

# Search for relevant chunks
{:ok, results} = Arcana.search("your query", repo: MyApp.Repo)

# Ask questions with RAG
{:ok, answer} = Arcana.ask("What is X?", repo: MyApp.Repo, llm: my_llm)

# Delete a document
:ok = Arcana.delete(document.id, repo: MyApp.Repo)

Modules

Summary

Functions

Asks a question using retrieved context from the knowledge base. See Arcana.Ask.ask/2 for options.

Returns the configured chunker as a {module, opts} tuple. See Arcana.Config for configuration options.

Returns the current Arcana configuration.

Counts documents matching the list_documents/1 filters. See Arcana.Documents.count_documents/1.

Deletes a document and all its chunks.

Returns the configured embedder as a {module, opts} tuple. See Arcana.Config for configuration options.

Returns whether GraphRAG is enabled.

Ingests text content, creating a document with embedded chunks. See Arcana.Ingest.ingest/2 for options.

Ingests in-memory bytes, routing on the required :filename option's extension. See Arcana.Ingest.ingest_binary/2 for options.

Ingests a file, parsing its content and creating a document with embedded chunks. See Arcana.Ingest.ingest_file/2 for options.

Lists documents, newest first. See Arcana.Documents.list_documents/1.

Rewrites a query using a provided rewriter function. See Arcana.Search.rewrite_query/2 for options.

Searches for chunks similar to the query. See Arcana.Search.search/2 for options.

Functions

ask(question, opts)

Asks a question using retrieved context from the knowledge base. See Arcana.Ask.ask/2 for options.

chunker()

Returns the configured chunker as a {module, opts} tuple. See Arcana.Config for configuration options.

config()

Returns the current Arcana configuration.

count_documents(opts)

Counts documents matching the list_documents/1 filters. See Arcana.Documents.count_documents/1.

delete(document_id, opts)

Deletes a document and all its chunks.

When the graph is enabled, also sweeps the document's collection for orphaned graph data: entities left with zero mentions are deleted and communities that referenced them are marked dirty so the next summarize pass regenerates them.

Returns :ok, {:error, :not_found}, or {:error, {:sweep_failed, reason}} when the graph store fails to sweep. In the :sweep_failed case the document and its chunks ARE deleted — only the orphan cleanup failed, so the collection may hold entities with zero mentions until the next sweep.

Sweeping is optional for custom graph stores: one that doesn't implement Arcana.Graph.GraphStore.sweep_orphans/2 returns :ok and leaves the orphans alone.

Options

  • :repo - The Ecto repo to use (required)
  • :graph - Sweep orphaned graph data after deletion (default: from config)

embedder()

Returns the configured embedder as a {module, opts} tuple. See Arcana.Config for configuration options.

get_document(id, opts)

Fetches a document by id. See Arcana.Documents.get_document/2.

graph_enabled?(opts)

Returns whether GraphRAG is enabled.

ingest(text, opts)

Ingests text content, creating a document with embedded chunks. See Arcana.Ingest.ingest/2 for options.

ingest_binary(binary, opts)

Ingests in-memory bytes, routing on the required :filename option's extension. See Arcana.Ingest.ingest_binary/2 for options.

ingest_file(path, opts)

Ingests a file, parsing its content and creating a document with embedded chunks. See Arcana.Ingest.ingest_file/2 for options.

list_documents(opts)

Lists documents, newest first. See Arcana.Documents.list_documents/1.

rewrite_query(query, opts \\ [])

Rewrites a query using a provided rewriter function. See Arcana.Search.rewrite_query/2 for options.

search(query, opts)

Searches for chunks similar to the query. See Arcana.Search.search/2 for options.