pub struct VectorStore { /* private fields */ }Expand description
In-memory vector store for retrieval-augmented generation.
Uses the Ollama /api/embed endpoint to compute embeddings and cosine
similarity for nearest-neighbour search.
use std::sync::Arc;
use oxide_agent::rag::VectorStore;
use oxide_agent::client::HttpOllamaClient;
let client = Arc::new(HttpOllamaClient::new("http://localhost:11434"));
let mut store = VectorStore::new(client, "nomic-embed-text");
store.add_text("Rust ownership means one owner at a time.", Default::default()).await?;
let results = store.query("Who owns memory in Rust?", 3).await?;
println!("{}", results[0].content);Implementations§
Source§impl VectorStore
impl VectorStore
pub fn new<C: OllamaClient + 'static>( client: Arc<C>, embed_model: impl Into<String>, ) -> Self
Sourcepub async fn add_text(
&mut self,
text: impl Into<String>,
metadata: HashMap<String, String>,
) -> Result<(), OxideError>
pub async fn add_text( &mut self, text: impl Into<String>, metadata: HashMap<String, String>, ) -> Result<(), OxideError>
Embed a single string and add it to the store.
Sourcepub async fn add_file(&mut self, path: &Path) -> Result<usize, OxideError>
pub async fn add_file(&mut self, path: &Path) -> Result<usize, OxideError>
Read a UTF-8 text file and add each non-empty line as a separate document.
Sourcepub async fn query(
&self,
query: impl Into<String>,
top_k: usize,
) -> Result<Vec<SearchResult>, OxideError>
pub async fn query( &self, query: impl Into<String>, top_k: usize, ) -> Result<Vec<SearchResult>, OxideError>
Return the top_k most similar documents to query, ranked by
cosine similarity (highest first).
pub fn is_empty(&self) -> bool
Auto Trait Implementations§
impl Freeze for VectorStore
impl !RefUnwindSafe for VectorStore
impl Send for VectorStore
impl Sync for VectorStore
impl Unpin for VectorStore
impl UnsafeUnpin for VectorStore
impl !UnwindSafe for VectorStore
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more