Guava.DocumentQA (Guava v0.34.0)

Copy Markdown View Source

Question-answering over documents.

Server mode (default): documents are uploaded to the Guava server, which answers questions over them. No local vector store needed.

qa = Guava.DocumentQA.new(client, documents: [policy_text, faq_text])
{:ok, answer} = Guava.DocumentQA.ask(qa, "What is the deductible?")

Local mode: pass a :store (implementing Guava.RAG.VectorStore) and a :generation_model (implementing Guava.RAG.GenerationModel), each as a {module, state} tuple.

Summary

Functions

Add a document (content-addressed). Returns the updated DocumentQA.

Answer question over this instance's documents. Returns {:ok, answer} | {:error, _}.

Like ask/3, but returns the answer or raises Guava.Error.

Delete all documents tracked by this instance. Returns the updated DocumentQA.

Delete a document by key. Returns the updated DocumentQA.

Build a DocumentQA.

Add or replace a document by key. Returns the updated DocumentQA.

Types

t()

@type t() :: %Guava.DocumentQA{
  chunk_overlap: term(),
  chunk_size: term(),
  client: term(),
  generation_model: term(),
  instructions: term(),
  mode: term(),
  namespace: term(),
  store: term(),
  tracked_keys: term()
}

Functions

add_document(qa, text)

@spec add_document(t(), String.t()) :: t()

Add a document (content-addressed). Returns the updated DocumentQA.

ask(qa, question, k \\ 5)

@spec ask(t(), String.t(), pos_integer()) ::
  {:ok, String.t()} | {:error, Guava.Error.t()}

Answer question over this instance's documents. Returns {:ok, answer} | {:error, _}.

ask!(qa, question, k \\ 5)

@spec ask!(t(), String.t(), pos_integer()) :: String.t()

Like ask/3, but returns the answer or raises Guava.Error.

clear(qa)

@spec clear(t()) :: t()

Delete all documents tracked by this instance. Returns the updated DocumentQA.

delete_document(qa, key)

@spec delete_document(t(), String.t()) :: t()

Delete a document by key. Returns the updated DocumentQA.

new(client, opts \\ [])

@spec new(
  Guava.Client.t(),
  keyword()
) :: t()

Build a DocumentQA.

Options

  • :documents — string or list of strings to index at construction.
  • :ids — optional stable ids for the documents (enables later update).
  • :namespace — scope this instance's documents on the server.
  • :instructions — system instruction for answering.
  • :store, :generation_model — switch to local mode ({module, state}).
  • :chunk_size, :chunk_overlap — local-mode chunking.

upsert_document(qa, key, text)

@spec upsert_document(t(), String.t(), String.t()) :: t()

Add or replace a document by key. Returns the updated DocumentQA.