
Create and connect to a vector store
ragnar_store_create.Rd
Create and connect to a vector store
Usage
ragnar_store_create(
location = ":memory:",
embed = embed_ollama(),
embedding_size = ncol(embed("foo")),
overwrite = FALSE,
...,
extra_cols = NULL,
name = NULL
)
Arguments
- location
filepath, or
:memory:
- embed
A function that is called with a character vector and returns a matrix of embeddings. Note this function will be serialized and then deserialized in new R sessions, so it cannot reference to any objects in the global or parent environments. Make sure to namespace all function calls with
::
. If additional R objects must be available in the function, you can optionally supply acarrier::crate()
with packaged data. It can also beNULL
for stores that don't need to embed their texts, for example, if only using FTS algorithms such asragnar_retrieve_bm25()
.- embedding_size
integer
- overwrite
logical, what to do if
location
already exists- ...
Unused. Must be empty.
- extra_cols
A zero row data frame used to specify additional columns that should be added to the store. Such columns can be used for adding additional context when retrieving. See the examples for more information.
vctrs::vec_cast()
is used to consistently perform type checks and casts when inserting withragnar_store_insert()
.- name
A unique name for the store. Must match the
^[a-zA-Z0-9_-]+$
regex. Used byragnar_register_tool_retrieve()
for registering tools.
Examples
# A store with a dummy embedding
store <- ragnar_store_create(
embed = \(x) matrix(stats::runif(10), nrow = length(x), ncol = 10),
)
ragnar_store_insert(store, data.frame(text = "hello"))
# A store with a schema. When inserting into this store, users need to
# provide a `area` column.
store <- ragnar_store_create(
embed = \(x) matrix(stats::runif(10), nrow = length(x), ncol = 10),
extra_cols = data.frame(area = character()),
)
ragnar_store_insert(store, data.frame(text = "hello", area = "rag"))
# If you already have a data.frame with chunks that will be inserted into
# the store, you can quickly create a suitable store with:
chunks <- data.frame(text = letters, area = "rag")
store <- ragnar_store_create(
embed = \(x) matrix(stats::runif(10), nrow = length(x), ncol = 10),
extra_cols = vctrs::vec_ptype(chunks),
)
ragnar_store_insert(store, chunks)