本页介绍了 AlloyDB AI 向量搜索策略,并说明了何时使用每种策略。默认情况下,AlloyDB 使用 k 最近邻搜索 (KNN) 来查找与查询相似的矢量。向量索引会实现一种名为“近似最近邻 (ANN)”的搜索策略。创建矢量索引时,AlloyDB AI 会使用 ANN,其性能比 KNN 更好。请注意,选择向量索引时,您需要平衡查询延迟时间和检索率。
召回率衡量搜索功能检索给定查询的所有相关项的有效性。例如,假设您有 100 个嵌入,每个嵌入都代表数据库中的某个实体。您使用目标向量查询嵌入,并将结果限制为 10 个。KNN 向量搜索使用暴力计算方法查找 10 个最接近的向量,因此召回率为 100%。如果未创建或选择任何矢量搜索索引,AlloyDB AI 会默认使用此方法。在 AlloyDB for PostgreSQL 中创建矢量索引时,它通常会使用 ANN,后者可能会根据相似性对矢量进行分区,以便更快地检索。因此,使用 ANN 时,前面的示例中返回的 10 个矢量可能并不是距离最近的 10 个矢量。如果在检索到的 10 个向量中,只有 8 个向量在空间上与查询向量最接近,则召回率为 80%。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-03-06。"],[[["AlloyDB AI uses k-nearest neighbors (KNN) search by default to find vectors similar to a query, but using a vector index will use Approximate Nearest Neighbor (ANN) for better performance."],["Recall measures how effectively a search retrieves all relevant items, with KNN providing 100% recall by using a brute-force method, whereas ANN may have a slightly lower recall but faster retrieval."],["Query latency is the time it takes for a search to return results after a query is submitted."],["KNN search is recommended when accuracy is crucial and the number of vectors is under 100,000, while ANN is preferred for low latency and databases with more than 100,000 vectors."],["Creating a vector index, which utilizes ANN, is recommended by Google to optimize performance on vector search queries."]]],[]]