base_rag/examples/quick_start.py

28 lines
788 B
Python

"""Base RAG 使用示例"""
from base_rag import BaseRAG
class SimpleRAG(BaseRAG):
def ingest(self, file_path: str):
documents = self.load_and_split_documents(file_path)
self.add_documents_to_vector_store(documents)
print(f"导入 {len(documents)} 个文档")
def query(self, question: str) -> str:
docs = self.similarity_search(question)
return f"找到 {len(docs)} 个相关文档"
if __name__ == "__main__":
# 本地模型配置
config = {
"type": "local",
"model_name": "sentence-transformers/all-MiniLM-L6-v2"
}
rag = SimpleRAG(embedding_config=config)
print("RAG初始化完成!")
# rag.ingest("your_document.txt")
# result = rag.query("你的问题")
# print(result)