VectorStoreManager

Struct VectorStoreManager 

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

VectorStore のシンプルなインメモリ実装。

Implementations§

Source§

impl VectorStoreManager

Source

pub fn new(config: VectorStoreConfig) -> Self

新しい VectorStoreManager を生成。

Source

pub fn segments(&self) -> &[VectorSegment]

現在保持しているセグメント一覧(読み取り専用)を返す。

§注意(Disk モード復元時の前提)
  • VectorStoreManager は「セグメントの順序」を row_id の割当てに利用します(検索時に row_offset を積み上げる)。
  • from_segments で復元する場合は、永続化時と同じ順序(通常は古い→新しい)で segments を渡してください。
Source

pub fn config(&self) -> &VectorStoreConfig

設定を返す(Disk モードの復元用)。

§注意(Disk モード復元時の前提)
  • segments 内の各セグメントは、この config と整合している必要があります(例: dimension/metric)。
Source

pub fn next_segment_id(&self) -> u64

次に割り当てられるセグメントIDを返す(永続化用)。

§注意(Disk モード復元時の前提)
  • from_segments に渡す next_segment_id は、通常 max(segment_id) + 1 以上である必要があります。
Source

pub fn from_segments( config: VectorStoreConfig, segments: Vec<VectorSegment>, next_segment_id: u64, ) -> Self

永続化済みセグメントから VectorStoreManager を復元する(Disk モード向け)。

§注意(呼び出し側が満たすべき前提)
  • segments は永続化時と同じ順序(通常は古い→新しい)で渡すこと。
  • segments は重複しない segment_id を持つこと。
  • configsegments の整合(dimension/metric など)を保つこと。
  • next_segment_idmax(segment_id) + 1 以上であること(将来の追加/コンパクションで重複IDを避けるため)。
Source

pub async fn append_batch( &mut self, keys: &[i64], vectors: &[Vec<f32>], ) -> Result<AppendResult>

ベクトルバッチを追加する。

§Errors
  • DimensionMismatch: 入力ベクトルの次元が設定と異なる場合
  • InvalidVector: NaN/Inf を含む場合
§Examples
use alopex_core::vector::{VectorStoreManager, VectorStoreConfig};
let mut mgr = VectorStoreManager::new(VectorStoreConfig { dimension: 2, ..Default::default() });
let keys = vec![1, 2];
let vecs = vec![vec![1.0, 0.0], vec![0.0, 1.0]];
mgr.append_batch(&keys, &vecs).await?;
Source

pub fn segments_needing_compaction(&self) -> Vec<u64>

コンパクション対象セグメントを取得する。

deletion_ratiocompaction_threshold 以上かつ > 0 のセグメントIDを返す。 threshold >= 1.0 の場合は常に空。

§Examples
assert!(mgr.segments_needing_compaction().is_empty()); // no deletions yet
// Mark one row deleted -> deletion_ratio = 0.5, meets threshold
mgr.segments[0].deleted.set(0, true);
mgr.segments[0].recompute_deletion_stats();
assert_eq!(mgr.segments_needing_compaction(), vec![mgr.segments[0].segment_id]);
Source

pub async fn delete_batch(&mut self, keys: &[i64]) -> Result<DeleteResult>

指定キーのベクトルを論理削除する(in-memory)。

§Errors
  • セグメントのデコードに失敗した場合 InvalidFormat
§Examples
let res = futures::executor::block_on(mgr.delete_batch(&[1])).unwrap();
assert_eq!(res.vectors_deleted, 1);
Source

pub async fn compact_segment( &mut self, segment_id: u64, ) -> Result<CompactionResult>

セグメントをコンパクションして新セグメントに置換する。

削除済み行を物理的に取り除き、新セグメントを構築する(全削除時はセグメントを削除)。

§Errors
  • Error::NotFound 指定IDが存在しない場合
  • InvalidFormat セグメントのデコード/再構成に失敗した場合
§Examples
let seg_id = mgr.segments[0].segment_id;
let res = futures::executor::block_on(mgr.compact_segment(seg_id)).unwrap();
assert!(res.new_segment_id.is_some());
Source

pub fn search( &self, params: VectorSearchParams, ) -> Result<Vec<VectorSearchResult>>

ベクトル検索。

§Errors
  • DimensionMismatch: クエリ次元が設定と異なる場合。
  • InvalidVector: クエリに NaN/Inf が含まれる場合。
Source

pub fn search_with_stats( &self, params: VectorSearchParams, ) -> Result<(Vec<VectorSearchResult>, SearchStats)>

統計付き検索。

search と同じ結果に加え、走査/プルーニング件数を返す。

Trait Implementations§

Source§

impl Debug for VectorStoreManager

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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, 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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
Source§

impl<T> MaybeSend for T
where T: Send,