weaviate

Weaviate 向量搜索引擎

补充说明

Weaviate 是带 schema 的向量数据库,支持 BM25 与向量混合检索、模块化向量化和多租户。适合 RAG、语义搜索和知识库。

常用示例

Docker 启动:

docker run -d --name weaviate \
  -p 8080:8080 -p 50051:50051 \
  -e AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED=true \
  -e PERSISTENCE_DATA_PATH=/var/lib/weaviate \
  -v $(pwd)/weaviate:/var/lib/weaviate \
  semitechnologies/weaviate:1.27.0

创建 schema:

curl -X POST http://localhost:8080/v1/schema \
  -H 'Content-Type: application/json' \
  -d '{"classes":[{"class":"Document","vectorizer":"none","properties":[{"name":"content","dataType":["text"]}]}]}'

写入对象:

curl -X POST http://localhost:8080/v1/objects \
  -H 'Content-Type: application/json' \
  -d '{"class":"Document","properties":{"content":"如何排查磁盘满"},"vector":[0.1,0.2]}'

向量检索:

curl -X POST http://localhost:8080/v1/graphql \
  -H 'Content-Type: application/json' \
  -d '{"query":"{ Get { Document(nearVector:{vector:[0.1,0.2]}, limit:3){ content _additional { distance } } } }"}'

混合检索:

{
  Get {
    Document(hybrid: {query: "磁盘满", alpha: 0.5}, limit: 3) {
      content
    }
  }
}

易错点与排错

读完自测

合上页面,先回答,再展开对照。

  1. 写入对象失败并提示缺少向量,为什么?
  2. 查询结果为空,且 schema 的 class 名称大小写不一致,问题在哪?
  3. 混合检索结果权重失衡,调什么参数?
答案
  1. schema 使用了 vectorizer: none 但没有提供向量。
  2. class 名称大小写不一致会导致查询为空。
  3. 调 alpha,避免 BM25 和向量权重失衡。