Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions api/src/null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,29 @@ impl MemoryDocuments for NullMemoryProvider {
unsupported(Capability::Documents)
}

async fn list_documents(
&self,
_namespace: Option<&str>,
) -> Result<serde_json::Value, MemoryError> {
unsupported(Capability::Documents)
}

async fn list_namespaces(&self) -> Result<Vec<String>, MemoryError> {
unsupported(Capability::Documents)
}

async fn delete_document(
&self,
_namespace: &str,
_document_id: &str,
) -> Result<serde_json::Value, MemoryError> {
unsupported(Capability::Documents)
}

async fn clear_namespace(&self, _namespace: &str) -> Result<(), MemoryError> {
unsupported(Capability::Documents)
}

async fn query_documents(
&self,
_namespace: &str,
Expand Down Expand Up @@ -326,6 +349,10 @@ impl MemoryGraph for NullMemoryProvider {
unsupported(Capability::Graph)
}

async fn kv_delete(&self, _namespace: Option<&str>, _key: &str) -> Result<bool, MemoryError> {
unsupported(Capability::Graph)
}

async fn kv_list(
&self,
_namespace: Option<&str>,
Expand Down
36 changes: 36 additions & 0 deletions api/src/provider/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,42 @@ pub trait MemoryDocuments: Send + Sync {
key: &str,
) -> Result<Option<StoredMemoryDocument>, MemoryError>;

/// List document summaries, optionally restricted to one namespace.
///
/// # Errors
///
/// Backend failures only.
async fn list_documents(
&self,
namespace: Option<&str>,
) -> Result<serde_json::Value, MemoryError>;

/// List every namespace containing documents.
///
/// # Errors
///
/// Backend failures only.
async fn list_namespaces(&self) -> Result<Vec<String>, MemoryError>;

/// Delete a document by its driver-assigned id.
///
/// # Errors
///
/// Backend failures only; a missing document is reported in the returned
/// outcome rather than as an error.
async fn delete_document(
&self,
namespace: &str,
document_id: &str,
) -> Result<serde_json::Value, MemoryError>;

/// Delete all data belonging to one namespace.
///
/// # Errors
///
/// Backend failures only.
async fn clear_namespace(&self, namespace: &str) -> Result<(), MemoryError>;

/// Run a ranked query over one namespace's documents.
///
/// Returns both the ranked hits and the driver's rendered context text, so
Expand Down
7 changes: 7 additions & 0 deletions api/src/provider/knowledge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ pub trait MemoryGraph: Send + Sync {
value: serde_json::Value,
) -> Result<(), MemoryError>;

/// Delete one key/value record, reporting whether it existed.
///
/// # Errors
///
/// Backend failures only.
async fn kv_delete(&self, namespace: Option<&str>, key: &str) -> Result<bool, MemoryError>;

/// List key/value records, optionally restricted to a key prefix.
///
/// # Errors
Expand Down
2 changes: 1 addition & 1 deletion api/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
/// added to a family a driver may already advertise** (negotiation is
/// family-granular, not method-granular, so that case cannot be made minor-safe
/// by negotiation alone).
pub const CONTRACT_VERSION: (u16, u16) = (1, 0);
pub const CONTRACT_VERSION: (u16, u16) = (2, 0);

/// Whether a driver speaking `remote` can be bound against this build.
///
Expand Down
2 changes: 1 addition & 1 deletion api/src/version_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use super::*;

#[test]
fn contract_version_starts_at_one_zero() {
assert_eq!(CONTRACT_VERSION, (1, 0));
assert_eq!(CONTRACT_VERSION, (2, 0));
}

#[test]
Expand Down
5 changes: 5 additions & 0 deletions crates/tinymemory-module/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ mod exports {
"IngestChat",
"PutDocument",
"GetDocument",
"ListDocuments",
"ListNamespaces",
"DeleteDocument",
"ClearNamespace",
"QueryDocuments",
"Append",
"QuerySource",
Expand All @@ -239,6 +243,7 @@ mod exports {
"TouchEntities",
"KvGet",
"KvPut",
"KvDelete",
"KvList",
"Relations",
"PutRelation",
Expand Down
42 changes: 42 additions & 0 deletions crates/tinymemory-module/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,41 @@ impl MemoryDocuments for ModuleMemoryProvider {
.map(|document| Self::cross(&document, "convert stored document"))
.transpose()
}

async fn list_documents(
&self,
namespace: Option<&str>,
) -> Result<serde_json::Value, MemoryError> {
self.client
.list_documents(namespace)
.await
.map_err(|error| Self::other("list_documents", error))
}

async fn list_namespaces(&self) -> Result<Vec<String>, MemoryError> {
self.client
.list_namespaces()
.await
.map_err(|error| Self::other("list_namespaces", error))
}

async fn delete_document(
&self,
namespace: &str,
document_id: &str,
) -> Result<serde_json::Value, MemoryError> {
self.client
.delete_document(namespace, document_id)
.await
.map_err(|error| Self::other("delete_document", error))
}

async fn clear_namespace(&self, namespace: &str) -> Result<(), MemoryError> {
self.client
.clear_namespace(namespace)
.await
.map_err(|error| Self::other("clear_namespace", error))
}
async fn query_documents(
&self,
namespace: &str,
Expand Down Expand Up @@ -472,6 +507,13 @@ impl MemoryGraph for ModuleMemoryProvider {
.await
.map_err(|error| Self::other("kv_put", error))
}

async fn kv_delete(&self, namespace: Option<&str>, key: &str) -> Result<bool, MemoryError> {
self.client
.kv_delete(namespace, key)
.await
.map_err(|error| Self::other("kv_delete", error))
}
async fn kv_list(
&self,
namespace: Option<&str>,
Expand Down
39 changes: 39 additions & 0 deletions crates/tinymemory-module/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,38 @@ impl MemoryService {
.map_err(|error| into_bus_error(&error))
}

async fn list_documents(&self, namespace: Option<String>) -> BusResult<serde_json::Value> {
require_family!(self, as_documents, Capability::Documents)
.list_documents(namespace.as_deref())
.await
.map_err(|error| into_bus_error(&error))
}

async fn list_namespaces(&self) -> BusResult<Vec<String>> {
require_family!(self, as_documents, Capability::Documents)
.list_namespaces()
.await
.map_err(|error| into_bus_error(&error))
}

async fn delete_document(
&self,
namespace: String,
document_id: String,
) -> BusResult<serde_json::Value> {
require_family!(self, as_documents, Capability::Documents)
.delete_document(&namespace, &document_id)
.await
.map_err(|error| into_bus_error(&error))
}

async fn clear_namespace(&self, namespace: String) -> BusResult<()> {
require_family!(self, as_documents, Capability::Documents)
.clear_namespace(&namespace)
.await
.map_err(|error| into_bus_error(&error))
}

async fn query_documents(
&self,
namespace: String,
Expand Down Expand Up @@ -426,6 +458,13 @@ impl MemoryService {
.map_err(|error| into_bus_error(&error))
}

async fn kv_delete(&self, namespace: Option<String>, key: String) -> BusResult<bool> {
require_family!(self, as_graph, Capability::Graph)
.kv_delete(namespace.as_deref(), &key)
.await
.map_err(|error| into_bus_error(&error))
}

async fn kv_list(
&self,
namespace: Option<String>,
Expand Down
5 changes: 5 additions & 0 deletions crates/tinymemory-module/tests/module_e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,10 @@ const EXPECTED_METHODS: &[&str] = &[
"IngestChat",
"PutDocument",
"GetDocument",
"ListDocuments",
"ListNamespaces",
"DeleteDocument",
"ClearNamespace",
"QueryDocuments",
"Append",
"QuerySource",
Expand All @@ -507,6 +511,7 @@ const EXPECTED_METHODS: &[&str] = &[
"TouchEntities",
"KvGet",
"KvPut",
"KvDelete",
"KvList",
"Relations",
"PutRelation",
Expand Down