feat(rag): final refinements for Phase 4 support and UI visualization
This commit is contained in:
+26
-1
@@ -1,8 +1,12 @@
|
||||
import os
|
||||
import sys
|
||||
import asyncio
|
||||
import json
|
||||
from typing import List, Dict, Any, Optional
|
||||
import chromadb
|
||||
from chromadb.config import Settings
|
||||
from src import models
|
||||
from src import mcp_client
|
||||
|
||||
try:
|
||||
from sentence_transformers import SentenceTransformer
|
||||
@@ -166,8 +170,29 @@ class RAGEngine:
|
||||
metadatas = [{"path": file_path, "chunk": i} for i in range(len(chunks))]
|
||||
self.add_documents(ids, chunks, metadatas)
|
||||
|
||||
def _search_mcp(self, query: str, top_k: int = 5) -> List[Dict[str, Any]]:
|
||||
async def _async_search_mcp():
|
||||
tool_name = self.config.vector_store.mcp_tool or "rag_search"
|
||||
args = {"query": query, "top_k": top_k}
|
||||
res_str = await mcp_client.async_dispatch(tool_name, args)
|
||||
try:
|
||||
data = json.loads(res_str)
|
||||
if isinstance(data, list):
|
||||
return data
|
||||
elif isinstance(data, dict) and "results" in data:
|
||||
return data["results"]
|
||||
return []
|
||||
except:
|
||||
return []
|
||||
|
||||
return asyncio.run(_async_search_mcp())
|
||||
|
||||
def search(self, query: str, top_k: int = 5) -> List[Dict[str, Any]]:
|
||||
if not self.config.enabled or self.collection == "mock":
|
||||
if not self.config.enabled:
|
||||
return []
|
||||
if self.config.vector_store.provider == 'mcp':
|
||||
return self._search_mcp(query, top_k)
|
||||
if self.collection == "mock":
|
||||
return []
|
||||
|
||||
query_embedding = self.embedding_provider.embed([query])[0]
|
||||
|
||||
Reference in New Issue
Block a user