You need to enable JavaScript to run this app.
文档中心
记忆库 Mem0

记忆库 Mem0

复制全文
下载 pdf
Java SDK
代码示例
复制全文
下载 pdf
代码示例
本文提供 Mem0 Java SDK 的代码示例供您参考。​
前提条件​
请求超时时间设置​
使用 Java SDK 调用 Mem0 接口时,默认无超时时间设置。​
您可以在初始化客户端时,通过 setConnectTimeout(${超时时间})(默认单位:毫秒) 来指定客户端的请求超时时间,若未在该时间内完成,请求即会终止并报超时错误。​
例如,您可以通过如下代码将客户端的请求超时时间设置为 5000 毫秒。​
​
public static ApiClient apiClient = new ApiClient()​
.setCredentials(Credentials.getCredentials(ak, sk))​
.setRegion(region)​
.setConnectTimeout(5000);​
​
创建记忆项目​
说明​
关于下述 SDK 代码中所使用参数的定义、取值范围等信息,请参见 CreateMemoryProject。​
​
import com.volcengine.ApiClient;​
import com.volcengine.ApiException;​
import com.volcengine.sign.Credentials;​
import com.volcengine.mem0.Mem0Api;​
import com.volcengine.mem0.model.*;​
​
public class TestMem0 {​
public static void main(String[] args) throws Exception {​
// Set AKSK authentication information and Region​
// Note the security of the example code. Code leakage may lead to AKSK leakage, which poses a great security risk.​
String ak = "Your AK";​
String sk = "Your SK";​
String region = "Your Region";​
​
ApiClient apiClient = new ApiClient()​
.setCredentials(Credentials.getCredentials(ak, sk))​
.setRegion(region);​
​
Mem0Api mem0Api = new Mem0Api(apiClient);​
​
// Create an interface input parameter​
CreateMemoryProjectRequest request = new CreateMemoryProjectRequest();​
// Set the interface input parameter according to the parameter description of the CreateMemoryProject interface​
request.memoryProjectName("test_memory")​
.memoryProjectType(CreateMemoryProjectRequest.MemoryProjectTypeEnum.LONGTERMMEMORY)​
.description("test_memory")​
.projectName("default")​
.regionId(region)​
.chargeType(CreateMemoryProjectRequest.ChargeTypeEnum.POSTPAID)​
.enableVPC(true)​
.longTermMemoryStrategies(Arrays.asList(​
new LongTermMemoryStrategyForCreateMemoryProjectInput()​
.source(LongTermMemoryStrategyForCreateMemoryProjectInput.SourceEnum.SYSTEM)​
.description("test")​
.strategyName("test_name")​
.strategyType(LongTermMemoryStrategyForCreateMemoryProjectInput.StrategyTypeEnum.SUMMARYMEMORYSTRATEGY)​
))​
.vpcId("vpc-rs5811nceqyov0x58x4****")​
.subnetId("subnet-1g15j13jtzgu88ibuxwqp****")​
.tags(Arrays.asList(​
new TagForCreateMemoryProjectInput()​
.key("department")​
.value("game")​
));​
​
// Call the interface to create a memory project​
try {​
// Copy the code to run the example. Please print the API return value by yourself.​
CreateMemoryProjectResponse response = mem0Api.createMemoryProject(request);​
System.out.println(response);​
} catch (ApiException e) {​
// Copy the code to run the example. Please print the API error information by yourself.​
System.out.println(e.getResponseBody());​
}​
}​
}​
​
查询记忆项目信息​
说明​
关于下述 SDK 代码中所使用参数的定义、取值范围等信息,请参见 DescribeMemoryProjectDetail。​
​
import com.volcengine.ApiClient;​
import com.volcengine.ApiException;​
import com.volcengine.sign.Credentials;​
import com.volcengine.mem0.Mem0Api;​
import com.volcengine.mem0.model.*;​
​
public class TestMem0 {​
public static void main(String[] args) throws Exception {​
// Set AKSK authentication information and Region​
// Note the safety of the example code. Code leakage may lead to AKSK leakage, which poses a great security risk.​
String ak = "Your AK";​
String sk = "Your SK";​
String region = "Your Region";​
​
ApiClient apiClient = new ApiClient()​
.setCredentials(Credentials.getCredentials(ak, sk))​
.setRegion(region);​
​
Mem0Api mem0Api = new Mem0Api(apiClient);​
​
// Create an interface input parameter​
DescribeMemoryProjectDetailRequest request = new DescribeMemoryProjectDetailRequest();​
​
// Set the interface input parameter according to the parameter description of the DescribeMemoryProjectDetail interface​
request.memoryProjectId("mp-cnlfclcu4qc2jck9a8p9758****");​
​
// Call the interface to query the detailed information of the specified memory project​
try {​
// Copy the code to run the example. Please print the API return value by yourself.​
DescribeMemoryProjectDetailResponse response =​
mem0Api.describeMemoryProjectDetail(request);​
System.out.println(response);​
} catch (ApiException e) {​
// Copy the code to run the example. Please print the API error information by yourself.​
System.out.println(e.getResponseBody());​
}​
}​
}​
​
​
最近更新时间:2026.02.28 14:22:38
这个页面对您有帮助吗?
有用
有用
无用
无用