项目简介

Schema Search是一个专为数据库设计的自然语言搜索工具,能够快速帮助用户找到所需的数据库表及其关联关系,无需手动浏览复杂的数据库结构。

主要功能

  • 多数据库支持:兼容PostgreSQL、MySQL、Snowflake、BigQuery和Databricks等多种数据库系统
  • 灵活搜索策略:支持语义搜索、BM25关键词搜索、模糊匹配和混合搜索
  • 智能关联发现:通过外键关系自动发现相关的表
  • 高性能检索:支持多种优化算法,查询延迟在毫秒级别
  • 智能缓存:自动检测schema变化并更新缓存

安装步骤

# 基础安装(仅BM25+模糊搜索,约10MB)
pip install "schema-search[postgres]"

# 包含语义搜索功能(约500MB)
pip install "schema-search[postgres,semantic]"

# 包含MCP服务器功能
pip install "schema-search[postgres,semantic,mcp]"

服务器配置

将以下配置添加到MCP客户端(如Claude Desktop或Cursor)的配置文件中:

{
  "mcpServers": {
    "schema-search": {
      "command": "uvx",
      "args": [
        "schema-search[postgres,mcp]", 
        "postgresql://user:pass@localhost/db", 
        "可选配置文件路径", 
        "可选LLM API密钥", 
        "可选LLM基础URL"
      ]
    }
  }
}

参数说明:

  • 第一个参数:数据库连接字符串
  • 第二个参数:自定义配置文件路径(可选)
  • 第三个参数:LLM API密钥(仅在使用LLM生成schema摘要时需要)
  • 第四个参数:LLM基础URL(可选,用于自定义API端点)

基本使用方法

安装配置完成后,MCP客户端即可通过'schema_search'工具进行自然语言查询,例如:"用户退款信息存储在哪个表?"

Python API使用

from sqlalchemy import create_engine
from schema_search import SchemaSearch

engine = create_engine("postgresql://user:pass@localhost/db")
sc = SchemaSearch(engine)
results = sc.search("用户退款信息存储在哪里?")

信息

分类

数据库与文件