Features
RAG multi-channel retrieval service, providing:
- Vector semantic retrieval - Vector similarity search based on Milvus
- Rerank reranking - Fine-ranking of retrieval results
- Document storage - Save documents to the vector database
Usage
from services.rag_service.client import RAGServiceClient
client = RAGServiceClient()
# 健康检查
status = client.health()
Semantic retrieval
result = client.retrieve( query="Python asynchronous programming best practices", top_k=5, min_score=0.85, rerank=True ) print(result["results"])
Convenience method: get only the list of textstexts = client.retrieve_texts(query="Python asynchronous programming", top_k=5)
Save documentsclient.save(documents=[ {"text": "Document content...", "metadata": {"title": "Title", "url": "..."}} ])
## 返回格式
### retrieve
```json
{
"query": "Python 异步编程",
"results": [
{
"id": "abc123",
"text": "Python异步编程基于asyncio库...",
"score": 0.92,
"metadata": {"title": "Python官方文档", "url": "..."}
}
],
"total": 3,
"elapsed_ms": 45.2,
"from_cache": false
}
save
{
"saved_count": 5,
"collection_name": "websearch_results"
}