Reflect:在记忆之上推理
Reflect 操作在所存记忆之上进行代理式推理,并由记忆库的使命、指令和性格特质引导。与返回原始记忆的 Recall 不同,Reflect 会综合信息并得出带有置信度分数的结论。
概述
Reflect 在记忆之上进行推理:
- 从存储的记忆中综合洞察
- 推理受性格特质(怀疑度、字面度、共情度)影响
- 基于证据强度的置信度分数
- 用于透明性的引用来源
- 自动将相关的 心智模型 作为额外上下文纳入
基本用法
- Python
- TypeScript
- cURL
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)
import { HindsightClient } from '@vectorize-io/hindsight-client';
const client = new HindsightClient({
baseUrl: 'https://api.hindsight.vectorize.io',
apiKey: 'your-api-key'
});
// Ask a question
const response = await client.reflect(
'your-bank-id',
'What are the key priorities for the project?'
);
console.log(response.text);
console.log('Based on:', response.based_on);
curl -X POST https://api.hindsight.vectorize.io/v1/default/banks/{bank_id}/reflect \
-H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{
"query": "What are the key priorities for the project?"
}'
工作原理
调用 Reflect 时:
- 问题分析 - AI 理解你的问题
- 记忆检索 - 通过 TEMPR(语义、关键词、图、时间搜索)自动召回相关记忆
- 心智模型注入 - 相关的 心智模型 作为额外上下文被纳入
- 推理 - AI 在记忆库性格特质影响下,综合记忆和心智模型中的信息
- 答案生成 - 生成连贯的回应
- 来源引用 - 识别支撑的记忆和心智模型
请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
bank_id | string | 是 | 要查询的记忆库(在 URL 路径中) |
query | string | 是 | 要回答的问题 |
context | string | 否 | 该问题的额外上下文 |
budget | string | 否 | 搜索深度:"low"、"mid"、"high"(默认:"low") |
max_tokens | integer | 否 | 响应的最大 Token 数(默认:4096) |
response_schema | object | 否 | 用于结构化输出的 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
}
}
| 字段 | 说明 |
|---|---|
text | AI 生成的问题回答 |
based_on | 用于形成答案的记忆 |
mental_models | 用作上下文的心智模型(如有) |
structured_output | 提供了 response_schema 时的解析后 JSON |
usage | Token 消耗明细 |
Reflect 与 Recall 对比
| 方面 | Recall | Reflect |
|---|---|---|
| 输出 | 原始记忆 | 综合后的答案 |
| 处理 | 仅搜索 | 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="preferences?"
)
在需要时提供上下文
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?"
)
response = client.reflect(
bank_id=bank_id,
question="What are the requirements?"
)
在界面中使用
记忆库中的 Reflect 视图提供了交互式聊天界面:
- 进入你的记忆库
- 在侧边栏点击 Reflect
- 键入你的问题
- 查看 AI 生成的答案
- 检查来源引用
这对以下场景有用:
- 探索记忆库中存储的内容
- 在 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}")
使用来源可以:
- 验证答案的准确性
- 为用户提供透明性
- 链接回原始信息
- 调试意外的答案
错误处理
- Python
- TypeScript
try:
response = client.reflect(bank_id=bank_id, query=query)
print(response.text)
except Exception as e:
print(f"Error: {e}")
try {
const response = await client.reflect(bankId, query);
console.log(response.text);
} catch (error) {
console.error('Error:', error.message);
}
常见错误
| 错误 | 原因 | 解决方法 |
|---|---|---|
| 401 Unauthorized | API 密钥无效 | 检查 API 密钥 |
| 402 Payment Required | 额度不足 | 为账户添加额度 |
| 404 Not Found | bank_id 无效 | 确认记忆库存在 |
| 400 Bad Request | 问题为空 | 提供问题 |
性能考虑
- 问题成本更高 - Reflect 比 Recall 使用更多 Token
- 限制来源 - 使用
max_sources控制记忆检索 - 尽可能缓存 - 为常见问题存储答案
- 优先考虑 Recall - 如果原始记忆足够,优先使用 Recall