Global Rank · of 601 Skills
byted-bytehouse-hybrid-search AI Agent Skill
View Source: bytedance/agentkit-samples
SafeInstallation
npx skills add bytedance/agentkit-samples --skill byted-bytehouse-hybrid-search 11
Installs
ByteHouse 混合检索 Skill
🚀 快速开始
环境准备
pip install clickhouse-connect volcengine-python-sdk[ark] numpy scipy环境变量配置
优先从环境变量读取配置,禁止硬编码明文敏感信息:
# ByteHouse 配置
export BYTEHOUSE_HOST="<你的ByteHouse连接地址>"
export BYTEHOUSE_PORT="<ByteHouse端口>"
export BYTEHOUSE_USER="<ByteHouse用户名>"
export BYTEHOUSE_PASSWORD="<ByteHouse密码>"
export BYTEHOUSE_DATABASE="<默认数据库,可选,默认default>"
export BYTEHOUSE_SECURE="<是否启用加密,可选,默认true>"
# 火山引擎方舟 API 配置
export ARK_API_KEY="<火山引擎方舟API密钥>"
export ARK_BASE_URL="https://ark.cn-beijing.volces.com/api/v3"
export EMBEDDING_MODEL="doubao-embedding-vision-251215" # 文本向量化模型
export EMBEDDING_DIMENSIONS="1536" # 向量维度,可选,默认1536如果环境变量未配置,会自动提示用户输入。
📚 核心能力
1. 文本向量化
基于豆包文本向量化模型生成文本向量,支持任意长度中文文本。
2. 双索引构建
| 索引类型 | 说明 | 适用场景 |
|---|---|---|
| 全文倒排索引 | 基于BM25算法的全文检索,支持关键词匹配 | 精准关键词召回 |
| 向量索引 | 基于HNSW的向量相似度检索,支持语义匹配 | 语义相似召回 |
3. 核心功能
| 功能 | 方法 | 说明 |
|---|---|---|
| 全文检索 | fulltext_search() |
基于BM25的全文检索,返回BM25分数 |
| 向量检索 | vector_search() |
基于余弦相似度的向量检索,返回相似度分数 |
| 混合检索+RRF重排 | hybrid_search() |
双路召回后使用RRF算法重排,返回最终结果 |
| 自动生成向量 | insert_document()/batch_insert_documents() |
插入文档时自动生成向量并存储,无需手动处理 |
| 单个文档向量更新 | update_document_embedding() |
为单个文档重新生成并更新向量 |
| 批量补全缺失向量 | batch_update_missing_embeddings() |
自动扫描表中所有缺少向量的文档,批量生成并补全向量 |
4. RRF重排算法
Reciprocal Rank Fusion 算法,综合全文检索和向量检索的排名结果,公式:
score = Σ 1 / (k + rank)默认k=60,可自定义调整。
📖 代码实现
完整示例代码实现位于 scripts/ 目录:
scripts/embedding.py- 文本向量化模块scripts/hybrid_search_client.py- ByteHouse 混合检索客户端scripts/examples.py- 使用示例
快速使用
from scripts import ByteHouseHybridSearch
# 初始化客户端
search = ByteHouseHybridSearch(connection_type="http")
# 创建混合检索表(自动构建全文索引和向量索引)
search.create_hybrid_table("my_hybrid_index")
# 插入文档(自动生成向量 + 存储原始文本)
search.insert_document("my_hybrid_index", doc_id=1,
title="ByteHouse 混合检索",
content="ByteHouse 支持全文检索和向量检索,可实现混合检索能力")
# 混合检索(自动执行全文+向量检索,RRF重排返回结果)
results = search.hybrid_search("my_hybrid_index", query="ByteHouse检索能力", top_k=10)⚙️ 最佳实践
建表配置
CREATE TABLE {table_name} (
`doc_id` UInt64,
`title` String,
`content` String,
`embedding` Array(Float32),
-- 全文倒排索引(version=2支持BM25分数)
INDEX content_idx content TYPE inverted('standard', '{"version":"v2"}') GRANULARITY 1,
-- 向量索引(HNSW算法,余弦相似度)
INDEX embedding_idx embedding TYPE HNSW_SQ('DIM={vec_dimensions}', 'metric=COSINE', 'M=32', 'EF_CONSTRUCTION=256') GRANULARITY 1
)
ENGINE = MergeTree()
ORDER BY doc_id
SETTINGS
index_granularity = 1024,
enable_vector_index_preload = 1RRF参数调整
- 当全文检索结果更重要时,可降低
rrf_k值(推荐30-60) - 当向量检索结果更重要时,可提高
rrf_k值(推荐60-100)
🔗 参考文档
Installs
Security Audit
View Source
bytedance/agentkit-samples
More from this source
Power your AI Agents with
the best open-source models.
Drop-in OpenAI-compatible API. No data leaves Europe.
Explore Inference APIGLM
GLM 5
$1.00 / $3.20
per M tokens
Kimi
Kimi K2.5
$0.60 / $2.80
per M tokens
MiniMax
MiniMax M2.5
$0.30 / $1.20
per M tokens
Qwen
Qwen3.5 122B
$0.40 / $3.00
per M tokens
How to use this skill
Install byted-bytehouse-hybrid-search by running npx skills add bytedance/agentkit-samples --skill byted-bytehouse-hybrid-search in your project directory. Run the install command above in your project directory. The skill file will be downloaded from GitHub and placed in your project.
No configuration needed. Your AI agent (Claude Code, Cursor, Windsurf, etc.) automatically detects installed skills and uses them as context when generating code.
The skill enhances your agent's understanding of byted-bytehouse-hybrid-search, helping it follow established patterns, avoid common mistakes, and produce production-ready output.
What you get
Skills are plain-text instruction files — not executable code. They encode expert knowledge about frameworks, languages, or tools that your AI agent reads to improve its output. This means zero runtime overhead, no dependency conflicts, and full transparency: you can read and review every instruction before installing.
Compatibility
This skill works with any AI coding agent that supports the skills.sh format, including Claude Code (Anthropic), Cursor, Windsurf, Cline, Aider, and other tools that read project-level context files. Skills are framework-agnostic at the transport level — the content inside determines which language or framework it applies to.
Chat with 100+ AI Models in one App.
Use Claude, ChatGPT, Gemini alongside with EU-Hosted Models like Deepseek, GLM-5, Kimi K2.5 and many more.