语义代码索引与搜索工具

RAG MCP Server v2.0是一个简化的模型上下文协议服务器,提供自动代码索引和高级语义搜索功能,适用于开发效率提升和代码管理。

  • by ali-48
  • JavaScript
  • 本地部署
  • 更新于
在 GitHub 查看 ali-48/rag-mcp-server

使用说明

RAG MCP服务器v2.0

具有简化v2.0架构的MCP(模型上下文协议)服务器: 2主要工具 用于自动索引和语义代码搜索。

🚀 Nouvelle Architecture v2.0

📋 主要工具(简化)

工具 描述 替换
activated_rag 自动索引的主工具 injection_rag, index_project, update_project, analyse_code
recherche_rag 高级搜索工具 search_code

🎯 V2.0的好处

  1. 简化根 :2个工具而不是6个
  2. 全自动化 :内置检测VS代码+文件查看器
  3. 智能原生 :按内容类型划分的智能块
  4. 完全向后兼容性 :旧工具仍然有效(隐藏)
  5. 自动管道 :阶段0→ scan → 分析→ 分块→ 嵌入→ 注射

🏗️ 建筑技术

管道已激活_rag

activated_rag
    ├── Phase 0 : Détection projet VS Code
    ├── Scan fichiers & changements
    ├── Analyse statique multi-langage
    ├── Chunking intelligent
    │   ├── Code : 1 fonction = 1 chunk
    │   ├── Classes : N chunks
    │   └── Documentation : par paragraphes
    ├── Calcul embeddings
    │   ├── Code : nomic-embed-code
    │   └── Texte : nomic-embed-text
    └── Injection RAG

搜索功能

  • 混合搜索 :语义相似性+文本搜索的组合
  • 高级过滤器 :按内容类型、语言、扩展名、分数
  • 重新排序 :基于元数据的排名(新鲜度、大小、类型)
  • 动态阈值 :相似性阈值的自动自适应

📦 安装

# Cloner le dépôt
git clone <repository-url>
cd rag-mcp-server

# Installer les dépendances
npm install

# Construire le projet
npm run build

🚀 快速使用

自动索引

// Utilisation simple avec activated_rag
const result = await toolRegistry.execute('activated_rag', {
  project_path: '/chemin/vers/mon/projet',
  enable_phase0: true  // Détection automatique VS Code
});

高级搜索

// Recherche avec filtres
const results = await toolRegistry.execute('recherche_rag', {
  query: 'comment implémenter l\'authentification',
  scope: 'project',
  top_k: 5,
  filters: {
    content_type: ['code', 'doc'],
    language: ['typescript', 'javascript']
  }
});

🔧 配置v2.0

配置负责人

{
  "version": "2.0.0",
  "description": "Configuration RAG v2.0",
  "system": {
    "legacy_mode": true,
    "exposed_tools": ["activated_rag", "recherche_rag"],
    "legacy_tools": ["injection_rag", "index_project", "update_project", "search_code", "manage_projects"]
  },
  "defaults": {
    "embedding_provider": "ollama",
    "embedding_model": "nomic-embed-text",
    "chunk_size": 1000,
    "chunk_overlap": 200
  },
  "providers": {
    "ollama": {
      "description": "Ollama embeddings",
      "models": {
        "code": "nomic-embed-code",
        "text": "nomic-embed-text"
      }
    }
  }
}

从v1.0迁移

# Migration automatique
npm run migrate-v2

# Vérification
npm run test-retrocompatibility

🧪 测试

测试v2.0

# Tests de rétrocompatibilité
npm run test:retrocompatibility

# Tests de performance
npm run test:performance

# Tous les tests
npm test

具体测试

  • 迁移测试 :检查向后兼容性
  • 性能测试 :基准新系统与旧系统
  • 集成测试 :管道完整性验证
  • 质量测试 :单独嵌入的验证

🛠️ 项目结构v2.0

rag-mcp-server/
├── src/
│   ├── config/
│   │   └── rag-config.ts         # Gestionnaire de configuration v2.0
│   ├── core/
│   │   ├── tool-registry.ts      # Système central d'enregistrement
│   │   ├── registry.ts           # Enregistrement automatique v1.0
│   │   └── registry-v2.ts        # Enregistrement automatique v2.0
│   ├── tools/
│   │   ├── graph/                # Outils de graphe de connaissances (9 outils)
│   │   └── rag/                  # Outils RAG v2.0
│   │       ├── activated-rag.ts  # Outil maître v2.0
│   │       ├── recherche-rag.ts  # Recherche avancée v2.0
│   │       └── legacy/           # Outils legacy (masqués)
│   │           ├── injection-rag.ts
│   │           ├── index-project.ts
│   │           ├── update-project.ts
│   │           ├── search-code.ts
│   │           └── manage-projects.ts
│   ├── rag/                      # Composants RAG avancés
│   │   ├── indexer.ts            # Indexation avec chunking intelligent
│   │   ├── searcher.ts           # Recherche sémantique avancée
│   │   ├── vector-store.ts       # Stockage vectoriel v2.0
│   │   ├── vector-store-refactored.ts  # Refactorisation embeddings par type
│   │   ├── phase0/               # Phase 0 : Détection automatique
│   │   │   ├── workspace-detector.ts
│   │   │   ├── file-watcher.ts
│   │   │   ├── event-logger.ts
│   │   │   ├── chunker-integration.ts
│   │   │   └── llm-enrichment/   # Enrichissement LLM
│   │   └── ai-segmenter.ts       # Segmentation intelligente
│   └── index.ts                  # Point d'entrée principal
├── config/
│   ├── rag-config.json           # Configuration v1.0 (rétrocompatible)
│   └── rag-config-v2.json        # Configuration v2.0
├── docs/
│   ├── CONFIGURATION.md          # Guide de configuration
│   ├── PHASE0_3_README.md        # Documentation Phase 0
│   └── API_REFERENCE.md          # Référence API
├── test/
│   ├── retrocompatibility-v2.test.ts  # Tests rétrocompatibilité
│   └── phase0-llm-enrichment/    # Tests Phase 0
├── scripts/
│   ├── migrate-config-v2.js      # Migration v1.0 → v2.0
│   └── migrate-rag-store.js      # Migration données
└── package.json

📊 度量v2.0

可见工具

  • 2主要工具 : activated_rag, recherche_rag
  • 9图形工具 :知识图(不变)
  • 可见总数 :11工具

隐藏工具(向后兼容性)

  • 5传统工具 : injection_rag, index_project, update_project, search_code, manage_projects
  • 可访问 :通过直接呼叫(向后兼容)

表演

  • 初始化 :<500ms
  • 索引 :智能块的速度提高30-50%
  • 堆砌艰涩的 :单独嵌入时精度提高20-40%
  • 备忘录 :优化缓存的25%折扣

🔍 故障排除

常见问题

Q:旧工具不再工作了?
R :启用 legacy_mode: true 在配置中。

Q:activated@rag未检测到更改?
R :检查 enable_phase0: true 以及文件观察者权限。

Q:搜索分数低?
R :调整 filters.min_score 或者为内容类型使用适当的模板。

问:表演长度?
R :减少 chunk_size,使用 embedding_provider: 'fake' 对于测试,禁用 enable_watcher.

📈 监控

可用日志

  • logs/activated-rag.log :自动索引
  • logs/recherche-rag.log :高级研究
  • logs/phase0-events.log :事件阶段0
  • logs/performance.log :性能指标

关键指标

const metrics = {
  indexation: {
    files_processed: number,
    chunks_created: number,
    embedding_time_ms: number,
    total_time_ms: number
  },
  recherche: {
    query_time_ms: number,
    results_count: number,
    avg_score: number,
    cache_hit_rate: number
  },
  phase0: {
    files_watched: number,
    change_events: number,
    auto_index_count: number
  }
};

🔮 路线图

v2.1(即将推出)

  • 树保姆集成 :分析AST本地
  • 分布式缓存 :项目之间的嵌入共享
  • API REST :接口HTTP输出
  • 插件 :可定制扩展

v3.0(未来)

  • 自动学习 :参数调整
  • 协作 :用户之间的索引共享
  • CI/CD集成 :自动索引管道
  • 仪表盘 :界面网络去监控

📚 完整文档

🤝 贡献

  1. 分叉项目
  2. 创建分支(git checkout -b feature/amazing-feature)
  3. 提交更改(git commit -m 'Add amazing feature')
  4. 向分支推(git push origin feature/amazing-feature)
  5. 打开拉取请求

📄 许可证

该项目获得MIT许可。查看文件 LICENSE 更多详情。

🙏 致谢


最后更新 : 13/01/2026
版本 : 2.0.0
状态 :具有简化架构的生产就绪🚀
兼容性 :向后兼容v1.0.0

变更日志v2.0.0

  • 新潮 :具有2个主要工具的简化架构
  • 新潮 : activated_rag -自动索引的主工具
  • 新潮 : recherche_rag -带过滤器的高级搜索
  • 新潮 :集成阶段0(检测与代码+文件观察)
  • 新潮 :按内容类型划分的智能块
  • 新潮 :单独嵌入(代码与文本)
  • 新潮 :带隐藏工具的注册表系统v2.0
  • 新潮 :完整的向后兼容性测试
  • 新潮 :脚本去迁移v1.0→ v2.0
  • 新潮 :完整的v2.0文档
  • 改进 :30-50%以上的速度
  • 改进 :搜索精度提高20-40%
  • 改进 :内存减少25%
  • 向后兼容性 :所有V1.0工具都工作(隐藏)

变更日志v1.5.0

  • 新潮 :具有Ollama集成的智能LLM分析
  • 新潮 :服务法学硕士(LlmService)用于调用Ollama API
  • 新潮 :缓存LLM(LlmCache)浇注优化设计性能
  • 新潮 :LLM配置 rag-config.json 与供应商和准备
  • 新潮 智能任务:摘要、关键字提取、结构建议、实体检测、复杂性分类
  • 新潮 :集成到 ai-segmenter.ts 用于智能细分
  • 新潮 :集成到 indexer.ts 使用Cache LLM
  • 新潮 :LLM配置解除测试(test-llm-config.js)
  • 新潮 :Ollama集成测试(test-ollama-integration.js)
  • 改进 :支持多种可配置Ollama型号
  • 改进 :优化LLM调用的批处理
  • 改进 :具有可配置TTL的智能缓存
  • 改进 :LLM功能的完整文档