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
textorcontentcolumn.- embedding_fn
An embedding function, passed to
ragnar::ragnar_store_create()asembed, 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 examplelocationto keep the store in a file instead of in memory.
Value
An ellmer tool definition, as returned by ragnar_tool().
See also
Other integrations:
as_dsprrr_metric(),
as_dsprrr_traces(),
as_ellmer_tool(),
as_vitals_cost(),
as_vitals_samples(),
as_vitals_solver(),
as_vitals_task(),
llm_predict(),
ragnar_tool(),
reasoning_effort(),
register_dsprrr_engine(),
summarize_traces_df(),
temperature(),
top_p(),
use_dsprrr_template(),
validate_workflow(),
vitals_metrics
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?")
} # }