Files
ai-agent-book/cursor-chats/20251014_193935_语义代码搜索部分,需要阅读知识库一节,重写,不是_codebert_这种,而是通用的向量数据库匹配和_bm25_searc.md
liqiang b119135836
Build latest book artifacts / build (push) Canceled after 0s
dependency resolution / resolve (3.11) (push) Canceled after 0s
dependency resolution / resolve (3.13) (push) Canceled after 0s
deploy-pages / build (push) Canceled after 0s
deploy-pages / deploy (push) Canceled after 0s
i18n consistency check / check (push) Canceled after 0s
provider adoption tests / test (chapter2/context-compression) (push) Canceled after 0s
provider adoption tests / test (chapter2/prompt-injection) (push) Canceled after 0s
provider adoption tests / test (chapter2/system-hint) (push) Canceled after 0s
provider adoption tests / test (chapter3/log-sanitization) (push) Canceled after 0s
web-search-agent tests / test (push) Canceled after 0s
web-search-agent tests / agentbook (push) Canceled after 0s
ai-agent-book 精选快照(<2MB 代码与文档,来自 github.com/bojieli/ai-agent-book)
2026-08-20 13:12:50 +00:00

3.2 KiB
Raw Permalink Blame History

Cursor Chat: ai-agent-book

Metadata

  • Project: ai-agent-book
  • Path: /Users/boj
  • Date: 2025-10-14 19:39:35
  • Session ID: 68360ff9-dd3a-4138-a58e-036c36501bd9

Conversation

👤 You

语义代码搜索部分,需要阅读知识库一节,重写,不是 codebert 这种,而是通用的向量数据库匹配和 bm25 search 匹配代码片段。在 chunking 的时候需要尽可能 aware 函数等代码片段的边界


👤 You

语义代码搜索部分,需要阅读 chapter 3 一章,重写内容。不是用 codebert 这种,而是通用的向量数据库匹配和 bm25 search 匹配代码片段。在 chunking 的时候需要尽可能 aware 函数等代码片段的边界


🤖 Cursor Assistant

我来帮你重写 chapter5.md 中关于语义代码搜索的部分。首先让我阅读相关的内容。


🤖 Cursor Assistant

我来重写 chapter5.md 中关于语义代码搜索的部分。首先让我看一下当前的内容位置,然后基于 chapter3 中的 RAG 技术来重新撰写。


🤖 Cursor Assistant

让我重新读取这部分内容以确保准确定位:


🤖 Cursor Assistant

完成!我已经成功重写了第五章中关于语义代码搜索的部分。主要改进包括:

主要变化

  1. 新增"代码分块:结构感知的切分策略"小节

    • 强调了代码具有严格的语法结构和语义边界
    • 介绍了基于抽象语法树(AST)的结构感知分块策略
    • 说明了如何将函数、类、方法作为完整的逻辑单元进行切分
    • 这是用户特别要求的重点——在 chunking 时要 aware 函数等代码片段的边界
  2. 重写"混合检索:稠密嵌入与 BM25 的协同"小节

    • 不再使用 CodeBERT 等专门的代码模型,改为强调通用的文本嵌入模型(如 BGE-M3、OpenAI text-embedding-3)同样有效
    • 详细介绍了**稠密嵌入(Dense Embedding)**的工作原理和优势
    • 引入了BM25 算法作为稀疏检索的核心技术
    • 说明了如何通过混合检索流水线将两者结合,使用 RRF 或加权组合方式融合结果
  3. 新增"向量索引的构建与维护"小节

    • 详细讨论了 HNSW 索引在代码搜索中的应用
    • 说明了 BM25 倒排索引的构建方法,特别提到了代码分词的特殊处理(如驼峰命名

👤 You

太长了,不要这么多细节,简单介绍就行


🤖 Cursor Assistant

我明白了,我写得太详细了。让我重新写一个更简洁的版本:


🤖 Cursor Assistant

好的!我已经大幅精简了内容,现在只用4段话就涵盖了核心要点:

  1. 结构感知的分块:通过AST解析识别函数、类等完整语义单元
  2. 混合检索策略:向量嵌入(BGE-M3等通用模型)+ BM25,通过RRF融合结果
  3. 技术实现HNSW索引 + 倒排索引

保留了原有的例子和应用场景说明,但删除了大量实现细节。这样既满足了你提到的技术要求(不用CodeBERT、使用通用向量数据库和BM25、chunking要aware代码边界),又保持了简洁。


Exported from Cursor View