BailianLongTermMemory
public class BailianLongTermMemory implements LongTermMemory, AutoCloseable
io/agentscope/core/memory/bailian/BailianLongTermMemory.java:77–491Bailian Long Term 记忆,在多次调用之间保存和恢复会话与记忆数据。位于 io.agentscope.core.memory.bailian 包,实现 LongTermMemory、AutoCloseable。核心成员包括 record、retrieve、builder、close。
Long-term memory implementation using Bailian Long Term Memory service.
This implementation integrates with Alibaba Cloud Bailian's memory service, which provides persistent, searchable memory storage using semantic similarity and LLM-powered memory extraction.
Key Features:
-
Semantic memory search using vector embeddings
-
LLM-powered memory extraction and inference
-
Multi-tenant memory isolation (user_id, memory_library_id)
-
Reactive, non-blocking operations
Usage Example:
`// Using try-with-resources (recommended)
try (BailianLongTermMemory memory = BailianLongTermMemory.builder()
.apiKey(System.getenv("DASHSCOPE_API_KEY"))
.userId("user_001")
.memoryLibraryId("memory_library_123")
.projectId(project_id_123)
.profileSchema(profile_schema_123)
.build()) {
// Record messages
Msg msg = Msg.builder()
.role(MsgRole.USER)
.content("Remind me to drink water at 9 a.m. every day")
.build();
memory.record(List.of(msg)).block();
// Retrieve memories
Msg query = Msg.builder()
.role(MsgRole.USER)
.content("What reminder do I have?")
.build();
String memories = memory.retrieve(query).block();
}
`
嵌套类摘要Nested Class Summary
| 类Class | 类型Kind | 说明Description |
|---|---|---|
Builder | 类class | `BailianLongTermMemory`的构建器。 Builder for `BailianLongTermMemory`. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public Mono<Void> record(List<Msg> msgs) | 设置记录。 Records messages to long-term memory. |
public Mono<String> retrieve(Msg msg) | 按查询检索相关文档。 Retrieves relevant memories based on the input message. |
public static Builder builder()static | 创建新的构建器用于`BailianLongTermMemory`。 Creates a new builder for `BailianLongTermMemory`. |
public void close() | 关闭连接并释放相关资源。 Closes the BailianMemoryClient and releases resources. |
方法详情Method Detail
record
public Mono<Void> record(List<Msg> msgs)
设置记录。
Records messages to long-term memory.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
msgs | List<Msg> | 列出的消息到。list of messages to record |
Mono<Void>io/agentscope/core/memory/bailian/BailianLongTermMemory.java:147–215retrieve
public Mono<String> retrieve(Msg msg)
按查询检索相关文档。
Retrieves relevant memories based on the input message.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
msg | Msg | 消息到使用 as 搜索查询。the message to use as a search query |
Mono<String>io/agentscope/core/memory/bailian/BailianLongTermMemory.java:227–273builder
public static Builder builder()
创建新的构建器用于BailianLongTermMemory。
Creates a new builder for BailianLongTermMemory.
Builderio/agentscope/core/memory/bailian/BailianLongTermMemory.java:307–309close
public void close()
关闭连接并释放相关资源。
Closes the BailianMemoryClient and releases resources.
io/agentscope/core/memory/bailian/BailianLongTermMemory.java:314–319嵌套类详情Nested Class Detail
Builder
public static class BuilderBailianLongTermMemory的构建器。位于 io.agentscope.core.memory.bailian 包。核心成员包括 apiKey、apiBaseUrl、userId、memoryLibraryId、projectId、profileSchema。
Builder for BailianLongTermMemory.