自然语言数据库查询系统
一个基于Python的系统,使用模型上下文协议(MCP)服务器将自然语言问题转换为数据库查询。
概述
该系统使Marcus的团队能够通过以下方式处理数据请求:
- 为主数据库和分析数据库创建MCP服务器
- 将简明英语中的业务问题翻译为SQL查询
- 自动发现和导航复杂的数据关系
- 以用户友好的格式为非技术用户呈现结果
- 优雅地处理错误并提供有意义的反馈
建筑
- MCP服务器:处理对多个数据库的安全连接和查询
- 自然语言处理:将英语问题转换为SQL查询
- 架构发现:自动映射数据库结构和关系
- 查询执行:使用结果格式安全执行查询
- 错误处理:全面的错误管理和验证
安装
pip install -e .快速开始
from nldb_query import NLDBQuerySystem
# Initialize the system
query_system = NLDBQuerySystem()
# Ask a question in natural language
result = query_system.query("What are our top 10 customers by revenue this quarter?")
print(result.formatted_response)发展
# Install development dependencies
pip install -e ".[dev]"
# Run tests
pytest tests/
# Run linting
black src/ tests/
flake8 src/ tests/配置
看 docs/configuration.md 了解详细的配置选项。
许可证
MIT许可证
