Skip to main content

VectorIndexBuilder

Struct VectorIndexBuilder 

Source
pub struct VectorIndexBuilder<E: VectorExtractor> { /* private fields */ }
Expand description

Builder for constructing vector search indices.

Orchestrates the full pipeline: discover files → extract documents → batch embed → insert into backend.

§Example

use fabryk_vector::{VectorIndexBuilder, MockEmbeddingProvider, MockVectorExtractor};
use std::sync::Arc;

let provider = Arc::new(MockEmbeddingProvider::new(384));
let extractor = MockVectorExtractor;

let (backend, stats) = VectorIndexBuilder::new(extractor)
    .with_content_path("/data/concepts")
    .with_embedding_provider(provider)
    .build()
    .await?;

Implementations§

Source§

impl<E: VectorExtractor> VectorIndexBuilder<E>

Source

pub fn new(extractor: E) -> Self

Creates a new builder with the given extractor.

Source

pub fn with_content_path(self, path: impl Into<PathBuf>) -> Self

Sets the content directory path.

Source

pub fn with_embedding_provider( self, provider: Arc<dyn EmbeddingProvider>, ) -> Self

Sets the embedding provider.

Source

pub fn with_error_handling(self, handling: ErrorHandling) -> Self

Sets the error handling strategy.

Source

pub fn with_batch_size(self, size: usize) -> Self

Sets the batch size for embedding operations.

Source

pub fn with_cache_path(self, path: impl Into<PathBuf>) -> Self

Sets the cache file path for vector index persistence.

When set, the builder will:

  1. Check if the cache is fresh before building (by comparing content hashes)
  2. Load from cache on hit (fast path, avoids re-embedding)
  3. Save to cache after a successful build (for next time)
Source

pub fn skip_cache(self) -> Self

Forces a rebuild even if the cache is fresh.

Source

pub async fn build(self) -> Result<(SimpleVectorBackend, VectorIndexStats)>

Builds the vector index.

Returns a SimpleVectorBackend populated with embedded documents, plus build statistics.

§Phases
  1. Discover + Extract: Find content files, parse frontmatter, call extractor to produce VectorDocuments.
  2. Batch Embed + Insert: Embed documents in batches via the provider, then insert into the backend.
Source

pub async fn build_append( self, backend: &mut SimpleVectorBackend, ) -> Result<VectorIndexStats>

Append documents from a content path into an existing backend.

Unlike build(), this does not create a new backend — it adds embedded documents to the provided one. Use this to index multiple content directories (potentially with different extractors) into a single vector search backend.

§Example
// Build initial index from concept cards
let (mut backend, stats1) = VectorIndexBuilder::new(card_extractor)
    .with_content_path(&cards_path)
    .with_embedding_provider(provider.clone())
    .build()
    .await?;

// Append source documents with a different extractor
let stats2 = VectorIndexBuilder::new(source_extractor)
    .with_content_path(&sources_path)
    .with_embedding_provider(provider)
    .build_append(&mut backend)
    .await?;

Auto Trait Implementations§

§

impl<E> Freeze for VectorIndexBuilder<E>
where E: Freeze,

§

impl<E> !RefUnwindSafe for VectorIndexBuilder<E>

§

impl<E> Send for VectorIndexBuilder<E>

§

impl<E> Sync for VectorIndexBuilder<E>

§

impl<E> Unpin for VectorIndexBuilder<E>
where E: Unpin,

§

impl<E> UnsafeUnpin for VectorIndexBuilder<E>
where E: UnsafeUnpin,

§

impl<E> !UnwindSafe for VectorIndexBuilder<E>

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, 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, 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.