feat: solution for 'Агент с RAG-памятью'

This commit is contained in:
2026-06-24 14:17:50 +03:00
commit 589a621340
10 changed files with 276 additions and 0 deletions
+53
View File
@@ -0,0 +1,53 @@
import os
from dotenv import load_dotenv
from langchain_ollama import Ollama
from langchain_community.embeddings import OllamaEmbeddings
from langchain.vectorstores import Qdrant
from qdrant_client import QdrantClient
from src.agent import RAGAgent
from src.chunk_document import chunk_document
def main() -> None:
# Load environment variables if any
load_dotenv()
# Initialize LLM and embeddings
llm = Ollama(model="llama3")
embeddings = OllamaEmbeddings(model="llama3")
# Connect to Qdrant (assumes Qdrant is running locally on port 6333)
qdrant_client = QdrantClient(host="localhost", port=6333)
vector_store = Qdrant(
client=qdrant_client,
collection_name="rag_collection",
embeddings=embeddings,
)
# Create the RAG agent
rag_agent = RAGAgent(llm=llm, vector_store=vector_store, chunk_document_func=chunk_document)
# Example documents to add to the vector store
sample_docs = [
"LangChain is a framework for developing applications powered by language models.",
"Qdrant is a vector database that can store embeddings and perform similarity search.",
"Ollama provides a lightweight interface to run LLMs locally.",
]
rag_agent.add_documents(sample_docs)
# Build the agent executor
agent_executor = rag_agent.create_agent()
print("RAG Agent is ready. Type your question (or 'exit' to quit).")
while True:
user_input = input(">>> ")
if user_input.lower() in {"exit", "quit"}:
print("Goodbye!")
break
try:
response = agent_executor.invoke({"input": user_input})
print(response["output"])
except Exception as e:
print(f"Error: {e}")
if __name__ == "__main__":
main()