Skip to contents

create_search_tool() builds a ragnar store from documents (one chunked document per element, embedded with embedding_fn), indexes it and wraps it with ragnar_tool(), in one step. Embedding the documents calls the embedding provider.

Usage

create_search_tool(
  documents,
  embedding_fn,
  k = 5L,
  name = "search_documents",
  description = NULL,
  ...
)

Arguments

documents

A character vector of documents, or a data frame with a text or content column.

embedding_fn

An embedding function, passed to ragnar::ragnar_store_create() as embed, for example \(x) ragnar::embed_openai(x, model = "text-embedding-3-small").

k

Number of chunks to return per search.

name

Tool name shown to the model.

description

Tool description shown to the model; see ragnar_tool().

...

Passed to ragnar::ragnar_store_create(), for example location to keep the store in a file instead of in memory.

Value

An ellmer tool definition, as returned by ragnar_tool().

Examples

if (FALSE) { # \dontrun{
# Create tool directly from documents
docs <- c(
  "R is a programming language for statistical computing.",
  "Python is a general-purpose programming language.",
  "Julia is designed for high-performance numerical computing."
)

search_tool <- create_search_tool(
  documents = docs,
  embedding_fn = \(x) ragnar::embed_openai(x, model = "text-embedding-3-small"),
  k = 2
)

# Use the tool
search_tool("What language is best for statistics?")
} # }