pub struct Victor<D> { /* private fields */ }
Expand description
The main database struct.
Through this you can Victor::add
and Victor::search
for embeddings.
Implementations§
Source§impl<D: DirectoryHandle> Victor<D>
impl<D: DirectoryHandle> Victor<D>
Sourcepub fn new(root: impl Into<D>) -> Self
pub fn new(root: impl Into<D>) -> Self
Create a new Victor database given a directory handle.
For example, you can use std::path::PathBuf
to use the native filesystem.
Or you can use crate::memory::DirectoryHandle
to use an in-memory database.
Sourcepub async fn add(
&mut self,
content: Vec<impl Into<String>>,
tags: Vec<impl Into<String>>,
)
pub async fn add( &mut self, content: Vec<impl Into<String>>, tags: Vec<impl Into<String>>, )
Add many documents to the database. Embeddings will be generated for each document.
victor
.add(
vec!["Pineapple", "Rocks"], // documents
vec!["Pizza Toppings"], // tags (only used for filtering)
)
.await;
Sourcepub async fn add_single(
&mut self,
content: impl Into<String>,
tags: Vec<impl Into<String>>,
)
pub async fn add_single( &mut self, content: impl Into<String>, tags: Vec<impl Into<String>>, )
Add a single document to the database.
Embedding will be generated for the document.
When adding many documents, it is more efficient to use add
.
victor.add_single("Pepperoni pizza", vec!["Pizza Flavors"]).await;
Sourcepub async fn add_embeddings(
&mut self,
to_add: Vec<(impl Into<String>, Vec<f32>)>,
tags: Vec<impl Into<String>>,
)
pub async fn add_embeddings( &mut self, to_add: Vec<(impl Into<String>, Vec<f32>)>, tags: Vec<impl Into<String>>, )
Add many document/embedding pairs to the database. This is useful for adding embeddings that have already been generated.
victor.add_embeddings(vec![("Pepperoni pizza", vec![0.1, 0.2, 0.3])], vec!["Pizza Flavors"]).await;
Sourcepub async fn add_single_embedding(
&mut self,
content: impl Into<String>,
vector: Vec<f32>,
tags: Vec<impl Into<String>>,
)
pub async fn add_single_embedding( &mut self, content: impl Into<String>, vector: Vec<f32>, tags: Vec<impl Into<String>>, )
Add a single document/embedding pair to the database.
This is useful for adding embeddings that have already been generated.
When adding many documents, it is more efficient to use add_embeddings
.
victor.add_single_embedding("Pepperoni pizza", vec![0.1, 0.2, 0.3], vec!["Pizza Flavors"]).await;
Sourcepub async fn search(
&self,
content: impl Into<String>,
with_tags: Vec<impl Into<String>>,
top_n: u32,
) -> Vec<NearestNeighborsResult>
pub async fn search( &self, content: impl Into<String>, with_tags: Vec<impl Into<String>>, top_n: u32, ) -> Vec<NearestNeighborsResult>
Search the database for the nearest neighbors to a given document.
An embedding will be generated for the document being searched for.
This will return the top top_n
nearest neighbors.
victor.search("Pepperoni pizza", vec!["Pizza Flavors"], 10).await;
Auto Trait Implementations§
impl<D> Freeze for Victor<D>where
D: Freeze,
impl<D> RefUnwindSafe for Victor<D>where
D: RefUnwindSafe,
impl<D> Send for Victor<D>where
D: Send,
impl<D> Sync for Victor<D>where
D: Sync,
impl<D> Unpin for Victor<D>where
D: Unpin,
impl<D> UnwindSafe for Victor<D>where
D: UnwindSafe,
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.