Skip to main content

KnowledgeBase

Struct KnowledgeBase 

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

Clone shares one process-local engine. Close invalidates all its handles.

Implementations§

Source§

impl KnowledgeBase

Source

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

Source

pub fn directory(&self) -> &Path

Source

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

Source

pub fn memories(&self) -> MemoryStore

Source

pub fn graph(&self) -> GraphStore

Source

pub fn notes(&self) -> NoteStore

Source

pub fn embeddings(&self) -> EmbeddingStore

Source

pub fn update_index(&self) -> Result<HealthReport>

追平待索引队列:把写入累积的待办一趟索引完、只提交一次。 写入不再就地索引,使用方(尤其批量导入)在合适时机调用本方法即可; 期间读取走 sync_index_if_behind 自愈兜底。

Source

pub fn register_event_sink<F: Fn(&LogEvent) + Send + Sync + 'static>( &self, sink: F, )

注册事件接收回调。库在检索线程里同步调用它,所以回调必须非阻塞—— 在里面做同步 IO 或网络上报,会把检索拖住,和慢的重排回调一样。 回调抛错只丢这一条事件,不影响检索。不注册就完全不产出事件。

Source

pub fn unregister_event_sink(&self) -> bool

注销事件接收回调,返回此前是否有注册。

Source

pub fn event_sink_registered(&self) -> bool

当前是否注册了事件接收回调。

Source

pub fn rebuild_indexes(&self) -> Result<HealthReport>

Source

pub fn rebuild_progress(&self) -> Result<RebuildProgressReport>

读一次全文索引重建的进度快照。纯原子读、不碰写锁,可在重建进行时从另一线程轮询。

Source

pub fn health(&self) -> Result<HealthReport>

Source

pub fn backup(&self, target: impl AsRef<Path>) -> Result<()>

Consistent SQLite snapshot, including embeddings. Refuses to overwrite a file.

Source

pub fn restore( snapshot: impl AsRef<Path>, directory: impl AsRef<Path>, ) -> Result<Self>

Restores to a new directory; search indexes are rebuilt from the snapshot.

Source§

impl KnowledgeBase

Source

pub fn register_reranker<F: Reranker + 'static>( &self, reranker: F, ) -> Result<()>

注册重排回调。调用前按声明的定长约束强制截断,宿主不自己重排。

Source

pub fn register_reranker_with<F: Reranker + 'static>( &self, reranker: F, options: RerankerOptions, ) -> Result<()>

Source

pub fn unregister_reranker(&self) -> bool

Source

pub fn reranker_registered(&self) -> bool

Source

pub fn search(&self, request: &SearchRequest) -> Result<SearchResult>

Source

pub fn search_with_context( &self, request: &SearchRequest, limit: usize, ) -> Result<Vec<ContextualHit>>

先按 request 检索,再给每条命中挂上它在图上所在实体的邻域(实体 + 关系)。

「挂载」靠标签文本:命中的记录所带的 tag,与同一 namespace / scope 内某实体的名字或别名 文本相同,就认为该记录挂在这个实体上(两者都落在 strings 表,同一套归一化)。 limit 是每个实体邻域的规模上限。命中记录若没有命中任何实体,返回空邻域。

Source§

impl KnowledgeBase

Source

pub fn search_preset(&self, request: &PresetRequest) -> Result<PresetResult>

按预设检索。三个字段各自独立排序,互不挤占。

Trait Implementations§

Source§

impl Clone for KnowledgeBase

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Sync + Send>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Fruit for T
where T: Send + Downcast,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

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

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.