Experience Pooling 是 MetaGPT 中的一个缓存和检索系统,用于存储和重用函数输出,特别是针对 LLM 查询。通过智能地缓存先前的响应并评估其质量,该系统可以减少 API 调用,降低成本,提高响应时间,同时保持质量。本页面解释了 Experience Pooling 的工作原理、配置选项以及如何在您的应用程序中使用它。
Experience Pooling 作为 MetaGPT 中一个复杂的函数输出缓存层。与依赖精确匹配的简单缓存不同,Experience Pooling 可以识别语义上相似的请求并返回先前成功的响应。
来源
该系统由几个关键组件组成
Experience Pooling 的核心是 Experience 数据结构,它封装了请求-响应对及其元数据。
来源
The Experience model stores
req: The original request textresp: The response contentmetric: Performance metrics including time cost, money cost, and quality scoretag: A categorization label (typically function or class name)The ExperienceManager class manages the lifecycle of experiences, including storage, retrieval, and querying.
来源
The manager provides methods to
It supports two storage backends
The exp_cache decorator is the primary user interface for Experience Pooling. It wraps functions to provide automatic caching and retrieval.
来源
The decorator performs several key functions
Experience Pooling is highly configurable through the MetaGPT configuration system.
来源
关键配置选项
enabled: Master switch for the Experience Pooling systemenable_read/enable_write: Granular control over operationsretrieval_type: Choose between BM25 (text-based) or Chroma (vector-based) storageuse_llm_ranker: Whether to use LLM to rank retrieved experiencesExperience Pooling provides two storage backends with different characteristics
| 功能 | BM25 Storage | Chroma Vector Storage |
|---|---|---|
| Retrieval basis | Keyword matching | Semantic similarity |
| Embedding required | 否 | 是 |
| Storage format | Text index | Vector database |
| 最适合 | Exact/keyword queries | Semantic/conceptual queries |
| 配置 | retrieval_type: bm25 | retrieval_type: chroma |
来源
The system automatically creates and manages the storage based on the configured retrieval type.
To maintain quality, Experience Pooling includes evaluation mechanisms
来源
The default SimpleScorer uses an LLM to evaluate responses on a scale of 1-10, considering how well they address the request. The quality score is stored with the experience and used for future reference.
Here's how to use the exp_cache decorator in your code
来源
You can also use more advanced options
Experience Pooling is designed to integrate with other MetaGPT systems
来源
Experience Pooling shares architectural patterns with RoleZero's long-term memory system, but serves a different purpose
Both systems leverage similar RAG (Retrieval-Augmented Generation) technologies for storage and retrieval.
When implementing Experience Pooling in your applications, consider
来源
To enable verbose logging of new experiences for monitoring
Experience Pooling provides a powerful way to improve efficiency and reduce costs in MetaGPT applications by intelligently reusing previous results when appropriate.
刷新此 Wiki
最后索引时间2025 年 4 月 18 日(be6921)