跳到主要内容

Reflect:在记忆之上推理

Reflect 操作在所存记忆之上进行代理式推理,并由记忆库的使命、指令和性格特质引导。与返回原始记忆的 Recall 不同,Reflect 会综合信息并得出带有置信度分数的结论。

概述

Reflect 在记忆之上进行推理:

  • 从存储的记忆中综合洞察
  • 推理受性格特质(怀疑度、字面度、共情度)影响
  • 基于证据强度的置信度分数
  • 用于透明性的引用来源
  • 自动将相关的 心智模型 作为额外上下文纳入

基本用法

from hindsight_client import Hindsight

client = Hindsight(
base_url="https://api.hindsight.vectorize.io",
api_key="your-api-key"
)

# Ask a question
response = client.reflect(
bank_id="your-bank-id",
query="What are the key priorities for the project?"
)

print(response.text)
print("Based on:", response.based_on)

工作原理

调用 Reflect 时:

  1. 问题分析 - AI 理解你的问题
  2. 记忆检索 - 通过 TEMPR(语义、关键词、图、时间搜索)自动召回相关记忆
  3. 心智模型注入 - 相关的 心智模型 作为额外上下文被纳入
  4. 推理 - AI 在记忆库性格特质影响下,综合记忆和心智模型中的信息
  5. 答案生成 - 生成连贯的回应
  6. 来源引用 - 识别支撑的记忆和心智模型

请求参数

参数类型必填说明
bank_idstring要查询的记忆库(在 URL 路径中)
querystring要回答的问题
contextstring该问题的额外上下文
budgetstring搜索深度:"low"、"mid"、"high"(默认:"low")
max_tokensinteger响应的最大 Token 数(默认:4096)
response_schemaobject用于结构化输出的 JSON Schema

响应

{
"text": "Based on the stored memories, the key priorities for the project are: 1) Completing the user authentication module by March 15th, 2) Improving API response times to under 200ms, and 3) Adding support for dark mode as requested by multiple users.",
"based_on": [],
"mental_models": [
{
"id": "mm_abc123",
"text": "The project is focused on building a modern web application..."
}
],
"structured_output": null,
"usage": {
"input_tokens": 3352,
"output_tokens": 806,
"total_tokens": 4158
}
}
字段说明
textAI 生成的问题回答
based_on用于形成答案的记忆
mental_models用作上下文的心智模型(如有)
structured_output提供了 response_schema 时的解析后 JSON
usageToken 消耗明细

Reflect 与 Recall 对比

方面RecallReflect
输出原始记忆综合后的答案
处理仅搜索AI 推理
适用场景获取上下文回答问题
Token 用量较低较高
来源结果本身即为来源单独引用来源

何时使用 Recall

  • 你需要原始数据自行处理
  • 为另一个 AI 系统构建提示
  • 调试或审视存储的记忆
  • 最小化 Token 使用

何时使用 Reflect

  • 直接回答用户问题
  • 生成摘要或洞察
  • 需要从多条记忆中综合信息
  • 想要自动引用来源

问题最佳实践

提出清晰的问题

response = client.reflect(
bank_id=bank_id,
question="What communication preferences has the user expressed?"
)

在需要时提供上下文

response = client.reflect(
bank_id=bank_id,
question="What should I know before our meeting?",
context="We're meeting with the client to discuss the Q2 roadmap"
)

保持具体

response = client.reflect(
bank_id=bank_id,
question="What technical requirements were mentioned for the mobile app?"
)

在界面中使用

记忆库中的 Reflect 视图提供了交互式聊天界面:

  1. 进入你的记忆库
  2. 在侧边栏点击 Reflect
  3. 键入你的问题
  4. 查看 AI 生成的答案
  5. 检查来源引用

这对以下场景有用:

  • 探索记忆库中存储的内容
  • 在 API 集成之前测试问题
  • 理解记忆如何驱动答案

高级模式

对话上下文

基于先前的答案进行追问:

# First question
resp1 = client.reflect(
bank_id=bank_id,
question="Who are the key stakeholders?"
)

# Follow-up with context
resp2 = client.reflect(
bank_id=bank_id,
question="What are their main concerns?",
context=f"We identified these stakeholders: {resp1.answer}"
)

组合操作

用 Recall 获取上下文,用 Reflect 进行综合:

# Get relevant context
context_memories = client.recall(
bank_id=bank_id,
query="project history",
limit=5
)

# Ask a focused question with context
context_text = "\n".join([m.content for m in context_memories])
response = client.reflect(
bank_id=bank_id,
question="What lessons were learned from past projects?",
context=context_text
)

处理不确定性

Reflect 可以指明信息缺失:

response = client.reflect(
bank_id=bank_id,
question="What is the project budget?"
)

# Response might be:
# "I don't have information about the project budget in the stored memories."

Token 使用

Reflect 操作通常比 Recall 使用更多 Token,因为:

  • AI 推理计算密集
  • 多条记忆被一起处理
  • 答案生成需要额外的 Token

使用分析 页面监控用量。

来源引用

每个 Reflect 响应都包含来源:

response = client.reflect(bank_id=bank_id, question="...")

for source in response.sources:
print(f"Memory: {source.content}")
print(f"Relevance: {source.relevance}")

使用来源可以:

  • 验证答案的准确性
  • 为用户提供透明性
  • 链接回原始信息
  • 调试意外的答案

错误处理

try:
response = client.reflect(bank_id=bank_id, query=query)
print(response.text)
except Exception as e:
print(f"Error: {e}")

常见错误

错误原因解决方法
401 UnauthorizedAPI 密钥无效检查 API 密钥
402 Payment Required额度不足为账户添加额度
404 Not Foundbank_id 无效确认记忆库存在
400 Bad Request问题为空提供问题

性能考虑

  1. 问题成本更高 - Reflect 比 Recall 使用更多 Token
  2. 限制来源 - 使用 max_sources 控制记忆检索
  3. 尽可能缓存 - 为常见问题存储答案
  4. 优先考虑 Recall - 如果原始记忆足够,优先使用 Recall