You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

向量搜索可匹配无意义随机关键词?为何仍推荐混合搜索?

向量搜索匹配无意义关键词的疑问与混合搜索必要性探讨

我正在为基于LLM的项目做POC,使用向量数据库实现文档检索(IR)。之前看到主流向量数据库的博客推荐用**混合搜索(向量搜索+关键词搜索)**优化检索效果,尤其针对领域特定关键词。但在实现混合搜索前的测试中,我意外发现仅用向量搜索就能匹配查询中的领域特定关键词,甚至是随机生成的无意义词汇。

测试过程

  • 生成了一些无意义、不存在的关键词
  • 使用ChromaDB作为向量数据库,底层基于hnswlib实现近似最近邻搜索(ANN)

示例文档

[
    {
        "document_name": "Return Policy",
        "Category": "Fashion",
        "Product Name": "Zinsace",
        "Policy": "Customers can return the product within 14 days of purchase if it is unworn, with all tags attached and in its original condition. A refund will be provided in the original form of payment. However, customized or personalized Zinsace products are non-returnable."
    },
    {
        "document_name": "Return Policy",
        "Category": "Electronics",
        "Product Name": "Zisava",
        "Policy": "Customers can return the product within 30 days of purchase if it is unopened and in its original packaging. A refund will be issued in the original form of payment, excluding any shipping fees. However, Zisava products that have been used or show signs of damage are non-returnable."
    },
    {
        "document_name": "Return Policy",
        "Category": "Fashion",
        "Product Name": "Zinsape",
        "Policy": "Customers can return the product within 14 days of purchase if it is unworn, with all tags attached and in its original condition. A refund will be provided in the original form of payment. However, customized or personalized Zinsape products are non-returnable."
    },
    {
        "document_name": "Return Policy",
        "Category": "Electronics",
        "Product Name": "Zisada",
        "Policy": "Customers can return the product within 30 days of purchase if it is unopened and in its original packaging. A refund will be issued in the original form of payment, excluding any shipping fees. However, Zisada products that have been used or show signs of damage are non-returnable."
    }
]

索引与搜索脚本

import uuid

import chromadb
from chromadb.config import Settings
from chromadb.utils import embedding_functions

from hybrid.dummy_data import DUMMY_DATA

client = chromadb.Client(Settings(
    chroma_db_impl="duckdb+parquet",
    persist_directory="./hybrid"
))

openai_ef = embedding_functions.OpenAIEmbeddingFunction(
    api_key="XXXX",
    model_name="text-embedding-ada-002"
)

st_ef = embedding_functions.SentenceTransformerEmbeddingFunction(model_name='all-mpnet-base-v2')

# st_ef_mini = embedding_functions.SentenceTransformerEmbeddingFunction()

texts = [doc['Policy'] for doc in DUMMY_DATA]

metadatas = [{k: v for k, v in d.items() if k != 'Policy'} for d in DUMMY_DATA]

collection = client.get_or_create_collection(name="mpnet", metadata={'hnsw:space': 'l2'},
                                             embedding_function=st_ef)
ids = [str(uuid.uuid4()) for _ in texts]

collection.add(
    documents=texts,
    metadatas=metadatas,
    ids=ids
)

res = collection.query(
    query_texts=["I want to return Zinsace"],
    n_results=10
)

print(res.get('documents'))

输出结果

[
    [
        "Customers can return the product within 14 days of purchase if it is unworn, with all tags attached and in its original condition. A refund will be provided in the original form of payment. However, customized or personalized Zinsace products are non-returnable.",
        "Customers can return the product within 30 days of purchase if it is unopened and in its original packaging. A refund will be issued in the original form of payment, excluding any shipping fees. However, Zisada products that have been used or show signs of damage are non-returnable.",
        "Customers can return the product within 30 days of purchase if it is unopened and in its original packaging. A refund will be issued in the original form of payment, excluding any shipping fees. However, Zisava products that have been used or show signs of damage are non-returnable."
    ]
]

输出分析

  • 测试了3种嵌入模型:text-embedding-ada-002、all-mpnet-base-v2、all-MiniLM-L6-v2
  • 索引的文档均为包含随机无意义产品名的退货政策
  • 当查询为“I want to return Zinsace”或“I want to buy Zinsace”时,3种模型返回的首个结果都精准匹配了目标关键词

核心疑问

  1. 这些嵌入模型为何能为从未见过的无意义词汇生成可实现精准匹配的向量?
  2. 如果向量搜索已经能实现关键词匹配,为什么主流向量数据库还推荐使用混合搜索?是我的测试不够充分,还是存在认知偏差?

内容的提问来源于stack exchange,提问作者Swastik

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.18 15:07:53