{ "cells": [ { "cell_type": "code", "execution_count": 2, "id": "c1f56ae3-a056-4b31-bcab-27c2c97c00f1", "metadata": {}, "outputs": [], "source": [ "from pathlib import Path\n", "\n", "from importlib.util import find_spec\n", "if find_spec(\"rag\") is None:\n", " import sys\n", " sys.path.append('..')\n", "from rag.rag import RAG" ] }, { "cell_type": "code", "execution_count": 3, "id": "6b5cb12e-df7e-4532-b78b-216e11ed6161", "metadata": {}, "outputs": [], "source": [ "path = Path(\"/home/aktersnurra/projects/library/quant/math/a-signal-processing-perspective-on-financial-engineering.pdf\")" ] }, { "cell_type": "code", "execution_count": 4, "id": "b8382795-9610-4b24-80b7-31397b2faf90", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "\u001b[32m2024-04-07 21:14:48.364\u001b[0m | \u001b[34m\u001b[1mDEBUG \u001b[0m | \u001b[36mrag.db.vector\u001b[0m:\u001b[36m__configure\u001b[0m:\u001b[36m36\u001b[0m - \u001b[34m\u001b[1mCollection knowledge-base already exists...\u001b[0m\n", "\u001b[32m2024-04-07 21:14:48.368\u001b[0m | \u001b[34m\u001b[1mDEBUG \u001b[0m | \u001b[36mrag.db.document\u001b[0m:\u001b[36m__configure\u001b[0m:\u001b[36m25\u001b[0m - \u001b[34m\u001b[1mCreating documents table if it does not exist...\u001b[0m\n" ] } ], "source": [ "rag = RAG()" ] }, { "cell_type": "code", "execution_count": null, "id": "ac57e50d-1fc3-4fc9-90e5-5bdb97bd2f5e", "metadata": {}, "outputs": [], "source": [ "rag.add_pdf(path)\n" ] }, { "cell_type": "code", "execution_count": null, "id": "1c6b48d2-eb04-4a7c-8224-78aabfc7c887", "metadata": {}, "outputs": [], "source": [ "query = \"What is a factor model?\"" ] }, { "cell_type": "code", "execution_count": null, "id": "a95c8250-00b2-4cbc-a9c6-a76d14ef2da5", "metadata": {}, "outputs": [], "source": [ "rag.rag(query, \"quant researcher\", limit=5)" ] }, { "cell_type": "code", "execution_count": 8, "id": "2c28db8c-c2bb-4092-b1d3-fd3f8bb060b5", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rag.vector_db.client.delete_collection(\"knowledge-base\")" ] }, { "cell_type": "code", "execution_count": null, "id": "05f7068c-b4c6-47b2-ac62-79c021838500", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.8" } }, "nbformat": 4, "nbformat_minor": 5 }