Database

Struct Database 

Source
pub struct Database { /* private fields */ }
Expand description

Main database handle

Implementations§

Source§

impl Database

Source

pub fn add_collection( &self, name: &str, path: &str, pattern: &str, provider_type: &str, provider_config: Option<&str>, ) -> Result<()>

Add a new collection

Source

pub fn remove_collection(&self, name: &str) -> Result<bool>

Remove a collection and its documents

Source

pub fn rename_collection(&self, old_name: &str, new_name: &str) -> Result<bool>

Rename a collection

Source

pub fn list_collections(&self) -> Result<Vec<CollectionInfo>>

List all collections with document counts

Source

pub fn get_collection(&self, name: &str) -> Result<Option<CollectionInfo>>

Get collection by name

Source

pub fn touch_collection(&self, name: &str) -> Result<()>

Update collection’s updated_at timestamp

Source

pub async fn reindex_collection(&self, name: &str) -> Result<usize>

Reindex a collection using the provider system

Source

pub async fn generate_or_fetch_metadata( &self, content_hash: &str, content: &str, context: MetadataContext, generator: Option<&dyn MetadataGenerator>, ) -> Result<Option<DocumentMetadata>>

Generate or fetch metadata from cache

Source

pub fn get_llm_cache_public(&self, key: &str) -> Result<Option<String>>

Get metadata from LLM cache (public API)

Source

pub async fn reindex_collection_with_metadata( &self, name: &str, generator: Option<&dyn MetadataGenerator>, ) -> Result<usize>

Reindex all documents in a collection with optional metadata generation

Source§

impl Database

Source

pub fn insert_content(&self, hash: &str, content: &str) -> Result<bool>

Insert content if not exists (content-addressable)

Source

pub fn get_content(&self, hash: &str) -> Result<Option<String>>

Get content by hash

Source

pub fn cleanup_orphaned_content(&self) -> Result<usize>

Delete orphaned content (not referenced by any active document)

Source§

impl Database

Source

pub fn add_context(&self, path: &str, context: &str) -> Result<()>

Add context for a path

Source

pub fn list_contexts(&self) -> Result<Vec<ContextInfo>>

List all contexts

Source

pub fn check_missing_contexts(&self) -> Result<Vec<String>>

Check for collections missing context

Source

pub fn remove_context(&self, path: &str) -> Result<bool>

Remove context for a path

Source

pub fn resolve_context(&self, virtual_path: &str) -> Result<Option<String>>

Get context for a document path (hierarchical resolution)

Source§

impl Database

Source

pub fn insert_doc(&self, doc: &DocumentInsert<'_>) -> Result<i64>

Insert new document using struct parameters

Source

pub fn insert_document( &self, collection: &str, path: &str, title: &str, hash: &str, created_at: &str, modified_at: &str, source_type: &str, source_uri: Option<&str>, ) -> Result<i64>

Insert new document (legacy method)

Source

pub fn update_document( &self, id: i64, title: &str, hash: &str, modified_at: &str, ) -> Result<()>

Update existing document (new content hash)

Source

pub fn update_document_title( &self, id: i64, title: &str, modified_at: &str, ) -> Result<()>

Update document title only

Source

pub fn deactivate_document(&self, collection: &str, path: &str) -> Result<bool>

Soft-delete document (set active = 0)

Source

pub fn find_active_document( &self, collection: &str, path: &str, ) -> Result<Option<Document>>

Find active document by collection and path

Source

pub fn get_active_document_paths(&self, collection: &str) -> Result<Vec<String>>

Get all active document paths in collection

Source

pub fn find_by_docid(&self, docid: &str) -> Result<Option<DocumentResult>>

Find document by docid (hash prefix)

Source

pub fn delete_inactive_documents(&self) -> Result<usize>

Hard delete inactive documents

Source

pub fn lookup_document( &self, query: &str, collections: &HashMap<String, PathBuf>, ) -> Result<Option<DocumentResult>>

Multi-lookup with fallback chain

Source

pub fn fuzzy_find_documents( &self, query: &str, limit: usize, ) -> Result<Vec<DocumentResult>>

Fuzzy matching using simple contains + length

Source

pub fn get_document(&self, query: &str) -> Result<String>

Get document content by query (docid, virtual path, etc)

Source

pub fn list_documents_by_prefix( &self, prefix: &str, ) -> Result<Vec<DocumentListItem>>

List documents by prefix

Source

pub fn get_documents_by_pattern( &self, pattern: &str, ) -> Result<Vec<DocumentContent>>

Get multiple documents by pattern

Source§

impl Database

Source

pub fn open(path: impl AsRef<Path>) -> Result<Self>

Open database at path, creating if necessary

Source

pub fn open_in_memory() -> Result<Self>

Open in-memory database (for testing)

Source

pub fn initialize(&self) -> Result<()>

Initialize database schema

Source

pub fn schema_version(&self) -> Result<Option<i32>>

Get current schema version

Source

pub fn migrate(&self) -> Result<()>

Run migrations to upgrade schema to current version

Source§

impl Database

Source

pub fn get_stats(&self) -> Result<DatabaseStats>

Get database statistics

Source

pub fn vacuum(&self) -> Result<()>

Vacuum the database

Source

pub fn cleanup_orphaned_vectors(&self) -> Result<usize>

Cleanup orphaned vectors

Source§

impl Database

Source

pub fn add_metadata(&self, docid: &str, metadata: &UserMetadata) -> Result<()>

Add or update user metadata for a document

§Arguments
  • docid - Document ID (short hash like “abc123” or full “#abc123”)
  • metadata - User metadata to add/update
§Example
use agentroot_core::{Database, MetadataBuilder};

let db = Database::open("index.sqlite")?;
let metadata = MetadataBuilder::new()
    .text("author", "John Doe")
    .tags("labels", vec!["rust", "tutorial"])
    .build();

db.add_metadata("#abc123", &metadata)?;
Source

pub fn get_metadata(&self, docid: &str) -> Result<Option<UserMetadata>>

Get user metadata for a document

Source

pub fn remove_metadata_fields( &self, docid: &str, fields: &[String], ) -> Result<()>

Remove specific metadata fields from a document

Source

pub fn clear_metadata(&self, docid: &str) -> Result<()>

Clear all user metadata from a document

Source

pub fn find_by_metadata( &self, filter: &MetadataFilter, limit: usize, ) -> Result<Vec<String>>

Find documents matching metadata filter

Source

pub fn list_with_metadata( &self, limit: usize, ) -> Result<Vec<(String, UserMetadata)>>

List all documents with user metadata

Source§

impl Database

Source

pub fn ensure_vec_table(&self, _dimensions: usize) -> Result<()>

Ensure vector storage table exists

Source

pub fn insert_embedding( &self, hash: &str, seq: u32, pos: usize, model: &str, embedding: &[f32], ) -> Result<()>

Insert embedding for a document chunk

Source

pub fn has_vector_index(&self) -> bool

Check if vector index exists and has data

Source

pub fn get_all_embeddings(&self) -> Result<Vec<(String, Vec<f32>)>>

Get all embeddings for similarity search

Source

pub fn get_embeddings_for_collection( &self, collection: &str, ) -> Result<Vec<(String, Vec<f32>)>>

Get embeddings for specific hashes (for filtered search)

Source

pub fn get_hashes_needing_embedding(&self) -> Result<Vec<(String, String)>>

Get hashes that need embedding

Source

pub fn count_hashes_needing_embedding(&self) -> Result<usize>

Count hashes needing embedding

Source

pub fn delete_embeddings(&self, hash: &str) -> Result<usize>

Delete embeddings for a hash

Source

pub fn get_all_hashes_for_embedding(&self) -> Result<Vec<(String, String)>>

Get all hashes for embedding (for force re-embedding)

Source

pub fn check_model_compatibility( &self, model: &str, expected_dims: usize, ) -> Result<bool>

Check if model dimensions are compatible with expected dimensions

Source

pub fn get_cached_embedding( &self, chunk_hash: &str, model: &str, expected_dims: usize, ) -> Result<CacheLookupResult>

Look up a cached embedding by chunk hash (performs dimension check)

Source

pub fn get_cached_embedding_fast( &self, chunk_hash: &str, model: &str, ) -> Result<CacheLookupResult>

Look up a cached embedding by chunk hash (skips dimension check - caller must verify compatibility)

Source

pub fn insert_chunk_embedding( &self, doc_hash: &str, seq: u32, pos: usize, chunk_hash: &str, model: &str, embedding: &[f32], ) -> Result<()>

Insert a chunk embedding with cache support

Source

pub fn get_chunk_hashes_for_doc( &self, doc_hash: &str, ) -> Result<Vec<(u32, String)>>

Get chunk hashes for a document

Source

pub fn cleanup_orphaned_chunk_embeddings(&self) -> Result<usize>

Clean up orphaned chunk embeddings (not referenced by any document)

Source

pub fn register_model(&self, model: &str, dimensions: usize) -> Result<()>

Register model with its dimensions

Source

pub fn get_model_dimensions(&self, model: &str) -> Result<Option<usize>>

Get stored model dimensions

Source

pub fn count_cached_embeddings(&self, model: &str) -> Result<usize>

Count cached chunk embeddings

Source§

impl Database

Source

pub fn default_path() -> PathBuf

Get the default database path

Source§

impl Database

Source

pub fn get_all_content(&self) -> Result<Vec<(String, String)>>

Get all content hashes and content

Source

pub fn get_all_content_with_paths( &self, ) -> Result<Vec<(String, String, Option<String>)>>

Get all content with file paths

Source

pub fn get_content_needing_embedding_with_paths( &self, ) -> Result<Vec<(String, String, Option<String>)>>

Get content needing embedding with file paths

Source

pub fn get_document_title_by_hash(&self, hash: &str) -> Result<Option<String>>

Get document title by hash

Source§

impl Database

Source

pub fn search_fts( &self, query: &str, options: &SearchOptions, ) -> Result<Vec<SearchResult>>

Perform BM25 full-text search

Source§

impl Database

Source

pub fn search_vec_sync( &self, _query: &str, options: &SearchOptions, ) -> Result<Vec<SearchResult>>

Synchronous vector search (placeholder for CLI - needs runtime)

Source

pub fn search_hybrid_sync( &self, query: &str, options: &SearchOptions, ) -> Result<Vec<SearchResult>>

Synchronous hybrid search (placeholder for CLI - needs runtime)

Source§

impl Database

Source

pub async fn search_vec( &self, query: &str, embedder: &dyn Embedder, options: &SearchOptions, ) -> Result<Vec<SearchResult>>

Perform vector similarity search

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more