跳转到内容

Vector Database(向量数据库)

知识库位置:FDE Knowledge Base/03 Engineering/AI Engineering/Vector Database/Vector-Database.md 术语不确定时,请查阅 Glossary(中英文术语表)。

Vector Database(向量数据库)或 Vector Search System(向量检索系统)负责保存或索引向量,并执行 Approximate Nearest-neighbor(近似最近邻)搜索。

核心行为:

Query Vector(查询向量)
↓
Vector Index(向量索引)
↓
Nearest Vectors(最近的向量)
↓
Relevant Records(相关记录)

Vector Search(向量检索)常出现在:

  • RAG(Retrieval-Augmented Generation,检索增强生成)
  • Semantic Search(语义检索)
  • Recommendation(推荐)
  • Similarity Matching(相似度匹配)

但 FDE 最重要的能力不是:

知道最多 Vector DB 产品。

而是:

判断项目是否真的需要单独引入 Vector Database(向量数据库)。


3. Vector Database Is Not Automatically Required(向量数据库不是必需品)

Section titled “3. Vector Database Is Not Automatically Required(向量数据库不是必需品)”

对于小到中等规模应用:

Existing Database(既有数据库)
+
Vector Extension(向量扩展)

可能已经足够。

或者:

Existing Search Engine(既有搜索引擎)

本身已经支持:

  • Vector Search(向量检索)
  • Keyword Search(关键词检索)
  • Metadata Filtering(元数据过滤)

因此原则:

Start with the simplest viable infrastructure.(从最简可行基础设施开始。)


FDE 主要关注以下能力。

基于相似度检索。


例如:

department = HR(部门 = 人力资源)
status = Active(状态 = 有效)
region = US(区域 = 美国)

结合:

Keyword(关键词)
+
Vector(向量)

企业知识会变化。

系统必须支持:

  • update(更新)
  • delete(删除)
  • reindex(重建索引)

数据量和 Query Volume(查询量)增长后是否还能工作。


5. Enterprise Requirements(企业级要求)

Section titled “5. Enterprise Requirements(企业级要求)”

企业场景除了 Vector Search 本身,还需要考虑:

Permission(权限)
Tenant Isolation(租户隔离)
Encryption(加密)
Backup(备份)
Monitoring(监控)
Availability(可用性)
Deletion(删除)
Audit(审计)

这些往往比纯 Search Benchmark(检索基准测试)更重要。


6. Metadata Filtering(元数据过滤)

Section titled “6. Metadata Filtering(元数据过滤)”

假设 Query(查询):

What is the travel policy?(差旅政策是什么?)

但用户只能访问:

region = US(区域 = 美国)
department = Sales(部门 = 销售)

检索必须结合这些条件。

因此:

Semantic Search(语义检索)
+
Metadata Filter(元数据过滤器)

通常是 Enterprise RAG(企业级 RAG)的基本要求。


7. Permission-aware Search(权限感知检索)

Section titled “7. Permission-aware Search(权限感知检索)”

更高风险场景需要:

User Identity(用户身份)
↓
Permission Context(权限上下文)
↓
Search Filter(检索过滤器)
↓
Allowed Results Only(仅允许的结果)

而不是:

Search Everything(检索全部)
↓
LLM hides unauthorized content(靠大语言模型隐藏未授权内容)

只用 Vector Search 容易在:

  • IDs(编号)
  • names(名称)
  • acronyms(缩写)
  • exact phrases(精确短语)

上表现不好。

Hybrid(混合检索):

Keyword Search(关键词检索)
+
Vector Search(向量检索)
+
Ranking / Reranking(排序/重排序)

是企业 Search(搜索)中非常常见的设计。


FDE 应关注:

  • collection / index(集合/索引)
  • partition(分区)
  • namespace(命名空间)
  • tenant(租户)
  • metadata schema(元数据结构)
  • update strategy(更新策略)

不要只关注:

top-k(前 K 条结果数)。


企业知识会不断变化。

需要定义:

Source Changed(来源变更)
↓
Detect(检测)
↓
Parse(解析)
↓
Chunk(分块)
↓
Embed(向量化)
↓
Update Index(更新索引)

以及:

Document Deleted(文档删除)
↓
Remove Vectors(删除向量)

否则会产生:

stale knowledge(过期知识)。


11. Common Selection Questions(常见选型问题)

Section titled “11. Common Selection Questions(常见选型问题)”

选择 Vector Search Infrastructure(向量检索基础设施)时问:

How many vectors?(有多少向量?)
How many queries per second?(每秒多少查询?)
Do we need hybrid search?(需要混合检索吗?)
Do we need strong metadata filtering?(需要强元数据过滤吗?)
Do we need ACL filtering?(需要 ACL,Access Control List,访问控制列表过滤吗?)
How often does data change?(数据变化频率如何?)
Do we already operate PostgreSQL / search engine?(已经在运维 PostgreSQL 数据库/搜索引擎吗?)
What operational capability does the team have?(团队有什么运维能力?)

12. Dedicated Vector DB vs Existing Database(专用向量库 vs 既有数据库)

Section titled “12. Dedicated Vector DB vs Existing Database(专用向量库 vs 既有数据库)”

优点:

  • vector-native capabilities(向量原生能力)
  • scale(规模)
  • specialized indexing(专用索引)

缺点:

  • new infrastructure(新增基础设施)
  • operations(运维)
  • cost(成本)
  • data duplication(数据冗余)

优点:

  • simpler(更简单)
  • existing skills(既有技能)
  • transactional integration(事务集成)

缺点:

  • may have scaling limits(可能有扩展上限)
  • fewer specialized features(专用功能较少)

13. Common Failure Modes(常见失败模式)

Section titled “13. Common Failure Modes(常见失败模式)”

Failure 1 — Introduce Vector DB Too Early(过早引入向量库)

Section titled “Failure 1 — Introduce Vector DB Too Early(过早引入向量库)”

Prototype(原型)数据只有几千条,却引入复杂平台。


Failure 2 — No Metadata Model(没有元数据模型)

Section titled “Failure 2 — No Metadata Model(没有元数据模型)”

所有信息只存:

text + vector(文本 + 向量)

之后无法:

  • filter(过滤)
  • version(版本管理)
  • permission(权限控制)
  • govern(治理)

Failure 3 — Stale Index(索引过期)

Section titled “Failure 3 — Stale Index(索引过期)”

Source(来源)已更新,但 Vector Index 没同步。


Failure 4 — ACL Leakage(权限泄漏)

Section titled “Failure 4 — ACL Leakage(权限泄漏)”

Vector Search 不支持足够的 Permission filtering(权限过滤)。


Failure 5 — Benchmark-driven Choice(基准驱动选型)

Section titled “Failure 5 — Benchmark-driven Choice(基准驱动选型)”

选择系统只看:

queries per second(每秒查询数)

但忽略团队根本不会维护。


14. FDE Decision Framework(FDE 决策框架)

Section titled “14. FDE Decision Framework(FDE 决策框架)”
Existing infrastructure sufficient?(既有基础设施够用吗?)
├─ Yes(够) → Prefer existing(优先用既有的)
└─ No(不够)
↓
Need specialized vector scale/features?(需要专用向量规模/特性吗?)
├─ Yes(需要) → Consider dedicated vector system(考虑专用向量系统)
└─ No(不需要) → Keep architecture simple(保持架构简单)

目标:

Level C — Design(C 级:设计)

能够:

  • 理解 index / filter / hybrid(索引/过滤/混合检索)
  • 做 infrastructure trade-off(基础设施权衡)
  • 设计 metadata(元数据)
  • 理解 ACL(访问控制列表)
  • 诊断 stale index(过期索引)

不要求成为 Vector Database 内核专家。