rtc-voice-chat/backend/services/rag_service.py

31 lines
798 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
最小可用的 RAG 服务占位实现。
当前版本支持两种简单来源:
- RAG_STATIC_CONTEXT直接写在环境变量中的固定知识
- RAG_CONTEXT_FILE读取本地文件全文作为知识上下文
后续如果要接真正的向量检索,可以直接替换 retrieve 方法实现。
"""
from __future__ import annotations
from pathlib import Path
from utils.env import env_str
class RagService:
async def retrieve(self, query: str) -> str:
_ = query
context_file = env_str("RAG_CONTEXT_FILE")
if context_file:
path = Path(context_file).expanduser()
if path.exists() and path.is_file():
return path.read_text(encoding="utf-8")
return env_str("RAG_STATIC_CONTEXT")
rag_service = RagService()