From 34f4829f0e03c14b81a6f2300010dc085b257cc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B8=D1=80=D0=B8=D0=BB=D0=BB=20=D0=A0=D0=BE=D0=BC?= =?UTF-8?q?=D0=B0=D0=BD=D0=BE=D0=B2?= Date: Thu, 4 Jun 2026 23:24:01 +0000 Subject: [PATCH] Add src/rag_tools.py --- src/rag_tools.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/rag_tools.py diff --git a/src/rag_tools.py b/src/rag_tools.py new file mode 100644 index 0000000..fec20e3 --- /dev/null +++ b/src/rag_tools.py @@ -0,0 +1,24 @@ +"""Search tool for the Chroma vector store. + +The function `search_course_docs` performs a similarity search on the +persisted Chroma collection and returns the top *k* documents. +""" + +from typing import List + +from langchain_chroma import Chroma +from langchain_core.documents import Document + +from .config import CHROMA_DIR, CHROMA_TOP_K + +# Load the persistent store once – this is cheap because it just reads +# the SQLite file. +_chroma = Chroma(persist_directory=CHROMA_DIR) + +def search_course_docs(query: str, k: int = CHROMA_TOP_K) -> List[Document]: + """Return the top *k* documents that match *query*. + + The function is intentionally simple; it does not filter by metadata + because the FAQ files are small. + """ + return _chroma.similarity_search(query, k=k) \ No newline at end of file