Cognee 与 Litefuse 集成
什么是 Cognee? Cognee 是一个开源 AI 记忆框架,可将你的数据转换为可搜索、可推理的知识图谱。结合 Cognee 与 Litefuse,你可以为每个流水线步骤和搜索查询获得生产级的追踪、评估和分析能力。详情请见 GitHub 仓库 或文档。
什么是 Litefuse? Litefuse 是开源的 AI Agent 可观测性与评估平台,帮助团队在生产环境中追踪应用、调试问题、评估质量并监控成本。
快速开始指南
第 1 步:安装 Cognee(包含 Litefuse)
pip install cognee # langfuse 已声明为依赖,会被自动安装第 2 步:创建 Litefuse 项目
- 在 Litefuse Cloud 注册。
- 创建一个新项目,复制 public 与 secret API Key。
第 3 步:配置环境变量
创建一个 .env 文件,或直接在 shell 中导出变量:
LANGFUSE_PUBLIC_KEY=<your public key>
LANGFUSE_SECRET_KEY=<your secret key>
LANGFUSE_HOST=https://litefuse.cloud第 4 步:追踪 Cognee 函数
cognee 自带一个对 Litefuse 的小型封装。引入 get_observe(),并为你想监控的函数加上装饰器。
from cognee.modules.observability.get_observe import get_observe
observe = get_observe()
@observe(as_type="generation") # 可选标签
async def acreate_structured_output(...):
... # 你的业务逻辑每次函数执行时,装饰器会自动在 Litefuse 中开启一个 span,并把耗时、token 用量和自定义元数据等指标流式上报。
第 5 步:开始 Cognify 并查看 trace
像往常一样运行你的 Cognee 工作流:
import cognee
import asyncio
from cognee.modules.observability.get_observe import get_observe
observe = get_observe()
@observe(name="simple_example_run", as_type="example")
async def main():
await cognee.add("Natural language processing (NLP) is ...")
await cognee.cognify()
results = await cognee.search("Tell me about NLP")
for r in results:
print(r)
asyncio.run(main())打开 Litefuse UI —— 你会看到所有被 @observe 装饰的辅助函数对应的 trace。
添加你自己的 span
你可以为代码中任何函数添加 instrumentation —— 不仅仅是 cognee 的内部函数:
from cognee.modules.observability.get_observe import get_observe
observe = get_observe()
@observe(as_type="my_tool", metadata={"foo": "bar"})
def my_helper(arg1, arg2):
...资源
- Cognee 官网
- Cognee GitHub 仓库
- 关于本集成的 Cognee 文档
这个页面对你有帮助吗?