Files
Ai/rag/retrieve.py
T
sajad-dev 2c42ebe01c Refactor user data handling and enhance chat functionality
- Removed deprecated user_info files and paths from configuration.
- Added user soil data integration in chat context to improve response accuracy.
- Updated build_rag_context and chat_rag_stream functions to include sensor_uuid for user-specific data retrieval.
- Enhanced load_sources function to load user data from the database.
- Implemented filtering in search_with_query and QdrantVectorStore to isolate user data based on sensor_uuid.
- Introduced Celery Beat schedule for periodic user data ingestion.
2026-02-27 20:06:46 +03:30

35 lines
1.0 KiB
Python

"""
بازیابی RAG: embed کوئری و جستجو در vector store
"""
from .config import load_rag_config, RAGConfig
from .embedding import embed_single
from .vector_store import QdrantVectorStore
def search_with_query(
query: str,
sensor_uuid: str,
limit: int = 5,
score_threshold: float | None = None,
config: RAGConfig | None = None,
) -> list[dict]:
"""
کوئری را embed می‌کند و در vector store جستجو می‌کند.
فقط chunks مربوط به sensor_uuid یا __global__ برمی‌گردد (ایزوله‌سازی کاربر).
Args:
sensor_uuid: شناسه سنسور کاربر — اجباری برای امنیت
Returns:
لیست نتایج با id, score, text, metadata
"""
cfg = config or load_rag_config()
query_vector = embed_single(query, config=cfg)
store = QdrantVectorStore(config=cfg)
return store.search(
query_vector=query_vector,
limit=limit,
score_threshold=score_threshold,
sensor_uuid=sensor_uuid,
)