pub struct Engine { /* private fields */ }Expand description
The main Engine client.
Provides high-level operations for document indexing and retrieval. Uses interior mutability to allow sharing across async tasks.
§Cloning
Cloning is cheap - it only increments reference counts (Arc). All clones
share the same underlying resources.
§Thread Safety
The client is Clone + Send + Sync and can be safely shared across threads.
Implementations§
Source§impl Engine
impl Engine
Sourcepub fn builder() -> EngineBuilder
pub fn builder() -> EngineBuilder
Create a builder for custom configuration.
Sourcepub async fn index(&self, ctx: IndexContext) -> Result<String>
pub async fn index(&self, ctx: IndexContext) -> Result<String>
Index a document.
This is the main entry point for indexing documents. The IndexContext
parameter specifies the source (file path, content string, or bytes)
and indexing options.
§Arguments
ctx- The index context containing source and options
§Returns
A unique document ID string.
§Errors
Returns an error if:
- The file does not exist (for path sources)
- The file format is not supported
- The pipeline execution fails
§Example
use vectorless::client::{Engine, EngineBuilder, IndexContext, IndexMode};
use vectorless::parser::DocumentFormat;
let engine = EngineBuilder::new()
.with_workspace("./data")
.build()
.await?;
// From file
let id1 = engine.index(IndexContext::from_path("./doc.md")).await?;
// From content
let html = "<html><body><h1>Title</h1></body></html>";
let id2 = engine.index(
IndexContext::from_content(html, DocumentFormat::Html)
.with_name("webpage")
).await?;
// From bytes with force mode
let pdf_bytes = std::fs::read("./doc.pdf")?;
let id3 = engine.index(
IndexContext::from_bytes(pdf_bytes, DocumentFormat::Pdf)
.with_mode(IndexMode::Force)
).await?;Sourcepub async fn query(&self, doc_id: &str, question: &str) -> Result<QueryResult>
pub async fn query(&self, doc_id: &str, question: &str) -> Result<QueryResult>
Query a document.
Uses the adaptive retriever to find relevant content.
§Errors
Returns an error if:
- No workspace is configured
- The document is not found
- The retrieval fails
Sourcepub async fn query_with_context(
&self,
doc_id: &str,
question: &str,
ctx: &ClientContext,
) -> Result<QueryResult>
pub async fn query_with_context( &self, doc_id: &str, question: &str, ctx: &ClientContext, ) -> Result<QueryResult>
Query a document with context.
Allows request-specific configuration overrides.
Sourcepub async fn session(&self) -> Session
pub async fn session(&self) -> Session
Create a session for multi-document operations.
Sessions provide:
- Automatic caching of document trees
- Cross-document queries
- Session statistics
Sourcepub async fn list_documents(&self) -> Result<Vec<DocumentInfo>>
pub async fn list_documents(&self) -> Result<Vec<DocumentInfo>>
Sourcepub async fn get_structure(&self, doc_id: &str) -> Result<DocumentTree>
pub async fn get_structure(&self, doc_id: &str) -> Result<DocumentTree>
Get document structure (tree).
§Errors
Returns an error if:
- No workspace is configured
- The document is not found
Sourcepub async fn get_page_content(
&self,
doc_id: &str,
pages: &str,
) -> Result<String>
pub async fn get_page_content( &self, doc_id: &str, pages: &str, ) -> Result<String>
Get page content for PDFs.
§Errors
Returns an error if:
- No workspace is configured
- The document is not found
- No page content is available
Sourcepub async fn load(&self, doc_id: &str) -> Result<bool>
pub async fn load(&self, doc_id: &str) -> Result<bool>
Load a document from the workspace into cache.
This preloads the document into the LRU cache for faster access.
§Errors
Returns an error if no workspace is configured.
Sourcepub async fn exists(&self, doc_id: &str) -> Result<bool>
pub async fn exists(&self, doc_id: &str) -> Result<bool>
Check if a document exists in the workspace.
§Errors
Returns an error if no workspace is configured.
Sourcepub async fn get_metadata(&self, doc_id: &str) -> Result<Option<DocumentInfo>>
pub async fn get_metadata(&self, doc_id: &str) -> Result<Option<DocumentInfo>>
Sourcepub async fn batch_remove(&self, doc_ids: &[&str]) -> Result<usize>
pub async fn batch_remove(&self, doc_ids: &[&str]) -> Result<usize>
Remove multiple documents from the workspace.
Returns the number of documents successfully removed.
§Errors
Returns an error if no workspace is configured.
Sourcepub async fn clear(&self) -> Result<usize>
pub async fn clear(&self) -> Result<usize>
Remove all documents from the workspace.
Returns the number of documents removed.
§Errors
Returns an error if no workspace is configured.
Sourcepub fn indexer(&self) -> &IndexerClient
pub fn indexer(&self) -> &IndexerClient
Get the indexer client.
Sourcepub fn retriever(&self) -> &RetrieverClient
pub fn retriever(&self) -> &RetrieverClient
Get the retriever client.
Sourcepub fn workspace(&self) -> Option<&WorkspaceClient>
pub fn workspace(&self) -> Option<&WorkspaceClient>
Get the workspace client.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Engine
impl !RefUnwindSafe for Engine
impl Send for Engine
impl Sync for Engine
impl Unpin for Engine
impl UnsafeUnpin for Engine
impl !UnwindSafe for Engine
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 more