Rig-SQLite
This companion crate implements a Rig vector store based on SQLite.
Usage
Add the companion crate to your Cargo.toml, along with the rig-core crate:
[]
= "0.2.6"
= "0.37.0"
= { = "1", = ["derive"] }
= "1"
You can also run cargo add rig-sqlite rig-core serde_json and
cargo add serde --features derive to add the most recent versions of the
dependencies to your project.
See the /examples folder for usage examples.
Important Note
Before using the SQLite vector store, you must initialize the SQLite vector extension. Add this code before creating your connection:
use sqlite3_auto_extension;
use sqlite3_vec_init;
unsafe
Storing JSON Metadata
Declare JSON metadata columns with Column::new("metadata", "JSON") and store
the value as serde_json::Value. Rig writes the value as JSON text and parses
it back as structured JSON when documents are returned from vector searches.
use Embed;
use ;
use ;
Filtering JSON Metadata
SQLite filters can target document-table columns that store JSON text. Use SQLite's JSON extraction operators in the filter key:
use ;
use SqliteSearchFilter;
let req = builder
.query
.samples
.filter
.build;
Use ->> when you want SQLite to compare a JSON value as a SQL scalar, such as
text, number, or boolean. Use -> when you want to compare against JSON text;
Rig serializes the right-hand side as JSON for that form.
JSON metadata filters are applied after sqlite-vec candidate search because
they reference the document table, not sqlite-vec metadata columns. This keeps
results correct, including with samples(1), but requires exhaustive candidate
retrieval. For frequently-used scalar filters, prefer storing the value in a
regular column marked with Column::indexed() so sqlite-vec can apply it during
candidate search.