跳到主要内容

seekdb + Claude Code:打造懂向量数据库的 AI 编程助手

Claude Code 作为 Anthropic 推出的 AI 编程助手,凭借强大的代码理解和生成能力,正在成为越来越多开发者的得力工具。然而,当你在 Claude Code 中询问 seekdb 相关问题时,AI 可能无法给出准确的回答,因为它对 seekdb 这款新兴的 AI 原生搜索数据库了解有限。

本文以创建一个 seekdb 混合搜索应用为例,介绍如何通过 seekdb Claude Code 插件让 Claude Code 拥有 seekdb 专业知识,从而在开发过程中获得精准的技术指导。

seekdb Claude Code 插件介绍

seekdb Claude Code 插件是一款 Agent Skill 插件,该插件使 Claude Code 可以检索 seekdb 官方文档,从而理解 seekdb 数据库知识的上下文中,使其能够:

  • 理解 seekdb 数据库概念:向量搜索、混合搜索、AI 函数等。
  • 提供准确的代码建议:基于官方文档生成符合最佳实践的代码。
  • 回答 seekdb 相关问题:直接在终端中获取技术支持。
  • 加速开发流程:减少查阅文档的时间,专注于业务逻辑。

有关 seekdb Claude Code 插件的更多介绍,参见 seekdb Agent Skill

准备工作

  • Node.js 环境:需要 Node.js 18 或更高版本。

  • 网络访问:需要能够访问 GitHub(用于安装插件和获取最新文档)。

  • 在安装 seekdb 插件之前,请确保你已经安装了 Claude Code。如果还未安装,可以通过以下命令安装:

    npm install -g @anthropic-ai/claude-code

    安装完成后,配置 API 密钥:

    export ANTHROPIC_API_KEY="your-api-key-here"

    # 设置 API Base URL(如果使用代理或自定义端点)
    export ANTHROPIC_BASE_URL="https://api.anthropic.com"

步骤一:配置网络设置

seekdb 技能插件需要从 GitHub 获取最新文档,因此需要配置 Claude Code 允许网络请求。

在项目根目录下创建或编辑 .claude/settings.local.json 文件:

{
"skipWebFetchPreflight": true
}
信息

skipWebFetchPreflight 设置为 true 可跳过网络请求的预检,允许 Claude Code 直接访问远程文档。如果无法访问 GitHub,插件会自动回退到本地文档。

步骤二:安装 seekdb 插件

在项目根目录下输入 claude ,启动 Claude Code。

  1. 添加 seekdb 市场

    在 Claude Code 中运行:

    /plugin marketplace add oceanbase/seekdb-ecology-plugins
  2. 安装插件

    /plugin install seekdb-plugin@seekdb
  3. 重启 Claude Code

    安装完成后,退出并重新启动 Claude Code 以确保插件正确加载。

插件加载完成后,可以直接向 Claude Code 询问任何 seekdb 相关问题了。

步骤三:使用 Claude Code 创建一个 seekdb 混合搜索应用

安装插件后,在 Claude Code 中开始一个新对话,输入以下问题:

我想用 Python 创建一个简单的 seekdb 应用,实现文档的混合搜索功能,请帮我写代码

Claude Code 会给出准确的回答:

import pyseekdb

# ==================== 创建集合 ====================
# 创建嵌入式客户端
client = pyseekdb.Client(path="./seekdb.db")
# 创建集合
collection = client.create_collection(
name="hybrid_search_demo"
)

# ==================== 添加数据 ====================
# 定义文档
documents = [
"Machine learning is revolutionizing artificial intelligence and data science",
"Python programming language is essential for machine learning developers",
"Deep learning neural networks enable advanced AI applications",
"Data science combines statistics, programming, and domain expertise",
"Natural language processing uses machine learning to understand text",
"Computer vision algorithms process images using deep learning techniques",
"Reinforcement learning trains agents through reward-based feedback",
"Python libraries like TensorFlow and PyTorch simplify machine learning",
"Artificial intelligence systems can learn from large datasets",
"Neural networks mimic the structure of biological brain connections"
]

# 定义元数据
metadatas = [
{"category": "AI", "topic": "machine learning", "year": 2023, "popularity": 95},
{"category": "Programming", "topic": "python", "year": 2023, "popularity": 88},
{"category": "AI", "topic": "deep learning", "year": 2024, "popularity": 92},
{"category": "Data Science", "topic": "data analysis", "year": 2023, "popularity": 85},
{"category": "AI", "topic": "nlp", "year": 2024, "popularity": 90},
{"category": "AI", "topic": "computer vision", "year": 2023, "popularity": 87},
{"category": "AI", "topic": "reinforcement learning", "year": 2024, "popularity": 89},
{"category": "Programming", "topic": "python", "year": 2023, "popularity": 91},
{"category": "AI", "topic": "general ai", "year": 2023, "popularity": 93},
{"category": "AI", "topic": "neural networks", "year": 2024, "popularity": 94}
]

ids = [f"doc_{i+1}" for i in range(len(documents))]
# 插入数据
collection.add(ids=ids, documents=documents, metadatas=metadatas)

# ==================== 执行混合搜索 ====================
# 执行混合搜索
hybrid_result = collection.hybrid_search(
query={"where_document": {"$contains": "machine learning"}, "n_results": 10},
knn={"query_texts": ["AI research"], "n_results": 10},
rank={"rrf": {}},
n_results=5
)

# ==================== 打印查询结果 ====================
print("\n混合搜索结果:")
print(f" ids: {hybrid_result['ids'][0]}")
print(f" Document: {hybrid_result['documents'][0]}")

步骤四:运行示例

  1. 安装 pyseekdb

    pip install pyseekdb
  2. 创建文件并运行

    将上述代码保存为 hybrid_search_demo.py,然后运行:

    python hybrid_search_demo.py
  3. 查看结果

    混合搜索结果如下:

    ids: ['doc_1', 'doc_5', 'doc_2', 'doc_8', 'doc_3']
    Document: ['Machine learning is revolutionizing artificial intelligence and data science', 'Natural language processing uses machine learning to understand text', 'Python programming language is essential for machine learning developers', 'Python libraries like TensorFlow and PyTorch simplify machine learning', 'Deep learning neural networks enable advanced AI applications']

    混合搜索结合了关键词匹配(包含 "machine learning" 的文档)和语义搜索(与 "AI research" 语义相近的文档),通过 RRF(Reciprocal Rank Fusion)算法融合两路检索结果,返回最相关的文档。