Hindsight Node.js客户端:在JavaScript生态中使用AI记忆
Hindsight Node.js客户端在JavaScript生态中使用AI记忆【免费下载链接】hindsightHindsight: Agent Memory That Learns项目地址: https://gitcode.com/GitHub_Trending/hindsight2/hindsightHindsight Node.js客户端是一个专为JavaScript开发者设计的TypeScript SDK它提供了简洁的API接口帮助开发者在应用中轻松集成Hindsight的AI记忆功能。通过这个客户端你可以让AI应用拥有持久化的记忆能力实现跨会话的上下文理解和知识积累。快速开始安装与配置要开始使用Hindsight Node.js客户端首先需要安装依赖包。在你的Node.js项目中运行以下命令npm install vectorize-io/hindsight-client安装完成后你需要创建一个Hindsight客户端实例。最简单的方式是import { HindsightClient } from vectorize-io/hindsight-client; // 基本配置无认证 const client new HindsightClient({ baseUrl: http://localhost:8888 });如果你需要使用API密钥进行认证可以这样配置// 使用API密钥认证 const client new HindsightClient({ baseUrl: http://localhost:8888, apiKey: your-api-key });核心功能记忆的存储与检索Hindsight Node.js客户端提供了直观的API来管理AI记忆主要包括记忆的存储retain、检索recall和反思reflect三个核心操作。存储记忆Retain要存储一条记忆使用retain方法// 存储一条简单记忆 await client.retain(user123, Alice loves AI and machine learning);你还可以添加更多上下文信息// 带上下文的记忆存储 await client.retain(user123, Alice is learning TypeScript, { context: Online course, timestamp: new Date(), tags: [education, programming] });对于多条记忆可以使用retainBatch方法批量存储// 批量存储记忆 await client.retainBatch(user123, [ { content: Alice works at a tech company, tags: [career] }, { content: Alice enjoys hiking, tags: [hobbies] } ]);检索记忆Recall要检索与特定查询相关的记忆使用recall方法// 检索记忆 const results await client.recall(user123, What are Alice\s interests?); console.log(results.results);你可以通过标签过滤来精确检索特定类型的记忆// 带标签过滤的记忆检索 const results await client.recall(user123, What does Alice like?, { tags: [hobbies], tagsMatch: any_strict });反思与生成Reflectreflect方法允许AI基于存储的记忆进行思考并生成回应// 基于记忆生成回应 const answer await client.reflect(user123, Tell me about Alice); console.log(answer.response);你还可以提供额外的上下文来引导反思过程// 带上下文的反思 const answer await client.reflect(user123, What should I talk about with Alice?, { context: We are at a tech conference });高级功能记忆银行管理Hindsight使用记忆银行bank来组织不同用户或场景的记忆。你可以创建和管理多个记忆银行以实现数据隔离和分类。创建记忆银行// 创建新的记忆银行 await client.createBank(user123, { name: Alice\s Memory Bank, reflectMission: Help me understand Alice\s preferences and background });获取银行配置// 获取银行配置 const config await client.getBankConfig(user123); console.log(config);更新银行设置// 更新银行配置 await client.updateBankConfig(user123, { dispositionEmpathy: 4, retainChunkSize: 1000 });错误处理与最佳实践在使用Hindsight客户端时合理的错误处理非常重要try { const results await client.recall(user123, What are Alice\s interests?); console.log(results.results); } catch (error) { if (error instanceof HindsightError) { console.error(API Error: ${error.message} (Status: ${error.statusCode})); console.error(Details:, error.details); } else { console.error(Unexpected error:, error); } }最佳实践建议为不同用户或场景使用不同的记忆银行ID合理使用标签系统对记忆进行分类在生产环境中始终使用API密钥认证对于大量记忆考虑使用批量操作API根据应用需求调整记忆检索的预算参数客户端API参考Hindsight Node.js客户端提供了丰富的API来管理记忆和银行。以下是一些常用接口的简要说明retain(bankId, content, options): 存储单条记忆retainBatch(bankId, items, options): 批量存储记忆retainFiles(bankId, files, options): 上传文件并存储其内容recall(bankId, query, options): 检索与查询相关的记忆reflect(bankId, query, options): 基于记忆生成回应listMemories(bankId, options): 列出记忆createBank(bankId, options): 创建记忆银行getBankProfile(bankId): 获取银行配置文件updateBankConfig(bankId, options): 更新银行配置完整的API文档可以在客户端源代码中找到主要实现位于hindsight-clients/typescript/src/index.ts。结语Hindsight Node.js客户端为JavaScript开发者提供了强大而直观的工具让AI应用能够拥有持久化的记忆能力。通过简单的API调用你可以轻松实现记忆的存储、检索和反思为你的AI应用添加上下文理解和知识积累的能力。无论是构建智能聊天机器人、个人助手还是需要长期记忆的AI应用Hindsight Node.js客户端都能为你提供可靠的记忆管理解决方案。开始探索吧让你的AI应用不再健忘【免费下载链接】hindsightHindsight: Agent Memory That Learns项目地址: https://gitcode.com/GitHub_Trending/hindsight2/hindsight创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考