Compare commits

...

6 Commits

Author SHA1 Message Date
8e871647f6 ♻️ refactor(代码): 重构数据库优化器逻辑
- 移除不必要的DatabaseOptimizer类及其配置
- 添加WebsiteKnowledgeBase以支持网页知识库
- 优化MCPTools的使用,合并多个工具的初始化
2025-03-31 02:20:24 +08:00
0455760852 feat(database_optimizer): 支持异步数据库分析
- 新增异步主函数以提升性能
- 重构知识库加载及智能体创建逻辑
- 添加客户端会话以连接MCP服务器
2025-03-31 01:55:21 +08:00
f280258527 feat(database_optimizer): 添加数据库优化工程师智能体功能
- 使用 DeepSeek 模型进行智能分析
- 集成 PostgreSQL MCP 服务器工具
- 加载数据库知识库
- 提供数据库优化建议
2025-03-31 01:00:28 +08:00
356041051c feat(main): 增加PDF知识库和MCP工具集成
- 创建PDF知识库以从本地文件加载数据并支持向量搜索
- 集成MCP工具以与PostgreSQL数据库进行交互
- 通过组合知识库实现多源知识集成
2025-03-31 00:56:36 +08:00
e9865b3e5b feat(project): add initial project setup and dependencies
- 新增.gitignore以排除环境文件和IDE配置
- 更新pyproject.toml以添加新依赖:ipywidgets, openai, python-dotenv
- 新建Python脚本以加载环境变量并配置智能体

💄 style(notebook): improve notebook code structure and comments

- 修改notebook中代码块的执行计数为null
- 添加代码注释以提升可读性和理解性
- 引入load_dotenv以支持环境变量加载
2025-03-30 23:50:21 +08:00
d45eecda50 feat(pyproject): add new dependencies for project
- 添加`agno`、`anthropic`和`notebook`作为项目依赖
- 确保项目能够使用这些库以实现新的功能

 feat(notebook.ipynb): enhance notebook with new code cell

- 在Jupyter笔记本中添加新的代码单元以执行打印操作
- 更新内核配置以使用`.venv`环境
2025-03-30 23:16:31 +08:00
5 changed files with 2246 additions and 2 deletions

4
.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
.env
.idea
.venv
tmp

View File

@@ -4,4 +4,18 @@ version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = []
dependencies = [
"agno>=1.2.6",
"anthropic>=0.49.0",
"ipywidgets>=8.1.5",
"lancedb>=0.21.2",
"mcp>=1.6.0",
"notebook>=7.3.3",
"numpy>=2.2.4",
"openai>=1.69.0",
"pandas>=2.2.3",
"pypdf>=5.4.0",
"python-dotenv>=1.1.0",
"sqlalchemy>=2.0.40",
"tantivy>=0.22.2",
]

2061
uv.lock generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -16,11 +16,68 @@
"- [ ] 精通关系型数据库系统的理论知识以及`postgresql`的实现细节(知识库)\n",
"- [ ] 能够使用`postgresql mcp server`来分析现有数据库设计(行为)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2025-03-30T15:44:44.236141Z",
"start_time": "2025-03-30T15:44:44.223728Z"
}
},
"outputs": [],
"source": [
"# 然后在notebook中加载\n",
"from dotenv import load_dotenv\n",
"\n",
"# 加载当前目录下的.env文件\n",
"load_dotenv()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2025-03-30T15:44:58.492402Z",
"start_time": "2025-03-30T15:44:45.695125Z"
}
},
"outputs": [],
"source": [
"from agno.agent import Agent, RunResponse # noqa\n",
"from agno.models.deepseek import DeepSeek\n",
"\n",
"agent = Agent(model=DeepSeek(id=\"deepseek-chat\"), markdown=True)\n",
"\n",
"# Get the response in a variable\n",
"# run: RunResponse = agent.run(\"Share a 2 sentence horror story\")\n",
"# print(run.content)\n",
"\n",
"# Print the response in the terminal\n",
"agent.print_response(\"傻狗\")\n",
"# 用jupyter的话输出有问题妈的,转到py文件"
]
}
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python"
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.8"
}
},
"nbformat": 4,

108
数据库优化工程师.py Normal file
View File

@@ -0,0 +1,108 @@
#!/usr/bin/env python3
"""
PostgreSQL 数据库优化工程师智能体
功能:
- 使用 DeepSeek 模型进行智能分析
- 集成 PostgreSQL MCP 服务器工具
- 加载数据库知识库
- 提供数据库优化建议
"""
import asyncio
import os
from typing import Optional
from dataclasses import dataclass
from dotenv import load_dotenv
from agno.agent import Agent
from agno.models.deepseek import DeepSeek
from agno.knowledge.pdf import PDFKnowledgeBase
from agno.vectordb.lancedb import LanceDb, SearchType
from agno.embedder.openai import OpenAIEmbedder
from agno.knowledge.combined import CombinedKnowledgeBase
from agno.tools.mcp import MCPTools
from mcp.client.stdio import stdio_client
from mcp import ClientSession, StdioServerParameters
from agno.knowledge.website import WebsiteKnowledgeBase
async def main():
load_dotenv()
"""设置知识库"""
local_pdf_kb = PDFKnowledgeBase(
path="D:\\Sources\\DONGJAK-TOOLS\\pdfs\\Database Fundamentals.pdf",
vector_db=LanceDb(
table_name="database_fundamentals",
uri="tmp/lancedb",
search_type=SearchType.vector,
embedder=OpenAIEmbedder(id="text-embedding-3-small"),
),
)
# Create Website knowledge base
website_kb = WebsiteKnowledgeBase(
urls=["https://www.lucidchart.com/blog/database-design-best-practices"],
max_links=10,
vector_db=LanceDb(
table_name="website_documents",
uri="tmp/lancedb",
search_type=SearchType.vector,
embedder=OpenAIEmbedder(id="text-embedding-3-small"),
),
)
knowledge_base = CombinedKnowledgeBase(
sources=[local_pdf_kb, website_kb],
vector_db=LanceDb(
table_name="combined_documents",
uri="tmp/lancedb",
search_type=SearchType.vector,
embedder=OpenAIEmbedder(id="text-embedding-3-small"),
),
)
knowledge_base.load()
postgres_server_params = StdioServerParameters(
command="cmd",
args=[
"/c",
"npx",
"-y",
"@modelcontextprotocol/server-postgres",
"postgresql://postgres:postgres@192.168.1.7:5432/aq",
],
env={},
)
searxng_server_params = StdioServerParameters(
command="cmd",
args=[
"/c",
"npx",
"-y",
"https://github.com/ihor-sokoliuk/mcp-searxng.git",
],
env={
"SEARXNG_URL": "https://searchxng.ailoveworld.cn",
},
)
# Create a client session to connect to the MCP server
async with (
MCPTools(server_params=postgres_server_params) as postgres_tools,
MCPTools(server_params=searxng_server_params) as searxng_tools,
):
agent = Agent(
model=DeepSeek(id="deepseek-chat"),
markdown=True,
knowledge=knowledge_base,
search_knowledge=True,
show_tool_calls=True,
tools=[postgres_tools, searxng_tools],
)
await agent.aprint_response("帮我分析一下aq.public数据库,并给出优化建议", stream=True)
# await agent.aprint_response("阅读下 https://www.lucidchart.com/blog/database-design-best-practices 这篇文章", stream=True)
if __name__ == "__main__":
asyncio.run(main())