Rust API reference · Kjarni 0.2.8
kjarni::indexer
IndexInfo
pub struct IndexInfo
Information about an existing index
Fields
pub path: String,: Path to the indexpub document_count: usize,: Number of documentspub segment_count: usize,: Number of segmentspub dimension: usize,: Embedding dimensionpub size_bytes: u64,: Total size in bytespub embedding_model: Option<String>,: Embedding model used (if recorded)pub created_at: Option<u64>,: When the index was created
IndexStats
pub struct IndexStats
Statistics returned after indexing
Fields
pub documents_indexed: usize,: Number of documents indexedpub chunks_created: usize,: Number of chunks createdpub dimension: usize,: Embedding dimension usedpub size_bytes: u64,: Total index size in bytespub files_processed: usize,: Number of files processedpub files_skipped: usize,: Number of files skipped (errors, unsupported)pub elapsed_ms: u64,: Time taken in milliseconds
Indexer
pub struct Indexer
builder
pub fn builder(model: &str) -> IndexerBuilder
new
pub async fn new(model: &str) -> IndexerResult<Self>
Create with default settings
info
pub fn info(index_path: &str) -> IndexerResult<IndexInfo>
Get index info (static - doesn't need embedder)
delete
pub fn delete(index_path: &str) -> IndexerResult<()>
Delete an index
create
pub async fn create(&self, index_path: &str, inputs: &[&str]) -> IndexerResult<IndexStats>
Create a new index from files/directories
create_with_options
pub async fn create_with_options(&self, index_path: &str, inputs: &[&str], force: bool) -> IndexerResult<IndexStats>
Create with force overwrite option
create_with_callback
pub async fn create_with_callback<F, C>(&self, index_path: &str, inputs: &[&str], force: bool, on_progress: Option<F>, is_cancelled: Option<C>) -> IndexerResult<IndexStats> where F: Fn(ProgressStage, usize, usize, Option<&str>), C: Fn() -> bool,
Create with callback and cancellation support (for FFI)
add
pub async fn add(&self, index_path: &str, inputs: &[&str]) -> IndexerResult<usize>
Add documents to existing index
add_with_callback
pub async fn add_with_callback<F, C>(&self, index_path: &str, inputs: &[&str], on_progress: Option<F>, is_cancelled: Option<C>) -> IndexerResult<usize> where F: Fn(ProgressStage, usize, usize, Option<&str>), C: Fn() -> bool,
callback support (for FFI)
model_name
pub fn model_name(&self) -> &str
dimension
pub fn dimension(&self) -> usize
chunk_size
pub fn chunk_size(&self) -> usize
batch_size
pub fn batch_size(&self) -> usize
is_quiet
pub fn is_quiet(&self) -> bool
has_progress_callback
pub fn has_progress_callback(&self) -> bool
IndexerBuilder
pub struct IndexerBuilder
new
pub fn new(model: &str) -> Self
cpu
pub fn cpu(mut self) -> Self
gpu
pub fn gpu(mut self) -> Self
device
pub fn device(mut self, d: &str) -> Self
cache_dir
pub fn cache_dir(mut self, dir: impl Into<PathBuf>) -> Self
chunk_size
pub fn chunk_size(mut self, size: usize) -> Self
chunk_overlap
pub fn chunk_overlap(mut self, overlap: usize) -> Self
extension
pub fn extension(mut self, ext: &str) -> Self
extensions
pub fn extensions(mut self, exts: &[&str]) -> Self
exclude
pub fn exclude(mut self, pattern: &str) -> Self
recursive
pub fn recursive(mut self, r: bool) -> Self
include_hidden
pub fn include_hidden(mut self, h: bool) -> Self
max_file_size
pub fn max_file_size(mut self, bytes: usize) -> Self
max_docs_per_segment
pub fn max_docs_per_segment(mut self, n: usize) -> Self
batch_size
pub fn batch_size(mut self, n: usize) -> Self
quiet
pub fn quiet(mut self, q: bool) -> Self
on_progress
pub fn on_progress<F>(mut self, callback: F) -> Self where F: Fn(&Progress, Option<&str>) + Send + Sync + 'static,
cancel_token
pub fn cancel_token(mut self, token: watch::Receiver<bool>) -> Self
build
pub async fn build(self) -> IndexerResult<Indexer>
IndexerError
pub enum IndexerError
Error types for indexing operations
Variants
NoInputs,PathNotFound(String),IndexExists(String),IndexNotFound(String),EmbedderError(#[from] crate::embedder::EmbedderError),IndexingFailed(#[from] anyhow::Error),DimensionMismatchCancelled,
IndexerResult
pub type IndexerResult<T> = Result<T, IndexerError>
Kjarni runs the same engine on every platform: