1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"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": 2,
"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": 3,
"id": "b8382795-9610-4b24-80b7-31397b2faf90",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[32m2024-04-08 22:07:11.286\u001b[0m | \u001b[34m\u001b[1mDEBUG \u001b[0m | \u001b[36mrag.db.vector\u001b[0m:\u001b[36m__configure\u001b[0m:\u001b[36m37\u001b[0m - \u001b[34m\u001b[1mConfiguring collection knowledge-base...\u001b[0m\n",
"\u001b[32m2024-04-08 22:07:11.543\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": 4,
"id": "2c28db8c-c2bb-4092-b1d3-fd3f8bb060b5",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"rag.vector_db.client.delete_collection(\"knowledge-base\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0e664d3d-a787-45e5-8b71-8e5e0f348443",
"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
}
|