feat: RAG混合检索系统完整实现 + 启动脚本修复
Some checks failed
构建并部署 AI Agent 服务 / deploy (push) Failing after 5m4s

- 实现了稠密+稀疏混合检索,使用 Qdrant 原生 RRF 融合
- 修复了 retriever.py 的 BaseRetriever 继承和稀疏向量包装问题
- 修复了 pipeline.py 的 Optional 导入问题
- 添加了稀疏 embedder 的缓存配置
- 简化了 vector_store.py,移除不必要的逻辑
- 修复了 start.sh 的 PROJECT_DIR 硬编码和端口配置问题
- 完善了 RAG 检索的测试文件
This commit is contained in:
2026-05-04 02:54:37 +08:00
parent 54ba2d3457
commit 8af82f8f7f
9 changed files with 461 additions and 157 deletions

View File

@@ -54,3 +54,5 @@ DOCSTORE_URI = _get_str("DOCSTORE_URI") or DB_URI
# ========== 其他配置 ==========
# 可以在此添加其他 RAG Core 专用的配置项
# 稀疏模型缓存路径
FASTEMBED_CACHE_PATH = _get_str("FASTEMBED_CACHE_PATH") or "./models/fastembed_cache"

View File

@@ -4,7 +4,7 @@ BM25 稀疏嵌入器
"""
from typing import List
from fastembed.sparse.sparse_text_embedding import SparseTextEmbedding
from app.config import FASTEMBED_CACHE_PATH
from .config import FASTEMBED_CACHE_PATH
class BM25SparseEmbedder:
"""BM25 稀疏嵌入包装器,与现有嵌入器风格统一"""

View File

@@ -14,8 +14,7 @@ from langchain_core.embeddings import Embeddings
from langchain_qdrant import QdrantVectorStore as LangchainQdrantVS
from qdrant_client import QdrantClient
from qdrant_client.http.models import (
Distance, VectorParams, SparseVectorParams, SparseIndexParams,
SparseIndexType, PointStruct, NamedSparseVector, NamedVector
Distance, VectorParams, SparseVectorParams, PointStruct
)
from httpx import RemoteProtocolError
from qdrant_client.http.exceptions import ResponseHandlingException
@@ -61,6 +60,7 @@ class QdrantVectorStore:
client=self.get_client(),
collection_name=self.collection_name,
embedding=self.embeddings,
vector_name="dense",
)
def get_client(self) -> QdrantClient:
@@ -134,19 +134,13 @@ class QdrantVectorStore:
vectors_config = {
"dense": VectorParams(
size=vector_size,
distance=Distance.COSINE,
optional=True
distance=Distance.COSINE
)
}
# 稀疏向量配置
# 稀疏向量配置(简化版,不使用特殊索引类型)
sparse_vectors_config = {
"sparse": SparseVectorParams(
index=SparseIndexParams(
type=SparseIndexType.MUTABLE
),
optional=True
)
"sparse": SparseVectorParams()
}
client.create_collection(
@@ -197,10 +191,7 @@ class QdrantVectorStore:
# 构造双向量
named_vectors = {
"dense": dense_vectors[j],
"sparse": NamedSparseVector(
name="sparse",
vector=sparse_vectors[j]
)
"sparse": sparse_vectors[j]
}
points.append(PointStruct(