Skip to main content

kmp_memory_api/
memory_recall_api.rs

1use std::future::Future;
2
3use crate::{ApiCapabilities, ApiError, MemoryAskRequest, MemoryRecallView, MemoryWakeRequest};
4
5/// What an embedding product may ask of the kernel.
6///
7/// Reads only. Ingestion, projection and export have their own commands,
8/// idempotency and provenance inside the kernel; a consumer reaches them
9/// through the kernel's own surfaces. What this trait promises is the part a
10/// consumer needs to *recall* — and to keep working, with a stub, when the
11/// kernel is absent.
12///
13/// Methods return named `Send` futures rather than using `async fn`, so the
14/// trait can be consumed generically from multi-threaded runtimes. It is not
15/// object-safe; consumers hold an implementation by generic parameter, which
16/// is also what lets a stub replace the kernel in their tests.
17pub trait MemoryRecallApi: Send + Sync {
18    /// What this implementation is and what it can do. Checked by consumers at
19    /// startup, before anything is at stake.
20    fn capabilities(&self) -> ApiCapabilities;
21
22    /// Recall the bounded context of one about.
23    fn wake(
24        &self,
25        request: MemoryWakeRequest,
26    ) -> impl Future<Output = Result<MemoryRecallView, ApiError>> + Send;
27
28    /// Ask one question of the memory, under an explicit answer policy.
29    fn ask(
30        &self,
31        request: MemoryAskRequest,
32    ) -> impl Future<Output = Result<MemoryRecallView, ApiError>> + Send;
33}