pub struct Collection<T: Doc> { /* private fields */ }Expand description
A typed document collection stored in SpireDB.
Documents are stored as JSON in a SpireDB table, with vector embeddings in a separate vector index for semantic search.
Implementations§
Source§impl<T: Doc> Collection<T>
impl<T: Doc> Collection<T>
Sourcepub fn table_name(&self) -> String
pub fn table_name(&self) -> String
The internal table name used in SpireDB.
Sourcepub fn index_name(&self) -> String
pub fn index_name(&self) -> String
The internal vector index name used in SpireDB.
Sourcepub async fn ensure(&self) -> Result<()>
pub async fn ensure(&self) -> Result<()>
Ensure the backing table and vector index exist.
Creates them if they don’t exist. Safe to call multiple times.
Sourcepub async fn insert(&self, doc: &T) -> Result<String>
pub async fn insert(&self, doc: &T) -> Result<String>
Insert a document. Automatically generates embedding if embed_text() is non-empty.
Sourcepub async fn insert_many(&self, docs: &[T]) -> Result<Vec<String>>
pub async fn insert_many(&self, docs: &[T]) -> Result<Vec<String>>
Insert multiple documents in a batch.
Sourcepub async fn get(&self, id: &str) -> Result<Option<T>>
pub async fn get(&self, id: &str) -> Result<Option<T>>
Get a document by ID.
Checks the in-memory cache first, then falls back to a GetPayload RPC to retrieve the payload from SpireDB.
Sourcepub async fn all(&self) -> Result<Vec<T>>
pub async fn all(&self) -> Result<Vec<T>>
List all documents in the collection.
Performs a broad vector search to retrieve all stored documents.
Use filter for SQL-based filtering once implemented.
Sourcepub fn similar_vec(&self, vec: &[f32]) -> Search<T>
pub fn similar_vec(&self, vec: &[f32]) -> Search<T>
Find documents similar to a raw vector.
Sourcepub fn filter(&self, sql_where: &str) -> Filter<T>
pub fn filter(&self, sql_where: &str) -> Filter<T>
Filter documents using SQL WHERE clause (no vector search).
Sourcepub async fn watch(&self) -> Result<WatchStream<T>>
pub async fn watch(&self) -> Result<WatchStream<T>>
Watch for changes to this collection via CDC.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Collection<T>
impl<T> !RefUnwindSafe for Collection<T>
impl<T> Send for Collection<T>
impl<T> Sync for Collection<T>
impl<T> Unpin for Collection<T>where
T: Unpin,
impl<T> UnsafeUnpin for Collection<T>
impl<T> !UnwindSafe for Collection<T>
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request