Files
nexus/wiki/concepts/Vector-Embedding.md
2026-04-23 00:02:55 +08:00

54 lines
2.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: "Vector Embedding"
type: concept
last_updated: 2026-04-22
---
## Definition
将文本、图片、音频等非结构化数据通过深度学习模型转换为高维稠密向量dense vector使语义相似的内容在向量空间中彼此接近。
## How It Works
1. **编码Encoding**:文本经过 embedding 模型(如 BERT、OpenAI text-embedding-3-small、BGE-m3处理输出固定维度的实数向量常见维度384/768/1536/3072
2. **存储**向量存入向量数据库Qdrant、Pinecone、Weaviate或支持向量索引的数据库pgvector、SQLite + sqlite-vss
3. **检索**查询时将查询文本同样编码为向量在向量空间中搜索最近邻ANN 或 KNN
## Key Properties
| 属性 | 说明 |
|------|------|
| 维度dimensionality | 越高表达能力越强,但存储/计算成本更高 |
| 语义保持semantic preservation | 同义词/近义表达在空间中接近 |
| 可微性 | 支持通过梯度下降持续优化(对比学习) |
| 跨模态 | CLIP 等模型可实现图文跨模态检索 |
## Core Operations
- **余弦相似度**cosine similarity衡量方向一致性值域 [-1, 1]
- **点积**dot product值域无界embedding 已归一化时等价于余弦相似度
- **欧氏距离**L2 distance衡量绝对距离
## Applications
| 应用 | 说明 |
|------|------|
| RAG | 检索相关文档片段作为 LLM 上下文 |
| 语义去重 | [[Semantic-Deduplication]] — 识别语义重复内容 |
| 推荐系统 | 基于内容 embedding 找相似物品 |
| 聚类分析 | 将相似文档自动分组 |
## Tools & Models
- **OpenAI text-embedding-3-small**1536 维,性价比最高($0.02/1M tokens
- **BGE-m3**支持中文多语言开源FlagEmbedding
- **nomic-embed-text**:开源 768 维,支持本地部署
- **sqlite-vss**SQLite 扩展,支持向量 ANN 搜索
- **Qdrant**:开源向量数据库,支持过滤条件
## Connections
- [[Semantic-Deduplication]] — 向量嵌入的直接应用
- [[Knowledge-Base-RAG]] — RAG 的核心检索技术
- [[YouTube-Content-Pipeline]] — 用向量嵌入实现选题去重