匠人学院 JR Academy
Google AI Essentials
AI Engineer
Google AI Essentials

An English entry point to JR Academy curated Google AI learning materials and practical references.

Google AI EssentialsEmbeddings 与向量检索

Embeddings 与 Vector Search 原理解析

Source: Google Cloud "Encoder-Decoder Architecture" & "Embeddings" Target: Machine Learning Engineers Estimated Time: 30 mins

#什么是 Embeddings (嵌入)?

在自然语言处理 (NLP) 中,计算机无法直接理解“猫”或“狗”这样的文字。Embeddings 就是将文字转换成一串数字(向量)的技术。

  • 核心思想: 语义相近的词,在向量空间中的距离也应该相近。
  • 维度 (Dimensions): 一个 Embedding 可能有 768 或 1536 个维度,每个维度代表某种潜在的语义特征。

Vector Space
Vector Space


#向量空间 (Vector Space)

想象一个多维空间:

  • King - Man + Woman ≈ Queen:这就是经典的向量运算例子。
  • 语义聚类: "Apple" 和 "Banana" 会聚在一起(水果),而与 "Dog" 距离很远。

#Vector Search (向量检索) 的挑战

当你有了数亿个向量时,如何快速找到与 Query 最相似的 Top-K 个向量? 传统的暴力计算(一一比对)太慢了。

#Google 的解决方案:ScaNN

Google 开源的 ScaNN (Scalable Nearest Neighbors) 算法是目前业界最快的近似最近邻搜索 (ANN) 算法之一。它通过量化和各向异性损失函数,实现了极高的检索速度和准确率。


#如何在 Google Cloud 上使用?

Google 将这些黑科技封装成了 Vertex AI Vector Search:

  1. Serverless: 不需要自己维护庞大的索引服务器。
  2. Low Latency: 支持毫秒级的亿级数据检索。
  3. Auto-scaling: 根据流量自动扩缩容。

Summary: Embeddings 是 AI 理解世界的“通用语言”。掌握了它,你就掌握了 RAG、推荐系统和语义搜索的钥匙。