Lenny RAG MCP服务器
MCP服务器提供299个Lenny Rachitsky播客转录本的分层RAG。通过检索相关见解、真实世界的例子和完整的文字记录上下文,实现产品开发头脑风暴。
快速开始
# Clone the repository (includes pre-built index via Git LFS)
git clone git@github.com:mpnikhil/lenny-rag-mcp.git
cd lenny-rag-mcp
# Create and activate virtual environment
python -m venv venv
source venv/bin/activate
# Install the package
pip install -e .克劳德代码
claude mcp add lenny --scope user -- /path/to/lenny-rag-mcp/venv/bin/python -m src.server或添加到 ~/.claude.json:
{
"mcpServers": {
"lenny": {
"type": "stdio",
"command": "/path/to/lenny-rag-mcp/venv/bin/python",
"args": ["-m", "src.server"],
"cwd": "/path/to/lenny-rag-mcp"
}
}
}克劳德桌面版
添加 ~/Library/Application Support/Claude/claude_desktop_config.json:
{
"mcpServers": {
"lenny": {
"command": "/path/to/lenny-rag-mcp/venv/bin/python",
"args": ["-m", "src.server"],
"cwd": "/path/to/lenny-rag-mcp"
}
}
}光标
添加 .cursor/mcp.json 在您的项目或 ~/.cursor/mcp.json 全球地:
{
"mcpServers": {
"lenny": {
"command": "/path/to/lenny-rag-mcp/venv/bin/python",
"args": ["-m", "src.server"],
"cwd": "/path/to/lenny-rag-mcp"
}
}
}替换 /path/to/lenny-rag-mcp 在所有配置中都包含您的实际克隆位置。______________________________________________________________________
MCP工具
search_lenny
在整个语料库中进行语义搜索。返回渐进式披露的指针。
| 参数 | 类型 | 说明 |
|---|---|---|
query | string | 搜索查询(例如,“B2B产品定价”、“创始人模式”) |
top_k | integer | 结果数(默认值:5,最大值:20) |
type_filter | string | 按类型筛选: insight, example, topic, episode |
退货: 根据相关性得分、剧集参考和主题ID对结果进行排名,以便深入了解。
get_chapter
加载具有完整上下文的特定主题。使用后 search_lenny 以获取详细信息。
| 参数 | 类型 | 说明 |
|---|---|---|
episode | string | 剧集文件名(例如“Brian Chesky.txt”) |
topic_id | string | 主题ID(例如“Topic_3”) |
退货: 主题摘要、所有见解、所有示例和原始转录片段。
get_full_transcript
加载包含元数据的完整剧集记录。
| 参数 | 类型 | 说明 |
|---|---|---|
episode | string | 剧集文件名(例如“Brian Chesky.txt”) |
退货: 完整成绩单(10-40K标记)、剧集元数据和主题列表。
list_episodes
浏览可用剧集,可选择按专业知识过滤。
| 参数 | 类型 | 说明 |
|---|---|---|
expertise_filter | string | 按标签筛选(例如,“增长”、“定价”、“AI”) |
退货: 299集的列表,带有嘉宾姓名和专业标签。
______________________________________________________________________
数据管理方法
分层提取
每个成绩单都被处理成一个4级层次结构,实现了渐进式披露:
Episode
├── Topics (10-20 per episode)
│ ├── Insights (2-4 per topic)
│ └── Examples (1-3 per topic)这使得Claude可以从轻量级搜索结果开始,只在需要时进行深入搜索,从而保持上下文窗口的效率。
提取模式
{
"episode": {
"guest": "Guest Name",
"expertise_tags": ["growth", "pricing", "leadership"],
"summary": "150-200 word episode summary",
"key_frameworks": ["Framework 1", "Framework 2"]
},
"topics": [{
"id": "topic_1",
"title": "Searchable topic title",
"summary": "Topic summary",
"line_start": 1,
"line_end": 150
}],
"insights": [{
"id": "insight_1",
"text": "Actionable insight or contrarian take",
"context": "Additional context",
"topic_id": "topic_1",
"line_start": 45,
"line_end": 52
}],
"examples": [{
"id": "example_1",
"explicit_text": "The story as told in the transcript",
"inferred_identity": "Airbnb",
"confidence": "high",
"tags": ["marketplace", "growth", "launch strategy"],
"lesson": "Specific lesson from this example",
"topic_id": "topic_1",
"line_start": 60,
"line_end": 85
}]
}隐式锚点检测
许多客人提到的公司没有点名(“我以前的公司……”)。提取提示指示模型根据客人的背景推断身份:
- 布莱恩·切斯基说“当我们开始”→ Airbnb(高信心)
- 一位市场专家说“一家拼车公司”→ 可能是优步/Lyft(中等信心)
这展示了仅靠关键字搜索无法找到的示例。
质量阈值
每次转录提取都会根据最低阈值进行验证:
| 元素 | 最小值 | 典型值 |
|---|---|---|
| 主题 | 10 | 15-20 |
| 见解 | 15 | 25-35 |
| 示例 | 10 | 18-25 |
低于阈值的提取会触发手动审查警告。
______________________________________________________________________
模型和技术栈
| 组件 | 型号/工具 | 用途 |
|---|---|---|
| 预处理 | 克劳德·海库 (通过Claude CLI) | 从成绩单中提取结构化层次结构 |
| 嵌入件 | bge-small-en-v1.5 | 搜索的语义相似性 |
| 矢量数据库 | 色度数据库 | 持久矢量存储 |
| MCP框架 | 主控程序 (Python SDK) | Claude的工具接口 |
为什么选择Claude Haiku进行预处理?
- 质量:Haiku可靠地遵循复杂的提取提示
- 成本:每份成绩单约0.02-0.03美元(299集共约6-9美元)
- 速度:每份成绩单约30秒
为什么使用bge-small-en-v1.5进行嵌入?
- 演出:针对其大小的顶级检索质量
- 效率:384维,快速推理
- 本地:完全在CPU上运行,不需要API调用
______________________________________________________________________
语料库统计
| 度量 | 计数 |
|---|---|
| 剧集 | 299 |
| 主题 | 6183 |
| 见解 | 8840 |
| 示例 | 6502 |
| 平均话题/集 | 20.7 |
| 平均见解/集 | 29.6 |
| 平均实例/集 | 21.7 |
______________________________________________________________________
重建索引
该回购包括一个预先构建的ChromaDB索引。从头开始重建:
重新处理成绩单(需要Claude CLI)
# Process all unprocessed transcripts
python scripts/preprocess_haiku.py
# Process specific file
python scripts/preprocess_haiku.py --file "Brian Chesky.txt"
# Parallel processing (4 batches of 50)
python scripts/preprocess_haiku.py --limit 50 --offset 0 &
python scripts/preprocess_haiku.py --limit 50 --offset 50 &
python scripts/preprocess_haiku.py --limit 50 --offset 100 &
python scripts/preprocess_haiku.py --limit 50 --offset 150 &重建嵌入
# Incremental (only new files)
python scripts/embed.py
# Full rebuild
python scripts/embed.py --rebuild______________________________________________________________________
项目结构
lenny-rag-mcp/
├── transcripts/ # 299 raw .txt podcast transcripts
├── preprocessed/ # Extracted JSON hierarchy (one per episode)
├── chroma_db/ # Vector embeddings (Git LFS)
├── prompts/
│ └── extraction.md # Haiku extraction prompt
├── src/
│ ├── server.py # MCP server & tool definitions
│ ├── retrieval.py # LennyRetriever class (ChromaDB wrapper)
│ └── utils.py # File loading utilities
├── scripts/
│ ├── preprocess_haiku.py # Claude CLI preprocessing
│ └── embed.py # ChromaDB embedding pipeline
└── pyproject.toml______________________________________________________________________
许可证
麻省理工学院
