LLMs/RAG.ipynb
2025-01-30 18:59:53 +03:30

1380 lines
108 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"id": "6a2d4624-4d76-4c52-a0f8-b353b6848549",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"این یک مشکل رایج است که اغلب به دلایل مختلف ایجاد می شود. برخی از عللن های متداول قطع اینترنت عبارتند از:\n",
"\n",
"1. اتصال نادرست: ممکن است اتصال شما با ارائه دهنده خدمات اینترنت (ISP) نادرست باشد، در نتیجه قطع دسترسی به اینترنت.\n",
"2. خطای شبکه: مشکلاتی مانند خرابی تجهیزات شبکه یا خطاهای مربوطه ممکن است باعث قطع اینترنت شوند.\n",
"3. مسدود بودن آدرس IP: اگر آدرس آی پی شما توسط ارائه دهنده خدمات اینترنت مسدود شود، نمی توانید به اینترنت دسترسی داشته باشید.\n",
"4. مصرف زیاد باند باس: اگر مصرف زیادی از باند باس در طول یک زمان خاص یا مداوم باشد، ممکن است موجب قطع اینترنت شود.\n",
"5. مشکلات تهدید کننده ایمنی: حملات سایبری و ویروس های رایانه ای نیز می توانند باعث قطع اینترنت شوند.\n",
"\n",
"از سوی دیگر، ارائه دهندگان خدمات اینترنت اغلب در نظر می گیرند که به دلیل مسائل فنی یا نگهداری شبکه، اینترنت را برای چند ساعت یا یک روز قطع کنند. در چنین مواردی معمولاً اطلاع رسانی قبلی داده نمی شود و زمانی که مشکل حل شد، اینترنت مجدداً قابل دسترسی است.\n",
"\n",
"در صورت تجربه قطع اینترنت، توصیه می شود که با ارائه دهنده خدمات اینترنت تماس بگیرید و از وضعیت اتصال خود آگاه شوید. در بسیاری از موارد، مشکلات به سرعت حل می شود و شما می توانید دوباره به اینترنت دسترسی داشته باشید.\n",
"این یک مشکل رایج است که اغلب به دلایل مختلف ایجاد می شود. برخی از عللن های متداول قطع اینترنت عبارتند از:\n",
"\n",
"1. اتصال نادرست: ممکن است اتصال شما با ارائه دهنده خدمات اینترنت (ISP) نادرست باشد، در نتیجه قطع دسترسی به اینترنت.\n",
"2. خطای شبکه: مشکلاتی مانند خرابی تجهیزات شبکه یا خطاهای مربوطه ممکن است باعث قطع اینترنت شوند.\n",
"3. مسدود بودن آدرس IP: اگر آدرس آی پی شما توسط ارائه دهنده خدمات اینترنت مسدود شود، نمی توانید به اینترنت دسترسی داشته باشید.\n",
"4. مصرف زیاد باند باس: اگر مصرف زیادی از باند باس در طول یک زمان خاص یا مداوم باشد، ممکن است موجب قطع اینترنت شود.\n",
"5. مشکلات تهدید کننده ایمنی: حملات سایبری و ویروس های رایانه ای نیز می توانند باعث قطع اینترنت شوند.\n",
"\n",
"از سوی دیگر، ارائه دهندگان خدمات اینترنت اغلب در نظر می گیرند که به دلیل مسائل فنی یا نگهداری شبکه، اینترنت را برای چند ساعت یا یک روز قطع کنند. در چنین مواردی معمولاً اطلاع رسانی قبلی داده نمی شود و زمانی که مشکل حل شد، اینترنت مجدداً قابل دسترسی است.\n",
"\n",
"در صورت تجربه قطع اینترنت، توصیه می شود که با ارائه دهنده خدمات اینترنت تماس بگیرید و از وضعیت اتصال خود آگاه شوید. در بسیاری از موارد، مشکلات به سرعت حل می شود و شما می توانید دوباره به اینترنت دسترسی داشته باشید.\n"
]
}
],
"source": [
"#Test Dorna\n",
"response: ChatResponse = chat(model='partai/dorna-llama3', messages=[\n",
" {\n",
" 'role': 'user',\n",
" 'content': 'چرا اینترنت قطع میشه؟',\n",
" },\n",
"])\n",
"print(response['message']['content'])\n",
"print(response.message.content)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "a312f740-400a-49a5-a79e-41195aa49746",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Collecting faiss-cpu\n",
" Downloading faiss_cpu-1.9.0.post1-cp311-cp311-win_amd64.whl.metadata (4.5 kB)\n",
"Collecting sentence-transformers\n",
" Downloading sentence_transformers-3.4.0-py3-none-any.whl.metadata (10 kB)\n",
"Requirement already satisfied: ollama in c:\\users\\asus\\anaconda3\\lib\\site-packages (0.4.7)\n",
"Requirement already satisfied: numpy in c:\\users\\asus\\anaconda3\\lib\\site-packages (1.26.4)\n",
"Requirement already satisfied: packaging in c:\\users\\asus\\anaconda3\\lib\\site-packages (from faiss-cpu) (23.1)\n",
"Collecting transformers<5.0.0,>=4.41.0 (from sentence-transformers)\n",
" Downloading transformers-4.48.1-py3-none-any.whl.metadata (44 kB)\n",
" ---------------------------------------- 0.0/44.4 kB ? eta -:--:--\n",
" --------- ------------------------------ 10.2/44.4 kB ? eta -:--:--\n",
" --------- ------------------------------ 10.2/44.4 kB ? eta -:--:--\n",
" -------------------------- ----------- 30.7/44.4 kB 220.2 kB/s eta 0:00:01\n",
" -------------------------- ----------- 30.7/44.4 kB 220.2 kB/s eta 0:00:01\n",
" -------------------------------------- 44.4/44.4 kB 168.2 kB/s eta 0:00:00\n",
"Requirement already satisfied: tqdm in c:\\users\\asus\\anaconda3\\lib\\site-packages (from sentence-transformers) (4.65.0)\n",
"Requirement already satisfied: torch>=1.11.0 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from sentence-transformers) (2.5.1)\n",
"Requirement already satisfied: scikit-learn in c:\\users\\asus\\anaconda3\\lib\\site-packages (from sentence-transformers) (1.2.2)\n",
"Requirement already satisfied: scipy in c:\\users\\asus\\anaconda3\\lib\\site-packages (from sentence-transformers) (1.11.4)\n",
"Collecting huggingface-hub>=0.20.0 (from sentence-transformers)\n",
" Downloading huggingface_hub-0.27.1-py3-none-any.whl.metadata (13 kB)\n",
"Requirement already satisfied: Pillow in c:\\users\\asus\\anaconda3\\lib\\site-packages (from sentence-transformers) (10.2.0)\n",
"Requirement already satisfied: httpx<0.29,>=0.27 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from ollama) (0.28.1)\n",
"Requirement already satisfied: pydantic<3.0.0,>=2.9.0 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from ollama) (2.10.5)\n",
"Requirement already satisfied: anyio in c:\\users\\asus\\anaconda3\\lib\\site-packages (from httpx<0.29,>=0.27->ollama) (4.2.0)\n",
"Requirement already satisfied: certifi in c:\\users\\asus\\anaconda3\\lib\\site-packages (from httpx<0.29,>=0.27->ollama) (2024.2.2)\n",
"Requirement already satisfied: httpcore==1.* in c:\\users\\asus\\anaconda3\\lib\\site-packages (from httpx<0.29,>=0.27->ollama) (1.0.7)\n",
"Requirement already satisfied: idna in c:\\users\\asus\\anaconda3\\lib\\site-packages (from httpx<0.29,>=0.27->ollama) (3.4)\n",
"Requirement already satisfied: h11<0.15,>=0.13 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from httpcore==1.*->httpx<0.29,>=0.27->ollama) (0.14.0)\n",
"Requirement already satisfied: filelock in c:\\users\\asus\\anaconda3\\lib\\site-packages (from huggingface-hub>=0.20.0->sentence-transformers) (3.13.1)\n",
"Requirement already satisfied: fsspec>=2023.5.0 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from huggingface-hub>=0.20.0->sentence-transformers) (2023.10.0)\n",
"Requirement already satisfied: pyyaml>=5.1 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from huggingface-hub>=0.20.0->sentence-transformers) (6.0.1)\n",
"Requirement already satisfied: requests in c:\\users\\asus\\anaconda3\\lib\\site-packages (from huggingface-hub>=0.20.0->sentence-transformers) (2.31.0)\n",
"Requirement already satisfied: typing-extensions>=3.7.4.3 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from huggingface-hub>=0.20.0->sentence-transformers) (4.12.2)\n",
"Requirement already satisfied: annotated-types>=0.6.0 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from pydantic<3.0.0,>=2.9.0->ollama) (0.7.0)\n",
"Requirement already satisfied: pydantic-core==2.27.2 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from pydantic<3.0.0,>=2.9.0->ollama) (2.27.2)\n",
"Requirement already satisfied: networkx in c:\\users\\asus\\anaconda3\\lib\\site-packages (from torch>=1.11.0->sentence-transformers) (3.1)\n",
"Requirement already satisfied: jinja2 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from torch>=1.11.0->sentence-transformers) (3.1.3)\n",
"Requirement already satisfied: sympy==1.13.1 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from torch>=1.11.0->sentence-transformers) (1.13.1)\n",
"Requirement already satisfied: mpmath<1.4,>=1.1.0 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from sympy==1.13.1->torch>=1.11.0->sentence-transformers) (1.3.0)\n",
"Requirement already satisfied: colorama in c:\\users\\asus\\anaconda3\\lib\\site-packages (from tqdm->sentence-transformers) (0.4.6)\n",
"Requirement already satisfied: regex!=2019.12.17 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from transformers<5.0.0,>=4.41.0->sentence-transformers) (2023.10.3)\n",
"Collecting tokenizers<0.22,>=0.21 (from transformers<5.0.0,>=4.41.0->sentence-transformers)\n",
" Downloading tokenizers-0.21.0-cp39-abi3-win_amd64.whl.metadata (6.9 kB)\n",
"Collecting safetensors>=0.4.1 (from transformers<5.0.0,>=4.41.0->sentence-transformers)\n",
" Downloading safetensors-0.5.2-cp38-abi3-win_amd64.whl.metadata (3.9 kB)\n",
"Requirement already satisfied: joblib>=1.1.1 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from scikit-learn->sentence-transformers) (1.2.0)\n",
"Requirement already satisfied: threadpoolctl>=2.0.0 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from scikit-learn->sentence-transformers) (2.2.0)\n",
"Requirement already satisfied: sniffio>=1.1 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from anyio->httpx<0.29,>=0.27->ollama) (1.3.0)\n",
"Requirement already satisfied: MarkupSafe>=2.0 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from jinja2->torch>=1.11.0->sentence-transformers) (2.1.3)\n",
"Requirement already satisfied: charset-normalizer<4,>=2 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from requests->huggingface-hub>=0.20.0->sentence-transformers) (2.0.4)\n",
"Requirement already satisfied: urllib3<3,>=1.21.1 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from requests->huggingface-hub>=0.20.0->sentence-transformers) (2.0.7)\n",
"Downloading faiss_cpu-1.9.0.post1-cp311-cp311-win_amd64.whl (13.8 MB)\n",
" ---------------------------------------- 0.0/13.8 MB ? eta -:--:--\n",
" ---------------------------------------- 0.0/13.8 MB ? eta -:--:--\n",
" ---------------------------------------- 0.0/13.8 MB ? eta -:--:--\n",
" ---------------------------------------- 0.0/13.8 MB ? eta -:--:--\n",
" ---------------------------------------- 0.0/13.8 MB ? eta -:--:--\n",
" ---------------------------------------- 0.1/13.8 MB 563.7 kB/s eta 0:00:25\n",
" ---------------------------------------- 0.1/13.8 MB 563.7 kB/s eta 0:00:25\n",
" --------------------------------------- 0.2/13.8 MB 751.6 kB/s eta 0:00:19\n",
" --------------------------------------- 0.2/13.8 MB 845.5 kB/s eta 0:00:17\n",
" --------------------------------------- 0.2/13.8 MB 689.6 kB/s eta 0:00:20\n",
" --------------------------------------- 0.3/13.8 MB 865.8 kB/s eta 0:00:16\n",
" - -------------------------------------- 0.4/13.8 MB 928.4 kB/s eta 0:00:15\n",
" - -------------------------------------- 0.4/13.8 MB 949.4 kB/s eta 0:00:15\n",
" - -------------------------------------- 0.6/13.8 MB 1.1 MB/s eta 0:00:13\n",
" - -------------------------------------- 0.6/13.8 MB 1.2 MB/s eta 0:00:12\n",
" -- ------------------------------------- 0.7/13.8 MB 1.2 MB/s eta 0:00:11\n",
" -- ------------------------------------- 0.9/13.8 MB 1.4 MB/s eta 0:00:10\n",
" --- ------------------------------------ 1.0/13.8 MB 1.5 MB/s eta 0:00:09\n",
" --- ------------------------------------ 1.2/13.8 MB 1.6 MB/s eta 0:00:09\n",
" --- ------------------------------------ 1.3/13.8 MB 1.6 MB/s eta 0:00:08\n",
" ---- ----------------------------------- 1.5/13.8 MB 1.7 MB/s eta 0:00:08\n",
" ---- ----------------------------------- 1.6/13.8 MB 1.8 MB/s eta 0:00:07\n",
" ---- ----------------------------------- 1.6/13.8 MB 1.8 MB/s eta 0:00:07\n",
" ---- ----------------------------------- 1.6/13.8 MB 1.7 MB/s eta 0:00:08\n",
" ---- ----------------------------------- 1.6/13.8 MB 1.7 MB/s eta 0:00:08\n",
" ---- ----------------------------------- 1.6/13.8 MB 1.7 MB/s eta 0:00:08\n",
" ---- ----------------------------------- 1.6/13.8 MB 1.7 MB/s eta 0:00:08\n",
" ------- -------------------------------- 2.7/13.8 MB 2.3 MB/s eta 0:00:05\n",
" ------- -------------------------------- 2.8/13.8 MB 2.3 MB/s eta 0:00:05\n",
" -------- ------------------------------- 2.9/13.8 MB 2.3 MB/s eta 0:00:05\n",
" --------- ------------------------------ 3.1/13.8 MB 2.4 MB/s eta 0:00:05\n",
" --------- ------------------------------ 3.3/13.8 MB 2.4 MB/s eta 0:00:05\n",
" --------- ------------------------------ 3.3/13.8 MB 2.4 MB/s eta 0:00:05\n",
" --------- ------------------------------ 3.4/13.8 MB 2.4 MB/s eta 0:00:05\n",
" --------- ------------------------------ 3.4/13.8 MB 2.3 MB/s eta 0:00:05\n",
" --------- ------------------------------ 3.4/13.8 MB 2.3 MB/s eta 0:00:05\n",
" --------- ------------------------------ 3.4/13.8 MB 2.3 MB/s eta 0:00:05\n",
" --------- ------------------------------ 3.4/13.8 MB 2.3 MB/s eta 0:00:05\n",
" --------- ------------------------------ 3.4/13.8 MB 2.3 MB/s eta 0:00:05\n",
" --------- ------------------------------ 3.4/13.8 MB 2.3 MB/s eta 0:00:05\n",
" --------- ------------------------------ 3.4/13.8 MB 2.3 MB/s eta 0:00:05\n",
" ----------- ---------------------------- 4.0/13.8 MB 2.3 MB/s eta 0:00:05\n",
" ------------ --------------------------- 4.4/13.8 MB 2.4 MB/s eta 0:00:05\n",
" ------------ --------------------------- 4.5/13.8 MB 2.4 MB/s eta 0:00:04\n",
" ------------ --------------------------- 4.5/13.8 MB 2.4 MB/s eta 0:00:04\n",
" -------------- ------------------------- 4.9/13.8 MB 2.5 MB/s eta 0:00:04\n",
" -------------- ------------------------- 5.1/13.8 MB 2.5 MB/s eta 0:00:04\n",
" --------------- ------------------------ 5.3/13.8 MB 2.6 MB/s eta 0:00:04\n",
" ---------------- ----------------------- 5.7/13.8 MB 2.7 MB/s eta 0:00:04\n",
" ----------------- ---------------------- 6.0/13.8 MB 2.8 MB/s eta 0:00:03\n",
" ------------------ --------------------- 6.4/13.8 MB 2.8 MB/s eta 0:00:03\n",
" ------------------ --------------------- 6.5/13.8 MB 2.9 MB/s eta 0:00:03\n",
" ------------------- -------------------- 6.7/13.8 MB 2.9 MB/s eta 0:00:03\n",
" -------------------- ------------------- 7.0/13.8 MB 3.0 MB/s eta 0:00:03\n",
" --------------------- ------------------ 7.3/13.8 MB 3.0 MB/s eta 0:00:03\n",
" --------------------- ------------------ 7.4/13.8 MB 3.0 MB/s eta 0:00:03\n",
" --------------------- ------------------ 7.6/13.8 MB 3.1 MB/s eta 0:00:03\n",
" ---------------------- ----------------- 7.9/13.8 MB 3.1 MB/s eta 0:00:02\n",
" ----------------------- ---------------- 8.3/13.8 MB 3.2 MB/s eta 0:00:02\n",
" ------------------------ --------------- 8.5/13.8 MB 3.2 MB/s eta 0:00:02\n",
" ------------------------- -------------- 8.8/13.8 MB 3.3 MB/s eta 0:00:02\n",
" -------------------------- ------------- 9.1/13.8 MB 3.3 MB/s eta 0:00:02\n",
" --------------------------- ------------ 9.4/13.8 MB 3.4 MB/s eta 0:00:02\n",
" --------------------------- ------------ 9.4/13.8 MB 3.4 MB/s eta 0:00:02\n",
" --------------------------- ------------ 9.4/13.8 MB 3.4 MB/s eta 0:00:02\n",
" ---------------------------- ----------- 9.8/13.8 MB 3.4 MB/s eta 0:00:02\n",
" ---------------------------- ----------- 9.8/13.8 MB 3.4 MB/s eta 0:00:02\n",
" ---------------------------- ----------- 9.8/13.8 MB 3.4 MB/s eta 0:00:02\n",
" ---------------------------- ----------- 9.8/13.8 MB 3.4 MB/s eta 0:00:02\n",
" ----------------------------- ---------- 10.3/13.8 MB 3.6 MB/s eta 0:00:01\n",
" ------------------------------ --------- 10.5/13.8 MB 3.7 MB/s eta 0:00:01\n",
" ------------------------------ --------- 10.6/13.8 MB 3.8 MB/s eta 0:00:01\n",
" ------------------------------- -------- 10.9/13.8 MB 3.9 MB/s eta 0:00:01\n",
" -------------------------------- ------- 11.1/13.8 MB 4.0 MB/s eta 0:00:01\n",
" -------------------------------- ------- 11.4/13.8 MB 4.0 MB/s eta 0:00:01\n",
" --------------------------------- ------ 11.6/13.8 MB 4.1 MB/s eta 0:00:01\n",
" ---------------------------------- ----- 11.9/13.8 MB 4.5 MB/s eta 0:00:01\n",
" ---------------------------------- ----- 12.1/13.8 MB 4.4 MB/s eta 0:00:01\n",
" ---------------------------------- ----- 12.1/13.8 MB 4.4 MB/s eta 0:00:01\n",
" ----------------------------------- ---- 12.2/13.8 MB 4.3 MB/s eta 0:00:01\n",
" ------------------------------------ --- 12.5/13.8 MB 4.2 MB/s eta 0:00:01\n",
" ------------------------------------- -- 12.8/13.8 MB 4.1 MB/s eta 0:00:01\n",
" ------------------------------------- -- 13.1/13.8 MB 4.2 MB/s eta 0:00:01\n",
" -------------------------------------- - 13.3/13.8 MB 4.2 MB/s eta 0:00:01\n",
" --------------------------------------- 13.6/13.8 MB 4.3 MB/s eta 0:00:01\n",
" --------------------------------------- 13.8/13.8 MB 5.0 MB/s eta 0:00:01\n",
" --------------------------------------- 13.8/13.8 MB 5.0 MB/s eta 0:00:01\n",
" ---------------------------------------- 13.8/13.8 MB 4.8 MB/s eta 0:00:00\n",
"Downloading sentence_transformers-3.4.0-py3-none-any.whl (275 kB)\n",
" ---------------------------------------- 0.0/275.7 kB ? eta -:--:--\n",
" ---------------------------------------- 0.0/275.7 kB ? eta -:--:--\n",
" ---------------------------------------- 0.0/275.7 kB ? eta -:--:--\n",
" ---- ----------------------------------- 30.7/275.7 kB ? eta -:--:--\n",
" ---- ----------------------------------- 30.7/275.7 kB ? eta -:--:--\n",
" ---------- ---------------------------- 71.7/275.7 kB 558.5 kB/s eta 0:00:01\n",
" ---------- ---------------------------- 71.7/275.7 kB 558.5 kB/s eta 0:00:01\n",
" ------------------- ------------------ 143.4/275.7 kB 655.8 kB/s eta 0:00:01\n",
" -------------------------- ----------- 194.6/275.7 kB 737.3 kB/s eta 0:00:01\n",
" ---------------------------- --------- 204.8/275.7 kB 692.4 kB/s eta 0:00:01\n",
" ------------------------------- ------ 225.3/275.7 kB 724.0 kB/s eta 0:00:01\n",
" -------------------------------------- 275.7/275.7 kB 737.5 kB/s eta 0:00:00\n",
"Downloading huggingface_hub-0.27.1-py3-none-any.whl (450 kB)\n",
" ---------------------------------------- 0.0/450.7 kB ? eta -:--:--\n",
" ---------- ----------------------------- 122.9/450.7 kB 3.6 MB/s eta 0:00:01\n",
" ------------ --------------------------- 143.4/450.7 kB 2.8 MB/s eta 0:00:01\n",
" --------------------------------------- 450.6/450.7 kB 3.1 MB/s eta 0:00:01\n",
" ---------------------------------------- 450.7/450.7 kB 3.1 MB/s eta 0:00:00\n",
"Downloading transformers-4.48.1-py3-none-any.whl (9.7 MB)\n",
" ---------------------------------------- 0.0/9.7 MB ? eta -:--:--\n",
" ---------------------------------------- 0.0/9.7 MB ? eta -:--:--\n",
" --------------------------------------- 0.1/9.7 MB 2.4 MB/s eta 0:00:04\n",
" --------------------------------------- 0.1/9.7 MB 2.1 MB/s eta 0:00:05\n",
" - -------------------------------------- 0.3/9.7 MB 2.0 MB/s eta 0:00:05\n",
" - -------------------------------------- 0.4/9.7 MB 2.0 MB/s eta 0:00:05\n",
" - -------------------------------------- 0.5/9.7 MB 2.2 MB/s eta 0:00:05\n",
" -- ------------------------------------- 0.7/9.7 MB 2.6 MB/s eta 0:00:04\n",
" --- ------------------------------------ 0.8/9.7 MB 2.5 MB/s eta 0:00:04\n",
" --- ------------------------------------ 0.9/9.7 MB 2.7 MB/s eta 0:00:04\n",
" ---- ----------------------------------- 1.2/9.7 MB 2.9 MB/s eta 0:00:03\n",
" ----- ---------------------------------- 1.3/9.7 MB 2.8 MB/s eta 0:00:04\n",
" ------ --------------------------------- 1.6/9.7 MB 3.1 MB/s eta 0:00:03\n",
" ------- -------------------------------- 1.7/9.7 MB 3.3 MB/s eta 0:00:03\n",
" -------- ------------------------------- 2.0/9.7 MB 3.5 MB/s eta 0:00:03\n",
" -------- ------------------------------- 2.1/9.7 MB 3.5 MB/s eta 0:00:03\n",
" --------- ------------------------------ 2.2/9.7 MB 3.3 MB/s eta 0:00:03\n",
" ---------- ----------------------------- 2.5/9.7 MB 3.4 MB/s eta 0:00:03\n",
" ---------- ----------------------------- 2.6/9.7 MB 3.5 MB/s eta 0:00:03\n",
" ---------- ----------------------------- 2.6/9.7 MB 3.5 MB/s eta 0:00:03\n",
" ------------ --------------------------- 2.9/9.7 MB 3.5 MB/s eta 0:00:02\n",
" ------------ --------------------------- 3.1/9.7 MB 3.5 MB/s eta 0:00:02\n",
" -------------- ------------------------- 3.4/9.7 MB 3.6 MB/s eta 0:00:02\n",
" --------------- ------------------------ 3.7/9.7 MB 3.7 MB/s eta 0:00:02\n",
" ---------------- ----------------------- 4.0/9.7 MB 3.8 MB/s eta 0:00:02\n",
" ----------------- ---------------------- 4.3/9.7 MB 3.9 MB/s eta 0:00:02\n",
" ------------------ --------------------- 4.5/9.7 MB 3.9 MB/s eta 0:00:02\n",
" ------------------- -------------------- 4.6/9.7 MB 4.0 MB/s eta 0:00:02\n",
" -------------------- ------------------- 4.9/9.7 MB 4.0 MB/s eta 0:00:02\n",
" --------------------- ------------------ 5.1/9.7 MB 4.1 MB/s eta 0:00:02\n",
" ---------------------- ----------------- 5.4/9.7 MB 4.1 MB/s eta 0:00:02\n",
" ----------------------- ---------------- 5.7/9.7 MB 4.2 MB/s eta 0:00:01\n",
" ------------------------ --------------- 5.9/9.7 MB 4.2 MB/s eta 0:00:01\n",
" ------------------------- -------------- 6.2/9.7 MB 4.3 MB/s eta 0:00:01\n",
" ------------------------- -------------- 6.3/9.7 MB 4.3 MB/s eta 0:00:01\n",
" --------------------------- ------------ 6.5/9.7 MB 4.3 MB/s eta 0:00:01\n",
" ---------------------------- ----------- 6.8/9.7 MB 4.4 MB/s eta 0:00:01\n",
" ---------------------------- ----------- 7.0/9.7 MB 4.3 MB/s eta 0:00:01\n",
" ----------------------------- ---------- 7.1/9.7 MB 4.3 MB/s eta 0:00:01\n",
" ------------------------------ --------- 7.4/9.7 MB 4.3 MB/s eta 0:00:01\n",
" ------------------------------- -------- 7.6/9.7 MB 4.3 MB/s eta 0:00:01\n",
" ------------------------------- -------- 7.6/9.7 MB 4.3 MB/s eta 0:00:01\n",
" ------------------------------- -------- 7.6/9.7 MB 4.3 MB/s eta 0:00:01\n",
" -------------------------------- ------- 8.0/9.7 MB 4.2 MB/s eta 0:00:01\n",
" --------------------------------- ------ 8.1/9.7 MB 4.2 MB/s eta 0:00:01\n",
" --------------------------------- ------ 8.2/9.7 MB 4.2 MB/s eta 0:00:01\n",
" --------------------------------- ------ 8.2/9.7 MB 4.1 MB/s eta 0:00:01\n",
" ---------------------------------- ----- 8.3/9.7 MB 4.0 MB/s eta 0:00:01\n",
" ---------------------------------- ----- 8.3/9.7 MB 4.0 MB/s eta 0:00:01\n",
" ---------------------------------- ----- 8.4/9.7 MB 3.9 MB/s eta 0:00:01\n",
" ----------------------------------- ---- 8.6/9.7 MB 3.9 MB/s eta 0:00:01\n",
" ------------------------------------ --- 8.7/9.7 MB 3.9 MB/s eta 0:00:01\n",
" ------------------------------------ --- 8.9/9.7 MB 3.9 MB/s eta 0:00:01\n",
" ------------------------------------- -- 9.1/9.7 MB 3.9 MB/s eta 0:00:01\n",
" -------------------------------------- - 9.3/9.7 MB 3.9 MB/s eta 0:00:01\n",
" --------------------------------------- 9.5/9.7 MB 3.9 MB/s eta 0:00:01\n",
" --------------------------------------- 9.6/9.7 MB 3.9 MB/s eta 0:00:01\n",
" --------------------------------------- 9.6/9.7 MB 3.9 MB/s eta 0:00:01\n",
" --------------------------------------- 9.7/9.7 MB 3.9 MB/s eta 0:00:01\n",
" ---------------------------------------- 9.7/9.7 MB 3.8 MB/s eta 0:00:00\n",
"Downloading safetensors-0.5.2-cp38-abi3-win_amd64.whl (303 kB)\n",
" ---------------------------------------- 0.0/303.8 kB ? eta -:--:--\n",
" - -------------------------------------- 10.2/303.8 kB ? eta -:--:--\n",
" - -------------------------------------- 10.2/303.8 kB ? eta -:--:--\n",
" --- ----------------------------------- 30.7/303.8 kB 330.3 kB/s eta 0:00:01\n",
" --------- ----------------------------- 71.7/303.8 kB 787.7 kB/s eta 0:00:01\n",
" ----------- --------------------------- 92.2/303.8 kB 525.1 kB/s eta 0:00:01\n",
" --------------------- ---------------- 174.1/303.8 kB 748.1 kB/s eta 0:00:01\n",
" ---------------------------- --------- 225.3/303.8 kB 860.2 kB/s eta 0:00:01\n",
" -------------------------------------- 303.8/303.8 kB 988.3 kB/s eta 0:00:00\n",
"Downloading tokenizers-0.21.0-cp39-abi3-win_amd64.whl (2.4 MB)\n",
" ---------------------------------------- 0.0/2.4 MB ? eta -:--:--\n",
" -- ------------------------------------- 0.1/2.4 MB 4.2 MB/s eta 0:00:01\n",
" --- ------------------------------------ 0.2/2.4 MB 2.9 MB/s eta 0:00:01\n",
" ------ --------------------------------- 0.4/2.4 MB 2.9 MB/s eta 0:00:01\n",
" -------- ------------------------------- 0.5/2.4 MB 2.8 MB/s eta 0:00:01\n",
" ------------ --------------------------- 0.7/2.4 MB 3.1 MB/s eta 0:00:01\n",
" --------------- ------------------------ 0.9/2.4 MB 3.3 MB/s eta 0:00:01\n",
" ------------------- -------------------- 1.1/2.4 MB 3.3 MB/s eta 0:00:01\n",
" --------------------- ------------------ 1.3/2.4 MB 3.5 MB/s eta 0:00:01\n",
" ------------------------ --------------- 1.5/2.4 MB 3.3 MB/s eta 0:00:01\n",
" ------------------------ --------------- 1.5/2.4 MB 3.3 MB/s eta 0:00:01\n",
" ------------------------ --------------- 1.5/2.4 MB 3.3 MB/s eta 0:00:01\n",
" --------------------------- ------------ 1.6/2.4 MB 2.7 MB/s eta 0:00:01\n",
" ---------------------------- ----------- 1.7/2.4 MB 2.6 MB/s eta 0:00:01\n",
" ------------------------------ --------- 1.8/2.4 MB 2.6 MB/s eta 0:00:01\n",
" -------------------------------- ------- 1.9/2.4 MB 2.6 MB/s eta 0:00:01\n",
" ---------------------------------- ----- 2.1/2.4 MB 2.7 MB/s eta 0:00:01\n",
" ------------------------------------- -- 2.2/2.4 MB 2.7 MB/s eta 0:00:01\n",
" -------------------------------------- - 2.3/2.4 MB 2.7 MB/s eta 0:00:01\n",
" --------------------------------------- 2.4/2.4 MB 2.6 MB/s eta 0:00:01\n",
" ---------------------------------------- 2.4/2.4 MB 2.5 MB/s eta 0:00:00\n",
"Installing collected packages: safetensors, faiss-cpu, huggingface-hub, tokenizers, transformers, sentence-transformers\n",
"Successfully installed faiss-cpu-1.9.0.post1 huggingface-hub-0.27.1 safetensors-0.5.2 sentence-transformers-3.4.0 tokenizers-0.21.0 transformers-4.48.1\n"
]
}
],
"source": [
"!pip install faiss-cpu sentence-transformers ollama numpy"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "9100712e-4b06-4168-b8ac-36f0c2865e42",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Building optimized index...\n",
"پردازش سوال 1/6 تکمیل شد\n",
"پردازش سوال 2/6 تکمیل شد\n",
"پردازش سوال 3/6 تکمیل شد\n",
"پردازش سوال 4/6 تکمیل شد\n",
"پردازش سوال 5/6 تکمیل شد\n",
"پردازش سوال 6/6 تکمیل شد\n",
"تمامی سوالات با موفقیت پردازش شدند!\n"
]
}
],
"source": [
"# MANUALLY RAG\n",
"from ollama import chat\n",
"import numpy as np\n",
"import faiss\n",
"from sentence_transformers import SentenceTransformer\n",
"import os\n",
"import re\n",
"\n",
"DOCUMENT_PATHS = [\n",
" r'C:\\Users\\ASUS\\Downloads\\Hamrah.txt', #replace path\n",
" r'C:\\Users\\ASUS\\Downloads\\vape.txt',\n",
" r'C:\\Users\\ASUS\\Downloads\\Shah.txt',\n",
" r'C:\\Users\\ASUS\\Downloads\\Khalife.txt',\n",
" r'C:\\Users\\ASUS\\Downloads\\carbon.txt',\n",
" r'C:\\Users\\ASUS\\Downloads\\takapoo.txt'\n",
"]\n",
"\n",
"EMBEDDING_MODEL = 'sentence-transformers/paraphrase-multilingual-mpnet-base-v2'\n",
"LLM_MODEL = 'partai/dorna-llama3'\n",
"CHUNK_SIZE = 1000\n",
"OVERLAP = 200\n",
"INDEX_PATH = r'C:\\Users\\ASUS\\Downloads\\doc_index.faiss'\n",
"CHUNK_MAP_PATH = r'C:\\Users\\ASUS\\Downloads\\chunk_map.npy'\n",
"\n",
"class AdvancedRAG:\n",
" def __init__(self):\n",
" self.encoder = SentenceTransformer(EMBEDDING_MODEL)\n",
" self.index = None\n",
" self.chunk_map = []\n",
" \n",
" def create_index(self):\n",
" \"\"\"Create FAISS index with cosine similarity and document mapping\"\"\"\n",
" all_chunks = []\n",
" doc_mapping = []\n",
" \n",
" # Process via CHUNKING (REQ 4 RAG)\n",
" for doc_idx, path in enumerate(DOCUMENT_PATHS):\n",
" with open(path, 'r', encoding='utf-8') as f:\n",
" text = re.sub(r'\\s+', ' ', f.read()).strip()\n",
" chunks = [text[i:i+CHUNK_SIZE] for i in range(0, len(text), CHUNK_SIZE - OVERLAP)]\n",
" all_chunks.extend(chunks)\n",
" doc_mapping.extend([doc_idx] * len(chunks))\n",
" \n",
" # Normalized embeddings (REQ 4 cosine similarity)\n",
" embeddings = self.encoder.encode(all_chunks)\n",
" faiss.normalize_L2(embeddings) \n",
" \n",
" # FAISS index & Mapping\n",
" self.index = faiss.IndexFlatIP(embeddings.shape[1])\n",
" self.index.add(embeddings.astype(np.float32))\n",
" self.chunk_map = np.array(doc_mapping)\n",
" \n",
" # Index \n",
" faiss.write_index(self.index, INDEX_PATH)\n",
" # Mapping \n",
" np.save(CHUNK_MAP_PATH, self.chunk_map)\n",
" \n",
" def load_index(self):\n",
" \"\"\"LOAD EXISTING DATA\"\"\"\n",
" self.index = faiss.read_index(INDEX_PATH)\n",
" self.chunk_map = np.load(CHUNK_MAP_PATH, allow_pickle=True)\n",
" \n",
" def query(self, question, doc_index, top_k=5):\n",
" \"\"\"DOCUMENT-SPECIFIC QUERY WITH COSINE SIMILARITY \"\"\"\n",
" # Encode \n",
" query_embed = self.encoder.encode([question])\n",
" # Normalize \n",
" faiss.normalize_L2(query_embed)\n",
" \n",
" distances, indices = self.index.search(query_embed.astype(np.float32), top_k*3)\n",
" \n",
" relevant_chunks = []\n",
" for idx in indices[0]:\n",
" if self.chunk_map[idx] == doc_index:\n",
" relevant_chunks.append(idx)\n",
" if len(relevant_chunks) >= top_k:\n",
" break\n",
" \n",
" return relevant_chunks\n",
"\n",
"class AnswerGenerator:\n",
" def __init__(self, rag_system):\n",
" self.rag = rag_system\n",
" self.chunks = [] \n",
" \n",
" def get_answer(self, question, doc_index):\n",
" \"\"\"GENERATING CONTEXT-AWARE ANSWER\"\"\"\n",
" if not self.chunks:\n",
" self._load_chunks()\n",
" \n",
" chunk_indices = self.rag.query(question, doc_index)\n",
" context = \"\\n\".join([self.chunks[idx] for idx in chunk_indices])\n",
" \n",
" prompt = f\"\"\"با استفاده از متن زیر به سوال پاسخ دهید:\n",
"{context}\n",
"\n",
"اگر پاسخ در متن وجود ندارد عبارت 'پاسخی یافت نشد' را برگردانید\n",
"\n",
"سوال: {question}\n",
"پاسخ:\"\"\"\n",
" \n",
" response = chat(model=LLM_MODEL, messages=[{'role': 'user', 'content': prompt}])\n",
" return response['message']['content']\n",
" \n",
" def _load_chunks(self):\n",
" \"\"\"LOAD ALL CHUNKS(LAZY)\"\"\"\n",
" self.chunks = []\n",
" for path in DOCUMENT_PATHS:\n",
" with open(path, 'r', encoding='utf-8') as f:\n",
" text = re.sub(r'\\s+', ' ', f.read()).strip()\n",
" self.chunks.extend([text[i:i+CHUNK_SIZE] for i in range(0, len(text), CHUNK_SIZE - OVERLAP)])\n",
"\n",
"# MAIN EXE of RAG\n",
"if __name__ == \"__main__\":\n",
" # RAG init\n",
" rag = AdvancedRAG()\n",
" \n",
" if not os.path.exists(INDEX_PATH):\n",
" print(\"Building optimized index...\")\n",
" rag.create_index()\n",
" else:\n",
" print(\"Loading existing index...\")\n",
" rag.load_index()\n",
" # Answer Generator init\n",
" generator = AnswerGenerator(rag)\n",
" \n",
" queries = [\n",
" (\"چرا اینترنت همراه اول گوشی وصل نمیشود؟\", 0),\n",
" (\"چطوری ویپ مورد نظرمو پیدا کنم؟\", 1),\n",
" (\"شاه عباس که بود؟\", 2),\n",
" (\"خلیفه سلطان که بود و چه کرد؟\", 3),\n",
" (\"کربن اکتیو و کربن بلک چه هستند و چه تفاوتی دارند و برای چه استفاده میشن؟\", 4),\n",
" (\"شرکت تکاپو صنعت نامی چه محصولاتی ارایه میدهد؟ چه چیزی این شرکت را منحصر به فرد میسازد؟ سهام این شرکت صعودی است یا نزولی؟\", 5)\n",
" ]\n",
" \n",
" with open(r'C:\\Users\\ASUS\\Downloads\\representation.txt', 'w', encoding='utf-8') as f: #replace path\n",
" for q_idx, (query, doc_idx) in enumerate(queries):\n",
" answer = generator.get_answer(query, doc_idx)\n",
" f.write(f\"سوال {q_idx+1} ({doc_idx+1}):\\n{query}\\n\\nپاسخ:\\n{answer}\\n\\n{'='*50}\\n\\n\")\n",
" print(f\"پردازش سوال {q_idx+1}/{len(queries)} تکمیل شد\")\n",
"\n",
"print(\"تمامی سوالات با موفقیت پردازش شدند!\")"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "1acad95b-6ae6-480a-98cc-29b0e38d2646",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Collecting langchain\n",
" Downloading langchain-0.3.16-py3-none-any.whl.metadata (7.1 kB)\n",
"Collecting chromadb\n",
" Downloading chromadb-0.6.3-py3-none-any.whl.metadata (6.8 kB)\n",
"Requirement already satisfied: sentence-transformers in c:\\users\\asus\\anaconda3\\lib\\site-packages (3.4.0)\n",
"Requirement already satisfied: ollama in c:\\users\\asus\\anaconda3\\lib\\site-packages (0.4.7)\n",
"Requirement already satisfied: PyYAML>=5.3 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from langchain) (6.0.1)\n",
"Requirement already satisfied: SQLAlchemy<3,>=1.4 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from langchain) (2.0.25)\n",
"Requirement already satisfied: aiohttp<4.0.0,>=3.8.3 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from langchain) (3.9.3)\n",
"Collecting langchain-core<0.4.0,>=0.3.32 (from langchain)\n",
" Downloading langchain_core-0.3.32-py3-none-any.whl.metadata (6.3 kB)\n",
"Collecting langchain-text-splitters<0.4.0,>=0.3.3 (from langchain)\n",
" Downloading langchain_text_splitters-0.3.5-py3-none-any.whl.metadata (2.3 kB)\n",
"Collecting langsmith<0.4,>=0.1.17 (from langchain)\n",
" Downloading langsmith-0.3.2-py3-none-any.whl.metadata (14 kB)\n",
"Requirement already satisfied: numpy<2,>=1.22.4 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from langchain) (1.26.4)\n",
"Requirement already satisfied: pydantic<3.0.0,>=2.7.4 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from langchain) (2.10.5)\n",
"Requirement already satisfied: requests<3,>=2 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from langchain) (2.31.0)\n",
"Requirement already satisfied: tenacity!=8.4.0,<10,>=8.1.0 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from langchain) (8.2.2)\n",
"Collecting build>=1.0.3 (from chromadb)\n",
" Downloading build-1.2.2.post1-py3-none-any.whl.metadata (6.5 kB)\n",
"Collecting chroma-hnswlib==0.7.6 (from chromadb)\n",
" Downloading chroma_hnswlib-0.7.6-cp311-cp311-win_amd64.whl.metadata (262 bytes)\n",
"Collecting fastapi>=0.95.2 (from chromadb)\n",
" Downloading fastapi-0.115.7-py3-none-any.whl.metadata (27 kB)\n",
"Collecting uvicorn>=0.18.3 (from uvicorn[standard]>=0.18.3->chromadb)\n",
" Downloading uvicorn-0.34.0-py3-none-any.whl.metadata (6.5 kB)\n",
"Collecting posthog>=2.4.0 (from chromadb)\n",
" Downloading posthog-3.11.0-py2.py3-none-any.whl.metadata (2.9 kB)\n",
"Requirement already satisfied: typing_extensions>=4.5.0 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from chromadb) (4.12.2)\n",
"Collecting onnxruntime>=1.14.1 (from chromadb)\n",
" Downloading onnxruntime-1.20.1-cp311-cp311-win_amd64.whl.metadata (4.7 kB)\n",
"Collecting opentelemetry-api>=1.2.0 (from chromadb)\n",
" Downloading opentelemetry_api-1.29.0-py3-none-any.whl.metadata (1.4 kB)\n",
"Collecting opentelemetry-exporter-otlp-proto-grpc>=1.2.0 (from chromadb)\n",
" Downloading opentelemetry_exporter_otlp_proto_grpc-1.29.0-py3-none-any.whl.metadata (2.2 kB)\n",
"Collecting opentelemetry-instrumentation-fastapi>=0.41b0 (from chromadb)\n",
" Downloading opentelemetry_instrumentation_fastapi-0.50b0-py3-none-any.whl.metadata (2.1 kB)\n",
"Collecting opentelemetry-sdk>=1.2.0 (from chromadb)\n",
" Downloading opentelemetry_sdk-1.29.0-py3-none-any.whl.metadata (1.5 kB)\n",
"Requirement already satisfied: tokenizers>=0.13.2 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from chromadb) (0.21.0)\n",
"Collecting pypika>=0.48.9 (from chromadb)\n",
" Downloading PyPika-0.48.9.tar.gz (67 kB)\n",
" ---------------------------------------- 0.0/67.3 kB ? eta -:--:--\n",
" ---------------------------------------- 0.0/67.3 kB ? eta -:--:--\n",
" ---------------------------------------- 0.0/67.3 kB ? eta -:--:--\n",
" ------------------ --------------------- 30.7/67.3 kB ? eta -:--:--\n",
" ------------------ --------------------- 30.7/67.3 kB ? eta -:--:--\n",
" -------------------------------------- 67.3/67.3 kB 523.1 kB/s eta 0:00:00\n",
" Installing build dependencies: started\n",
" Installing build dependencies: finished with status 'done'\n",
" Getting requirements to build wheel: started\n",
" Getting requirements to build wheel: finished with status 'done'\n",
" Preparing metadata (pyproject.toml): started\n",
" Preparing metadata (pyproject.toml): finished with status 'done'\n",
"Requirement already satisfied: tqdm>=4.65.0 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from chromadb) (4.65.0)\n",
"Requirement already satisfied: overrides>=7.3.1 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from chromadb) (7.4.0)\n",
"Collecting importlib-resources (from chromadb)\n",
" Downloading importlib_resources-6.5.2-py3-none-any.whl.metadata (3.9 kB)\n",
"Collecting grpcio>=1.58.0 (from chromadb)\n",
" Downloading grpcio-1.70.0-cp311-cp311-win_amd64.whl.metadata (4.0 kB)\n",
"Collecting bcrypt>=4.0.1 (from chromadb)\n",
" Downloading bcrypt-4.2.1-cp39-abi3-win_amd64.whl.metadata (10 kB)\n",
"Collecting typer>=0.9.0 (from chromadb)\n",
" Downloading typer-0.15.1-py3-none-any.whl.metadata (15 kB)\n",
"Collecting kubernetes>=28.1.0 (from chromadb)\n",
" Downloading kubernetes-32.0.0-py2.py3-none-any.whl.metadata (1.5 kB)\n",
"Collecting tenacity!=8.4.0,<10,>=8.1.0 (from langchain)\n",
" Downloading tenacity-9.0.0-py3-none-any.whl.metadata (1.2 kB)\n",
"Collecting mmh3>=4.0.1 (from chromadb)\n",
" Downloading mmh3-5.1.0-cp311-cp311-win_amd64.whl.metadata (16 kB)\n",
"Collecting orjson>=3.9.12 (from chromadb)\n",
" Downloading orjson-3.10.15-cp311-cp311-win_amd64.whl.metadata (42 kB)\n",
" ---------------------------------------- 0.0/42.9 kB ? eta -:--:--\n",
" ---------------------------------------- 0.0/42.9 kB ? eta -:--:--\n",
" ---------------------------- ----------- 30.7/42.9 kB 1.3 MB/s eta 0:00:01\n",
" ---------------------------- ----------- 30.7/42.9 kB 1.3 MB/s eta 0:00:01\n",
" -------------------------------------- 42.9/42.9 kB 297.0 kB/s eta 0:00:00\n",
"Requirement already satisfied: httpx>=0.27.0 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from chromadb) (0.28.1)\n",
"Requirement already satisfied: rich>=10.11.0 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from chromadb) (13.3.5)\n",
"Requirement already satisfied: transformers<5.0.0,>=4.41.0 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from sentence-transformers) (4.48.1)\n",
"Requirement already satisfied: torch>=1.11.0 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from sentence-transformers) (2.5.1)\n",
"Requirement already satisfied: scikit-learn in c:\\users\\asus\\anaconda3\\lib\\site-packages (from sentence-transformers) (1.2.2)\n",
"Requirement already satisfied: scipy in c:\\users\\asus\\anaconda3\\lib\\site-packages (from sentence-transformers) (1.11.4)\n",
"Requirement already satisfied: huggingface-hub>=0.20.0 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from sentence-transformers) (0.27.1)\n",
"Requirement already satisfied: Pillow in c:\\users\\asus\\anaconda3\\lib\\site-packages (from sentence-transformers) (10.2.0)\n",
"Requirement already satisfied: aiosignal>=1.1.2 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (1.2.0)\n",
"Requirement already satisfied: attrs>=17.3.0 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (23.1.0)\n",
"Requirement already satisfied: frozenlist>=1.1.1 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (1.4.0)\n",
"Requirement already satisfied: multidict<7.0,>=4.5 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (6.0.4)\n",
"Requirement already satisfied: yarl<2.0,>=1.0 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (1.9.3)\n",
"Requirement already satisfied: packaging>=19.1 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from build>=1.0.3->chromadb) (23.1)\n",
"Collecting pyproject_hooks (from build>=1.0.3->chromadb)\n",
" Downloading pyproject_hooks-1.2.0-py3-none-any.whl.metadata (1.3 kB)\n",
"Requirement already satisfied: colorama in c:\\users\\asus\\anaconda3\\lib\\site-packages (from build>=1.0.3->chromadb) (0.4.6)\n",
"Collecting starlette<0.46.0,>=0.40.0 (from fastapi>=0.95.2->chromadb)\n",
" Downloading starlette-0.45.3-py3-none-any.whl.metadata (6.3 kB)\n",
"Requirement already satisfied: anyio in c:\\users\\asus\\anaconda3\\lib\\site-packages (from httpx>=0.27.0->chromadb) (4.2.0)\n",
"Requirement already satisfied: certifi in c:\\users\\asus\\anaconda3\\lib\\site-packages (from httpx>=0.27.0->chromadb) (2024.2.2)\n",
"Requirement already satisfied: httpcore==1.* in c:\\users\\asus\\anaconda3\\lib\\site-packages (from httpx>=0.27.0->chromadb) (1.0.7)\n",
"Requirement already satisfied: idna in c:\\users\\asus\\anaconda3\\lib\\site-packages (from httpx>=0.27.0->chromadb) (3.4)\n",
"Requirement already satisfied: h11<0.15,>=0.13 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from httpcore==1.*->httpx>=0.27.0->chromadb) (0.14.0)\n",
"Requirement already satisfied: filelock in c:\\users\\asus\\anaconda3\\lib\\site-packages (from huggingface-hub>=0.20.0->sentence-transformers) (3.13.1)\n",
"Requirement already satisfied: fsspec>=2023.5.0 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from huggingface-hub>=0.20.0->sentence-transformers) (2023.10.0)\n",
"Requirement already satisfied: six>=1.9.0 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from kubernetes>=28.1.0->chromadb) (1.16.0)\n",
"Requirement already satisfied: python-dateutil>=2.5.3 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from kubernetes>=28.1.0->chromadb) (2.8.2)\n",
"Collecting google-auth>=1.0.1 (from kubernetes>=28.1.0->chromadb)\n",
" Downloading google_auth-2.38.0-py2.py3-none-any.whl.metadata (4.8 kB)\n",
"Requirement already satisfied: websocket-client!=0.40.0,!=0.41.*,!=0.42.*,>=0.32.0 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from kubernetes>=28.1.0->chromadb) (0.58.0)\n",
"Collecting requests-oauthlib (from kubernetes>=28.1.0->chromadb)\n",
" Downloading requests_oauthlib-2.0.0-py2.py3-none-any.whl.metadata (11 kB)\n",
"Collecting oauthlib>=3.2.2 (from kubernetes>=28.1.0->chromadb)\n",
" Downloading oauthlib-3.2.2-py3-none-any.whl.metadata (7.5 kB)\n",
"Requirement already satisfied: urllib3>=1.24.2 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from kubernetes>=28.1.0->chromadb) (2.0.7)\n",
"Collecting durationpy>=0.7 (from kubernetes>=28.1.0->chromadb)\n",
" Downloading durationpy-0.9-py3-none-any.whl.metadata (338 bytes)\n",
"Collecting jsonpatch<2.0,>=1.33 (from langchain-core<0.4.0,>=0.3.32->langchain)\n",
" Downloading jsonpatch-1.33-py2.py3-none-any.whl.metadata (3.0 kB)\n",
"Collecting packaging>=19.1 (from build>=1.0.3->chromadb)\n",
" Downloading packaging-24.2-py3-none-any.whl.metadata (3.2 kB)\n",
"Requirement already satisfied: requests-toolbelt<2.0.0,>=1.0.0 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from langsmith<0.4,>=0.1.17->langchain) (1.0.0)\n",
"Collecting zstandard<0.24.0,>=0.23.0 (from langsmith<0.4,>=0.1.17->langchain)\n",
" Downloading zstandard-0.23.0-cp311-cp311-win_amd64.whl.metadata (3.0 kB)\n",
"Collecting coloredlogs (from onnxruntime>=1.14.1->chromadb)\n",
" Downloading coloredlogs-15.0.1-py2.py3-none-any.whl.metadata (12 kB)\n",
"Collecting flatbuffers (from onnxruntime>=1.14.1->chromadb)\n",
" Downloading flatbuffers-25.1.24-py2.py3-none-any.whl.metadata (875 bytes)\n",
"Requirement already satisfied: protobuf in c:\\users\\asus\\anaconda3\\lib\\site-packages (from onnxruntime>=1.14.1->chromadb) (3.20.3)\n",
"Requirement already satisfied: sympy in c:\\users\\asus\\anaconda3\\lib\\site-packages (from onnxruntime>=1.14.1->chromadb) (1.13.1)\n",
"Collecting deprecated>=1.2.6 (from opentelemetry-api>=1.2.0->chromadb)\n",
" Downloading Deprecated-1.2.18-py2.py3-none-any.whl.metadata (5.7 kB)\n",
"Requirement already satisfied: importlib-metadata<=8.5.0,>=6.0 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from opentelemetry-api>=1.2.0->chromadb) (7.0.1)\n",
"Collecting googleapis-common-protos~=1.52 (from opentelemetry-exporter-otlp-proto-grpc>=1.2.0->chromadb)\n",
" Downloading googleapis_common_protos-1.66.0-py2.py3-none-any.whl.metadata (1.5 kB)\n",
"Collecting opentelemetry-exporter-otlp-proto-common==1.29.0 (from opentelemetry-exporter-otlp-proto-grpc>=1.2.0->chromadb)\n",
" Downloading opentelemetry_exporter_otlp_proto_common-1.29.0-py3-none-any.whl.metadata (1.8 kB)\n",
"Collecting opentelemetry-proto==1.29.0 (from opentelemetry-exporter-otlp-proto-grpc>=1.2.0->chromadb)\n",
" Downloading opentelemetry_proto-1.29.0-py3-none-any.whl.metadata (2.3 kB)\n",
"Collecting protobuf (from onnxruntime>=1.14.1->chromadb)\n",
" Downloading protobuf-5.29.3-cp310-abi3-win_amd64.whl.metadata (592 bytes)\n",
"Collecting opentelemetry-instrumentation-asgi==0.50b0 (from opentelemetry-instrumentation-fastapi>=0.41b0->chromadb)\n",
" Downloading opentelemetry_instrumentation_asgi-0.50b0-py3-none-any.whl.metadata (1.9 kB)\n",
"Collecting opentelemetry-instrumentation==0.50b0 (from opentelemetry-instrumentation-fastapi>=0.41b0->chromadb)\n",
" Downloading opentelemetry_instrumentation-0.50b0-py3-none-any.whl.metadata (6.1 kB)\n",
"Collecting opentelemetry-semantic-conventions==0.50b0 (from opentelemetry-instrumentation-fastapi>=0.41b0->chromadb)\n",
" Downloading opentelemetry_semantic_conventions-0.50b0-py3-none-any.whl.metadata (2.3 kB)\n",
"Collecting opentelemetry-util-http==0.50b0 (from opentelemetry-instrumentation-fastapi>=0.41b0->chromadb)\n",
" Downloading opentelemetry_util_http-0.50b0-py3-none-any.whl.metadata (2.5 kB)\n",
"Requirement already satisfied: wrapt<2.0.0,>=1.0.0 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from opentelemetry-instrumentation==0.50b0->opentelemetry-instrumentation-fastapi>=0.41b0->chromadb) (1.14.1)\n",
"Collecting asgiref~=3.0 (from opentelemetry-instrumentation-asgi==0.50b0->opentelemetry-instrumentation-fastapi>=0.41b0->chromadb)\n",
" Downloading asgiref-3.8.1-py3-none-any.whl.metadata (9.3 kB)\n",
"Collecting monotonic>=1.5 (from posthog>=2.4.0->chromadb)\n",
" Downloading monotonic-1.6-py2.py3-none-any.whl.metadata (1.5 kB)\n",
"Collecting backoff>=1.10.0 (from posthog>=2.4.0->chromadb)\n",
" Downloading backoff-2.2.1-py3-none-any.whl.metadata (14 kB)\n",
"Requirement already satisfied: annotated-types>=0.6.0 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from pydantic<3.0.0,>=2.7.4->langchain) (0.7.0)\n",
"Requirement already satisfied: pydantic-core==2.27.2 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from pydantic<3.0.0,>=2.7.4->langchain) (2.27.2)\n",
"Requirement already satisfied: charset-normalizer<4,>=2 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from requests<3,>=2->langchain) (2.0.4)\n",
"Requirement already satisfied: markdown-it-py<3.0.0,>=2.2.0 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from rich>=10.11.0->chromadb) (2.2.0)\n",
"Requirement already satisfied: pygments<3.0.0,>=2.13.0 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from rich>=10.11.0->chromadb) (2.15.1)\n",
"Requirement already satisfied: greenlet!=0.4.17 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from SQLAlchemy<3,>=1.4->langchain) (3.0.1)\n",
"Requirement already satisfied: networkx in c:\\users\\asus\\anaconda3\\lib\\site-packages (from torch>=1.11.0->sentence-transformers) (3.1)\n",
"Requirement already satisfied: jinja2 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from torch>=1.11.0->sentence-transformers) (3.1.3)\n",
"Requirement already satisfied: mpmath<1.4,>=1.1.0 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from sympy->onnxruntime>=1.14.1->chromadb) (1.3.0)\n",
"Requirement already satisfied: regex!=2019.12.17 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from transformers<5.0.0,>=4.41.0->sentence-transformers) (2023.10.3)\n",
"Requirement already satisfied: safetensors>=0.4.1 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from transformers<5.0.0,>=4.41.0->sentence-transformers) (0.5.2)\n",
"Requirement already satisfied: click>=8.0.0 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from typer>=0.9.0->chromadb) (8.1.7)\n",
"Collecting shellingham>=1.3.0 (from typer>=0.9.0->chromadb)\n",
" Downloading shellingham-1.5.4-py2.py3-none-any.whl.metadata (3.5 kB)\n",
"Collecting httptools>=0.6.3 (from uvicorn[standard]>=0.18.3->chromadb)\n",
" Downloading httptools-0.6.4-cp311-cp311-win_amd64.whl.metadata (3.7 kB)\n",
"Requirement already satisfied: python-dotenv>=0.13 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from uvicorn[standard]>=0.18.3->chromadb) (0.21.0)\n",
"Collecting watchfiles>=0.13 (from uvicorn[standard]>=0.18.3->chromadb)\n",
" Downloading watchfiles-1.0.4-cp311-cp311-win_amd64.whl.metadata (5.0 kB)\n",
"Collecting websockets>=10.4 (from uvicorn[standard]>=0.18.3->chromadb)\n",
" Downloading websockets-14.2-cp311-cp311-win_amd64.whl.metadata (7.0 kB)\n",
"Requirement already satisfied: joblib>=1.1.1 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from scikit-learn->sentence-transformers) (1.2.0)\n",
"Requirement already satisfied: threadpoolctl>=2.0.0 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from scikit-learn->sentence-transformers) (2.2.0)\n",
"Requirement already satisfied: cachetools<6.0,>=2.0.0 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from google-auth>=1.0.1->kubernetes>=28.1.0->chromadb) (4.2.2)\n",
"Requirement already satisfied: pyasn1-modules>=0.2.1 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from google-auth>=1.0.1->kubernetes>=28.1.0->chromadb) (0.2.8)\n",
"Collecting rsa<5,>=3.1.4 (from google-auth>=1.0.1->kubernetes>=28.1.0->chromadb)\n",
" Downloading rsa-4.9-py3-none-any.whl.metadata (4.2 kB)\n",
"Requirement already satisfied: zipp>=0.5 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from importlib-metadata<=8.5.0,>=6.0->opentelemetry-api>=1.2.0->chromadb) (3.17.0)\n",
"Requirement already satisfied: jsonpointer>=1.9 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from jsonpatch<2.0,>=1.33->langchain-core<0.4.0,>=0.3.32->langchain) (2.1)\n",
"Requirement already satisfied: mdurl~=0.1 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from markdown-it-py<3.0.0,>=2.2.0->rich>=10.11.0->chromadb) (0.1.0)\n",
"Requirement already satisfied: sniffio>=1.1 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from anyio->httpx>=0.27.0->chromadb) (1.3.0)\n",
"Collecting humanfriendly>=9.1 (from coloredlogs->onnxruntime>=1.14.1->chromadb)\n",
" Downloading humanfriendly-10.0-py2.py3-none-any.whl.metadata (9.2 kB)\n",
"Requirement already satisfied: MarkupSafe>=2.0 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from jinja2->torch>=1.11.0->sentence-transformers) (2.1.3)\n",
"Collecting pyreadline3 (from humanfriendly>=9.1->coloredlogs->onnxruntime>=1.14.1->chromadb)\n",
" Downloading pyreadline3-3.5.4-py3-none-any.whl.metadata (4.7 kB)\n",
"Requirement already satisfied: pyasn1<0.5.0,>=0.4.6 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from pyasn1-modules>=0.2.1->google-auth>=1.0.1->kubernetes>=28.1.0->chromadb) (0.4.8)\n",
"Downloading langchain-0.3.16-py3-none-any.whl (1.0 MB)\n",
" ---------------------------------------- 0.0/1.0 MB ? eta -:--:--\n",
" ---------------------------------------- 0.0/1.0 MB ? eta -:--:--\n",
" ---------------------------------------- 0.0/1.0 MB ? eta -:--:--\n",
" - -------------------------------------- 0.0/1.0 MB ? eta -:--:--\n",
" -- ------------------------------------- 0.1/1.0 MB 656.4 kB/s eta 0:00:02\n",
" --- ------------------------------------ 0.1/1.0 MB 919.0 kB/s eta 0:00:02\n",
" --- ------------------------------------ 0.1/1.0 MB 919.0 kB/s eta 0:00:02\n",
" ---- ----------------------------------- 0.1/1.0 MB 547.6 kB/s eta 0:00:02\n",
" ------- -------------------------------- 0.2/1.0 MB 787.7 kB/s eta 0:00:02\n",
" ----------- ---------------------------- 0.3/1.0 MB 1.0 MB/s eta 0:00:01\n",
" ---------------- ----------------------- 0.4/1.0 MB 1.2 MB/s eta 0:00:01\n",
" -------------------- ------------------- 0.5/1.0 MB 1.3 MB/s eta 0:00:01\n",
" -------------------------- ------------- 0.7/1.0 MB 1.4 MB/s eta 0:00:01\n",
" ---------------------------- ----------- 0.7/1.0 MB 1.5 MB/s eta 0:00:01\n",
" -------------------------------- ------- 0.8/1.0 MB 1.5 MB/s eta 0:00:01\n",
" ----------------------------------- ---- 0.9/1.0 MB 1.5 MB/s eta 0:00:01\n",
" --------------------------------------- 1.0/1.0 MB 1.6 MB/s eta 0:00:01\n",
" ---------------------------------------- 1.0/1.0 MB 1.6 MB/s eta 0:00:00\n",
"Downloading chromadb-0.6.3-py3-none-any.whl (611 kB)\n",
" ---------------------------------------- 0.0/611.1 kB ? eta -:--:--\n",
" ---- ----------------------------------- 71.7/611.1 kB 2.0 MB/s eta 0:00:01\n",
" --------------- ------------------------ 235.5/611.1 kB 2.4 MB/s eta 0:00:01\n",
" ----------------------- ---------------- 358.4/611.1 kB 2.8 MB/s eta 0:00:01\n",
" ------------------------------ --------- 471.0/611.1 kB 3.0 MB/s eta 0:00:01\n",
" --------------------------------------- 604.2/611.1 kB 2.9 MB/s eta 0:00:01\n",
" ---------------------------------------- 611.1/611.1 kB 2.8 MB/s eta 0:00:00\n",
"Downloading chroma_hnswlib-0.7.6-cp311-cp311-win_amd64.whl (151 kB)\n",
" ---------------------------------------- 0.0/151.9 kB ? eta -:--:--\n",
" ----------------------------- ---------- 112.6/151.9 kB 3.3 MB/s eta 0:00:01\n",
" ---------------------------------------- 151.9/151.9 kB 1.8 MB/s eta 0:00:00\n",
"Downloading bcrypt-4.2.1-cp39-abi3-win_amd64.whl (153 kB)\n",
" ---------------------------------------- 0.0/153.1 kB ? eta -:--:--\n",
" -------------------------------- ------- 122.9/153.1 kB 3.6 MB/s eta 0:00:01\n",
" ---------------------------------------- 153.1/153.1 kB 3.0 MB/s eta 0:00:00\n",
"Downloading build-1.2.2.post1-py3-none-any.whl (22 kB)\n",
"Downloading fastapi-0.115.7-py3-none-any.whl (94 kB)\n",
" ---------------------------------------- 0.0/94.8 kB ? eta -:--:--\n",
" ---------------------------------------- 94.8/94.8 kB 2.7 MB/s eta 0:00:00\n",
"Downloading grpcio-1.70.0-cp311-cp311-win_amd64.whl (4.3 MB)\n",
" ---------------------------------------- 0.0/4.3 MB ? eta -:--:--\n",
" - -------------------------------------- 0.1/4.3 MB 3.6 MB/s eta 0:00:02\n",
" -- ------------------------------------- 0.2/4.3 MB 2.8 MB/s eta 0:00:02\n",
" --- ------------------------------------ 0.3/4.3 MB 3.0 MB/s eta 0:00:02\n",
" --- ------------------------------------ 0.4/4.3 MB 2.7 MB/s eta 0:00:02\n",
" ----- ---------------------------------- 0.5/4.3 MB 2.8 MB/s eta 0:00:02\n",
" ----- ---------------------------------- 0.6/4.3 MB 2.9 MB/s eta 0:00:02\n",
" ------ --------------------------------- 0.7/4.3 MB 2.6 MB/s eta 0:00:02\n",
" -------- ------------------------------- 0.9/4.3 MB 2.7 MB/s eta 0:00:02\n",
" --------- ------------------------------ 1.0/4.3 MB 2.7 MB/s eta 0:00:02\n",
" ---------- ----------------------------- 1.1/4.3 MB 2.7 MB/s eta 0:00:02\n",
" ----------- ---------------------------- 1.2/4.3 MB 2.7 MB/s eta 0:00:02\n",
" ------------ --------------------------- 1.4/4.3 MB 2.7 MB/s eta 0:00:02\n",
" ------------- -------------------------- 1.5/4.3 MB 2.7 MB/s eta 0:00:02\n",
" --------------- ------------------------ 1.7/4.3 MB 2.7 MB/s eta 0:00:01\n",
" ---------------- ----------------------- 1.8/4.3 MB 2.8 MB/s eta 0:00:01\n",
" ------------------ --------------------- 2.0/4.3 MB 2.7 MB/s eta 0:00:01\n",
" ------------------- -------------------- 2.1/4.3 MB 2.7 MB/s eta 0:00:01\n",
" ------------------- -------------------- 2.1/4.3 MB 2.7 MB/s eta 0:00:01\n",
" --------------------- ------------------ 2.3/4.3 MB 2.7 MB/s eta 0:00:01\n",
" ---------------------- ----------------- 2.4/4.3 MB 2.7 MB/s eta 0:00:01\n",
" ----------------------- ---------------- 2.5/4.3 MB 2.7 MB/s eta 0:00:01\n",
" ------------------------- -------------- 2.7/4.3 MB 2.7 MB/s eta 0:00:01\n",
" -------------------------- ------------- 2.8/4.3 MB 2.7 MB/s eta 0:00:01\n",
" --------------------------- ------------ 2.9/4.3 MB 2.7 MB/s eta 0:00:01\n",
" --------------------------- ------------ 3.0/4.3 MB 2.7 MB/s eta 0:00:01\n",
" ----------------------------- ---------- 3.2/4.3 MB 2.7 MB/s eta 0:00:01\n",
" ------------------------------ --------- 3.3/4.3 MB 2.7 MB/s eta 0:00:01\n",
" ------------------------------- -------- 3.4/4.3 MB 2.7 MB/s eta 0:00:01\n",
" ------------------------------- -------- 3.4/4.3 MB 2.7 MB/s eta 0:00:01\n",
" --------------------------------- ------ 3.6/4.3 MB 2.7 MB/s eta 0:00:01\n",
" ----------------------------------- ---- 3.8/4.3 MB 2.6 MB/s eta 0:00:01\n",
" ----------------------------------- ---- 3.9/4.3 MB 2.7 MB/s eta 0:00:01\n",
" ------------------------------------ --- 4.0/4.3 MB 2.6 MB/s eta 0:00:01\n",
" -------------------------------------- - 4.1/4.3 MB 2.6 MB/s eta 0:00:01\n",
" --------------------------------------- 4.2/4.3 MB 2.7 MB/s eta 0:00:01\n",
" --------------------------------------- 4.3/4.3 MB 2.6 MB/s eta 0:00:01\n",
" ---------------------------------------- 4.3/4.3 MB 2.6 MB/s eta 0:00:00\n",
"Downloading kubernetes-32.0.0-py2.py3-none-any.whl (2.0 MB)\n",
" ---------------------------------------- 0.0/2.0 MB ? eta -:--:--\n",
" - -------------------------------------- 0.1/2.0 MB 2.6 MB/s eta 0:00:01\n",
" --- ------------------------------------ 0.2/2.0 MB 2.3 MB/s eta 0:00:01\n",
" ---- ----------------------------------- 0.2/2.0 MB 1.8 MB/s eta 0:00:01\n",
" ----- ---------------------------------- 0.3/2.0 MB 1.8 MB/s eta 0:00:01\n",
" ------- -------------------------------- 0.4/2.0 MB 1.9 MB/s eta 0:00:01\n",
" --------- ------------------------------ 0.5/2.0 MB 1.8 MB/s eta 0:00:01\n",
" ---------- ----------------------------- 0.5/2.0 MB 1.9 MB/s eta 0:00:01\n",
" -------------- ------------------------- 0.7/2.0 MB 2.1 MB/s eta 0:00:01\n",
" ----------------- ---------------------- 0.9/2.0 MB 2.1 MB/s eta 0:00:01\n",
" -------------------- ------------------- 1.0/2.0 MB 2.3 MB/s eta 0:00:01\n",
" --------------------- ------------------ 1.0/2.0 MB 2.2 MB/s eta 0:00:01\n",
" ------------------------ --------------- 1.2/2.0 MB 2.2 MB/s eta 0:00:01\n",
" --------------------------- ------------ 1.4/2.0 MB 2.3 MB/s eta 0:00:01\n",
" ------------------------------ --------- 1.5/2.0 MB 2.4 MB/s eta 0:00:01\n",
" ---------------------------------- ----- 1.7/2.0 MB 2.4 MB/s eta 0:00:01\n",
" ------------------------------------- -- 1.9/2.0 MB 2.5 MB/s eta 0:00:01\n",
" ---------------------------------------- 2.0/2.0 MB 2.5 MB/s eta 0:00:00\n",
"Downloading langchain_core-0.3.32-py3-none-any.whl (412 kB)\n",
" ---------------------------------------- 0.0/412.4 kB ? eta -:--:--\n",
" ------ --------------------------------- 71.7/412.4 kB 3.8 MB/s eta 0:00:01\n",
" ---------------------- ----------------- 235.5/412.4 kB 3.6 MB/s eta 0:00:01\n",
" ------------------------------------- -- 389.1/412.4 kB 3.0 MB/s eta 0:00:01\n",
" --------------------------------------- 409.6/412.4 kB 3.2 MB/s eta 0:00:01\n",
" --------------------------------------- 409.6/412.4 kB 3.2 MB/s eta 0:00:01\n",
" ---------------------------------------- 412.4/412.4 kB 1.5 MB/s eta 0:00:00\n",
"Downloading langchain_text_splitters-0.3.5-py3-none-any.whl (31 kB)\n",
"Downloading langsmith-0.3.2-py3-none-any.whl (333 kB)\n",
" ---------------------------------------- 0.0/333.0 kB ? eta -:--:--\n",
" ----------------- ---------------------- 143.4/333.0 kB 4.3 MB/s eta 0:00:01\n",
" ------------------------------------ --- 307.2/333.0 kB 3.8 MB/s eta 0:00:01\n",
" ---------------------------------------- 333.0/333.0 kB 2.6 MB/s eta 0:00:00\n",
"Downloading mmh3-5.1.0-cp311-cp311-win_amd64.whl (41 kB)\n",
" ---------------------------------------- 0.0/41.5 kB ? eta -:--:--\n",
" ---------------------------------------- 41.5/41.5 kB 2.0 MB/s eta 0:00:00\n",
"Downloading onnxruntime-1.20.1-cp311-cp311-win_amd64.whl (11.3 MB)\n",
" ---------------------------------------- 0.0/11.3 MB ? eta -:--:--\n",
" --------------------------------------- 0.1/11.3 MB 2.8 MB/s eta 0:00:04\n",
" --------------------------------------- 0.2/11.3 MB 3.0 MB/s eta 0:00:04\n",
" - -------------------------------------- 0.4/11.3 MB 2.5 MB/s eta 0:00:05\n",
" - -------------------------------------- 0.4/11.3 MB 2.2 MB/s eta 0:00:05\n",
" - -------------------------------------- 0.5/11.3 MB 2.2 MB/s eta 0:00:05\n",
" -- ------------------------------------- 0.7/11.3 MB 2.4 MB/s eta 0:00:05\n",
" --- ------------------------------------ 0.9/11.3 MB 2.5 MB/s eta 0:00:05\n",
" --- ------------------------------------ 1.0/11.3 MB 2.6 MB/s eta 0:00:04\n",
" --- ------------------------------------ 1.1/11.3 MB 2.6 MB/s eta 0:00:04\n",
" ---- ----------------------------------- 1.2/11.3 MB 2.6 MB/s eta 0:00:04\n",
" ---- ----------------------------------- 1.2/11.3 MB 2.5 MB/s eta 0:00:05\n",
" ---- ----------------------------------- 1.3/11.3 MB 2.3 MB/s eta 0:00:05\n",
" ---- ----------------------------------- 1.4/11.3 MB 2.3 MB/s eta 0:00:05\n",
" ----- ---------------------------------- 1.5/11.3 MB 2.4 MB/s eta 0:00:05\n",
" ----- ---------------------------------- 1.5/11.3 MB 2.2 MB/s eta 0:00:05\n",
" ----- ---------------------------------- 1.6/11.3 MB 2.2 MB/s eta 0:00:05\n",
" ------ --------------------------------- 1.7/11.3 MB 2.2 MB/s eta 0:00:05\n",
" ------ --------------------------------- 1.8/11.3 MB 2.2 MB/s eta 0:00:05\n",
" ------ --------------------------------- 2.0/11.3 MB 2.2 MB/s eta 0:00:05\n",
" ------- -------------------------------- 2.0/11.3 MB 2.2 MB/s eta 0:00:05\n",
" ------- -------------------------------- 2.2/11.3 MB 2.3 MB/s eta 0:00:04\n",
" ------- -------------------------------- 2.3/11.3 MB 2.3 MB/s eta 0:00:04\n",
" -------- ------------------------------- 2.4/11.3 MB 2.2 MB/s eta 0:00:05\n",
" -------- ------------------------------- 2.5/11.3 MB 2.2 MB/s eta 0:00:04\n",
" --------- ------------------------------ 2.5/11.3 MB 2.2 MB/s eta 0:00:04\n",
" --------- ------------------------------ 2.6/11.3 MB 2.2 MB/s eta 0:00:05\n",
" --------- ------------------------------ 2.7/11.3 MB 2.2 MB/s eta 0:00:04\n",
" --------- ------------------------------ 2.8/11.3 MB 2.2 MB/s eta 0:00:04\n",
" --------- ------------------------------ 2.8/11.3 MB 2.1 MB/s eta 0:00:05\n",
" ---------- ----------------------------- 2.9/11.3 MB 2.1 MB/s eta 0:00:04\n",
" ---------- ----------------------------- 2.9/11.3 MB 2.1 MB/s eta 0:00:05\n",
" ---------- ----------------------------- 3.0/11.3 MB 2.0 MB/s eta 0:00:05\n",
" ---------- ----------------------------- 3.0/11.3 MB 2.0 MB/s eta 0:00:05\n",
" ---------- ----------------------------- 3.1/11.3 MB 2.0 MB/s eta 0:00:05\n",
" ---------- ----------------------------- 3.1/11.3 MB 2.0 MB/s eta 0:00:05\n",
" ---------- ----------------------------- 3.1/11.3 MB 1.9 MB/s eta 0:00:05\n",
" ----------- ---------------------------- 3.1/11.3 MB 1.9 MB/s eta 0:00:05\n",
" ----------- ---------------------------- 3.2/11.3 MB 1.9 MB/s eta 0:00:05\n",
" ----------- ---------------------------- 3.2/11.3 MB 1.8 MB/s eta 0:00:05\n",
" ----------- ---------------------------- 3.2/11.3 MB 1.8 MB/s eta 0:00:05\n",
" ----------- ---------------------------- 3.2/11.3 MB 1.8 MB/s eta 0:00:05\n",
" ----------- ---------------------------- 3.2/11.3 MB 1.8 MB/s eta 0:00:05\n",
" ----------- ---------------------------- 3.3/11.3 MB 1.7 MB/s eta 0:00:05\n",
" ----------- ---------------------------- 3.3/11.3 MB 1.7 MB/s eta 0:00:05\n",
" ----------- ---------------------------- 3.3/11.3 MB 1.7 MB/s eta 0:00:05\n",
" ----------- ---------------------------- 3.4/11.3 MB 1.6 MB/s eta 0:00:05\n",
" ------------ --------------------------- 3.4/11.3 MB 1.6 MB/s eta 0:00:05\n",
" ------------ --------------------------- 3.5/11.3 MB 1.6 MB/s eta 0:00:05\n",
" ------------ --------------------------- 3.5/11.3 MB 1.6 MB/s eta 0:00:05\n",
" ------------ --------------------------- 3.7/11.3 MB 1.6 MB/s eta 0:00:05\n",
" ------------- -------------------------- 3.8/11.3 MB 1.7 MB/s eta 0:00:05\n",
" ------------- -------------------------- 3.9/11.3 MB 1.7 MB/s eta 0:00:05\n",
" -------------- ------------------------- 4.1/11.3 MB 1.7 MB/s eta 0:00:05\n",
" -------------- ------------------------- 4.2/11.3 MB 1.7 MB/s eta 0:00:05\n",
" --------------- ------------------------ 4.3/11.3 MB 1.8 MB/s eta 0:00:04\n",
" --------------- ------------------------ 4.4/11.3 MB 1.8 MB/s eta 0:00:04\n",
" ---------------- ----------------------- 4.6/11.3 MB 1.8 MB/s eta 0:00:04\n",
" ---------------- ----------------------- 4.8/11.3 MB 1.8 MB/s eta 0:00:04\n",
" ----------------- ---------------------- 4.9/11.3 MB 1.8 MB/s eta 0:00:04\n",
" ----------------- ---------------------- 5.0/11.3 MB 1.9 MB/s eta 0:00:04\n",
" ------------------ --------------------- 5.1/11.3 MB 1.9 MB/s eta 0:00:04\n",
" ------------------ --------------------- 5.3/11.3 MB 1.9 MB/s eta 0:00:04\n",
" ------------------ --------------------- 5.4/11.3 MB 1.9 MB/s eta 0:00:04\n",
" ------------------- -------------------- 5.6/11.3 MB 1.9 MB/s eta 0:00:03\n",
" ------------------- -------------------- 5.6/11.3 MB 1.9 MB/s eta 0:00:03\n",
" -------------------- ------------------- 5.8/11.3 MB 2.0 MB/s eta 0:00:03\n",
" --------------------- ------------------ 6.0/11.3 MB 2.0 MB/s eta 0:00:03\n",
" --------------------- ------------------ 6.1/11.3 MB 2.0 MB/s eta 0:00:03\n",
" ---------------------- ----------------- 6.2/11.3 MB 2.0 MB/s eta 0:00:03\n",
" ---------------------- ----------------- 6.4/11.3 MB 2.0 MB/s eta 0:00:03\n",
" ---------------------- ----------------- 6.5/11.3 MB 2.0 MB/s eta 0:00:03\n",
" ----------------------- ---------------- 6.6/11.3 MB 2.0 MB/s eta 0:00:03\n",
" ----------------------- ---------------- 6.8/11.3 MB 2.1 MB/s eta 0:00:03\n",
" ------------------------ --------------- 6.8/11.3 MB 2.1 MB/s eta 0:00:03\n",
" ------------------------ --------------- 7.0/11.3 MB 2.1 MB/s eta 0:00:03\n",
" ------------------------ --------------- 7.0/11.3 MB 2.1 MB/s eta 0:00:03\n",
" ------------------------- -------------- 7.2/11.3 MB 2.1 MB/s eta 0:00:02\n",
" ------------------------- -------------- 7.4/11.3 MB 2.1 MB/s eta 0:00:02\n",
" -------------------------- ------------- 7.5/11.3 MB 2.1 MB/s eta 0:00:02\n",
" -------------------------- ------------- 7.6/11.3 MB 2.1 MB/s eta 0:00:02\n",
" --------------------------- ------------ 7.7/11.3 MB 2.1 MB/s eta 0:00:02\n",
" --------------------------- ------------ 7.8/11.3 MB 2.1 MB/s eta 0:00:02\n",
" --------------------------- ------------ 7.9/11.3 MB 2.1 MB/s eta 0:00:02\n",
" ---------------------------- ----------- 8.0/11.3 MB 2.1 MB/s eta 0:00:02\n",
" ---------------------------- ----------- 8.1/11.3 MB 2.1 MB/s eta 0:00:02\n",
" ---------------------------- ----------- 8.1/11.3 MB 2.1 MB/s eta 0:00:02\n",
" ----------------------------- ---------- 8.2/11.3 MB 2.1 MB/s eta 0:00:02\n",
" ----------------------------- ---------- 8.3/11.3 MB 2.1 MB/s eta 0:00:02\n",
" ----------------------------- ---------- 8.4/11.3 MB 2.1 MB/s eta 0:00:02\n",
" ------------------------------ --------- 8.5/11.3 MB 2.1 MB/s eta 0:00:02\n",
" ------------------------------ --------- 8.6/11.3 MB 2.1 MB/s eta 0:00:02\n",
" ------------------------------ --------- 8.7/11.3 MB 2.1 MB/s eta 0:00:02\n",
" ------------------------------- -------- 8.8/11.3 MB 2.1 MB/s eta 0:00:02\n",
" ------------------------------- -------- 9.0/11.3 MB 2.1 MB/s eta 0:00:02\n",
" -------------------------------- ------- 9.1/11.3 MB 2.1 MB/s eta 0:00:02\n",
" -------------------------------- ------- 9.3/11.3 MB 2.1 MB/s eta 0:00:01\n",
" --------------------------------- ------ 9.4/11.3 MB 2.1 MB/s eta 0:00:01\n",
" --------------------------------- ------ 9.5/11.3 MB 2.1 MB/s eta 0:00:01\n",
" --------------------------------- ------ 9.6/11.3 MB 2.1 MB/s eta 0:00:01\n",
" ---------------------------------- ----- 9.7/11.3 MB 2.1 MB/s eta 0:00:01\n",
" ---------------------------------- ----- 9.8/11.3 MB 2.2 MB/s eta 0:00:01\n",
" ----------------------------------- ---- 9.9/11.3 MB 2.2 MB/s eta 0:00:01\n",
" ----------------------------------- ---- 10.0/11.3 MB 2.2 MB/s eta 0:00:01\n",
" ----------------------------------- ---- 10.2/11.3 MB 2.2 MB/s eta 0:00:01\n",
" ------------------------------------ --- 10.3/11.3 MB 2.2 MB/s eta 0:00:01\n",
" ------------------------------------- -- 10.5/11.3 MB 2.2 MB/s eta 0:00:01\n",
" ------------------------------------- -- 10.7/11.3 MB 2.2 MB/s eta 0:00:01\n",
" ------------------------------------- -- 10.7/11.3 MB 2.2 MB/s eta 0:00:01\n",
" -------------------------------------- - 10.9/11.3 MB 2.2 MB/s eta 0:00:01\n",
" -------------------------------------- - 11.0/11.3 MB 2.2 MB/s eta 0:00:01\n",
" --------------------------------------- 11.2/11.3 MB 2.2 MB/s eta 0:00:01\n",
" --------------------------------------- 11.3/11.3 MB 2.2 MB/s eta 0:00:01\n",
" --------------------------------------- 11.3/11.3 MB 2.2 MB/s eta 0:00:01\n",
" ---------------------------------------- 11.3/11.3 MB 2.2 MB/s eta 0:00:00\n",
"Downloading opentelemetry_api-1.29.0-py3-none-any.whl (64 kB)\n",
" ---------------------------------------- 0.0/64.3 kB ? eta -:--:--\n",
" ---------------------------------------- 0.0/64.3 kB ? eta -:--:--\n",
" ---------------------------------------- 0.0/64.3 kB ? eta -:--:--\n",
" ------------------- -------------------- 30.7/64.3 kB 1.4 MB/s eta 0:00:01\n",
" ------------------- -------------------- 30.7/64.3 kB 1.4 MB/s eta 0:00:01\n",
" -------------------------------------- - 61.4/64.3 kB 469.7 kB/s eta 0:00:01\n",
" ---------------------------------------- 64.3/64.3 kB 496.0 kB/s eta 0:00:00\n",
"Downloading opentelemetry_exporter_otlp_proto_grpc-1.29.0-py3-none-any.whl (18 kB)\n",
"Downloading opentelemetry_exporter_otlp_proto_common-1.29.0-py3-none-any.whl (18 kB)\n",
"Downloading opentelemetry_proto-1.29.0-py3-none-any.whl (55 kB)\n",
" ---------------------------------------- 0.0/55.8 kB ? eta -:--:--\n",
" ------------------------------------ --- 51.2/55.8 kB 1.3 MB/s eta 0:00:01\n",
" ---------------------------------------- 55.8/55.8 kB 1.5 MB/s eta 0:00:00\n",
"Downloading opentelemetry_instrumentation_fastapi-0.50b0-py3-none-any.whl (12 kB)\n",
"Downloading opentelemetry_instrumentation-0.50b0-py3-none-any.whl (30 kB)\n",
"Downloading opentelemetry_instrumentation_asgi-0.50b0-py3-none-any.whl (16 kB)\n",
"Downloading opentelemetry_semantic_conventions-0.50b0-py3-none-any.whl (166 kB)\n",
" ---------------------------------------- 0.0/166.6 kB ? eta -:--:--\n",
" ---------------------- ----------------- 92.2/166.6 kB 2.6 MB/s eta 0:00:01\n",
" ---------------------- ----------------- 92.2/166.6 kB 2.6 MB/s eta 0:00:01\n",
" --------------------------- ------------ 112.6/166.6 kB 1.1 MB/s eta 0:00:01\n",
" ------------------------------------- 163.8/166.6 kB 984.6 kB/s eta 0:00:01\n",
" -------------------------------------- 166.6/166.6 kB 909.1 kB/s eta 0:00:00\n",
"Downloading opentelemetry_util_http-0.50b0-py3-none-any.whl (6.9 kB)\n",
"Downloading opentelemetry_sdk-1.29.0-py3-none-any.whl (118 kB)\n",
" ---------------------------------------- 0.0/118.1 kB ? eta -:--:--\n",
" -------------------------------------- - 112.6/118.1 kB 3.3 MB/s eta 0:00:01\n",
" ---------------------------------------- 118.1/118.1 kB 3.5 MB/s eta 0:00:00\n",
"Downloading orjson-3.10.15-cp311-cp311-win_amd64.whl (133 kB)\n",
" ---------------------------------------- 0.0/133.6 kB ? eta -:--:--\n",
" ------------------------------ --------- 102.4/133.6 kB 2.9 MB/s eta 0:00:01\n",
" ---------------------------------------- 133.6/133.6 kB 2.6 MB/s eta 0:00:00\n",
"Downloading posthog-3.11.0-py2.py3-none-any.whl (72 kB)\n",
" ---------------------------------------- 0.0/72.0 kB ? eta -:--:--\n",
" ---------------------------------------- 72.0/72.0 kB 2.0 MB/s eta 0:00:00\n",
"Downloading tenacity-9.0.0-py3-none-any.whl (28 kB)\n",
"Downloading typer-0.15.1-py3-none-any.whl (44 kB)\n",
" ---------------------------------------- 0.0/44.9 kB ? eta -:--:--\n",
" ---------------------------------------- 44.9/44.9 kB 2.2 MB/s eta 0:00:00\n",
"Downloading uvicorn-0.34.0-py3-none-any.whl (62 kB)\n",
" ---------------------------------------- 0.0/62.3 kB ? eta -:--:--\n",
" ------ --------------------------------- 10.2/62.3 kB ? eta -:--:--\n",
" ---------------------------------------- 62.3/62.3 kB 826.6 kB/s eta 0:00:00\n",
"Downloading importlib_resources-6.5.2-py3-none-any.whl (37 kB)\n",
"Downloading backoff-2.2.1-py3-none-any.whl (15 kB)\n",
"Downloading Deprecated-1.2.18-py2.py3-none-any.whl (10.0 kB)\n",
"Downloading durationpy-0.9-py3-none-any.whl (3.5 kB)\n",
"Downloading google_auth-2.38.0-py2.py3-none-any.whl (210 kB)\n",
" ---------------------------------------- 0.0/210.8 kB ? eta -:--:--\n",
" ------------- -------------------------- 71.7/210.8 kB 2.0 MB/s eta 0:00:01\n",
" ----------------------- ---------------- 122.9/210.8 kB 2.4 MB/s eta 0:00:01\n",
" ---------------------------------------- 210.8/210.8 kB 2.1 MB/s eta 0:00:00\n",
"Downloading googleapis_common_protos-1.66.0-py2.py3-none-any.whl (221 kB)\n",
" ---------------------------------------- 0.0/221.7 kB ? eta -:--:--\n",
" ------------------------- -------------- 143.4/221.7 kB 2.8 MB/s eta 0:00:01\n",
" ------------------------------------ --- 204.8/221.7 kB 2.5 MB/s eta 0:00:01\n",
" ---------------------------------------- 221.7/221.7 kB 1.9 MB/s eta 0:00:00\n",
"Downloading httptools-0.6.4-cp311-cp311-win_amd64.whl (88 kB)\n",
" ---------------------------------------- 0.0/88.6 kB ? eta -:--:--\n",
" ---------------------------------------- 88.6/88.6 kB 2.4 MB/s eta 0:00:00\n",
"Downloading jsonpatch-1.33-py2.py3-none-any.whl (12 kB)\n",
"Downloading monotonic-1.6-py2.py3-none-any.whl (8.2 kB)\n",
"Downloading oauthlib-3.2.2-py3-none-any.whl (151 kB)\n",
" ---------------------------------------- 0.0/151.7 kB ? eta -:--:--\n",
" ------------------ --------------------- 71.7/151.7 kB 2.0 MB/s eta 0:00:01\n",
" ---------------------------------------- 151.7/151.7 kB 2.2 MB/s eta 0:00:00\n",
"Downloading packaging-24.2-py3-none-any.whl (65 kB)\n",
" ---------------------------------------- 0.0/65.5 kB ? eta -:--:--\n",
" ---------------------------------------- 65.5/65.5 kB 1.7 MB/s eta 0:00:00\n",
"Downloading protobuf-5.29.3-cp310-abi3-win_amd64.whl (434 kB)\n",
" ---------------------------------------- 0.0/434.5 kB ? eta -:--:--\n",
" -------------- ------------------------- 153.6/434.5 kB 3.1 MB/s eta 0:00:01\n",
" ----------------------------------- ---- 389.1/434.5 kB 4.0 MB/s eta 0:00:01\n",
" ---------------------------------------- 434.5/434.5 kB 3.4 MB/s eta 0:00:00\n",
"Downloading shellingham-1.5.4-py2.py3-none-any.whl (9.8 kB)\n",
"Downloading starlette-0.45.3-py3-none-any.whl (71 kB)\n",
" ---------------------------------------- 0.0/71.5 kB ? eta -:--:--\n",
" ---------------------------------------- 71.5/71.5 kB ? eta 0:00:00\n",
"Downloading watchfiles-1.0.4-cp311-cp311-win_amd64.whl (284 kB)\n",
" ---------------------------------------- 0.0/284.2 kB ? eta -:--:--\n",
" ------------ --------------------------- 92.2/284.2 kB 2.6 MB/s eta 0:00:01\n",
" -------------------------------------- - 276.5/284.2 kB 3.4 MB/s eta 0:00:01\n",
" ---------------------------------------- 284.2/284.2 kB 2.9 MB/s eta 0:00:00\n",
"Downloading websockets-14.2-cp311-cp311-win_amd64.whl (164 kB)\n",
" ---------------------------------------- 0.0/164.4 kB ? eta -:--:--\n",
" --------------------------------------- 163.8/164.4 kB 5.0 MB/s eta 0:00:01\n",
" ---------------------------------------- 164.4/164.4 kB 3.3 MB/s eta 0:00:00\n",
"Downloading zstandard-0.23.0-cp311-cp311-win_amd64.whl (495 kB)\n",
" ---------------------------------------- 0.0/495.4 kB ? eta -:--:--\n",
" -------- ------------------------------- 102.4/495.4 kB 5.8 MB/s eta 0:00:01\n",
" ----------------------- ---------------- 286.7/495.4 kB 3.5 MB/s eta 0:00:01\n",
" ------------------------------------ --- 450.6/495.4 kB 3.5 MB/s eta 0:00:01\n",
" ---------------------------------------- 495.4/495.4 kB 3.4 MB/s eta 0:00:00\n",
"Downloading coloredlogs-15.0.1-py2.py3-none-any.whl (46 kB)\n",
" ---------------------------------------- 0.0/46.0 kB ? eta -:--:--\n",
" ---------------------------------------- 46.0/46.0 kB 2.2 MB/s eta 0:00:00\n",
"Downloading flatbuffers-25.1.24-py2.py3-none-any.whl (30 kB)\n",
"Downloading pyproject_hooks-1.2.0-py3-none-any.whl (10 kB)\n",
"Downloading requests_oauthlib-2.0.0-py2.py3-none-any.whl (24 kB)\n",
"Downloading asgiref-3.8.1-py3-none-any.whl (23 kB)\n",
"Downloading humanfriendly-10.0-py2.py3-none-any.whl (86 kB)\n",
" ---------------------------------------- 0.0/86.8 kB ? eta -:--:--\n",
" ---------------------------------------- 86.8/86.8 kB 2.5 MB/s eta 0:00:00\n",
"Downloading rsa-4.9-py3-none-any.whl (34 kB)\n",
"Downloading pyreadline3-3.5.4-py3-none-any.whl (83 kB)\n",
" ---------------------------------------- 0.0/83.2 kB ? eta -:--:--\n",
" ---------------------------------------- 83.2/83.2 kB 4.6 MB/s eta 0:00:00\n",
"Building wheels for collected packages: pypika\n",
" Building wheel for pypika (pyproject.toml): started\n",
" Building wheel for pypika (pyproject.toml): finished with status 'done'\n",
" Created wheel for pypika: filename=PyPika-0.48.9-py2.py3-none-any.whl size=53885 sha256=22504c977d53f1de4940cd5d9ebc31b49e5f50777a9953ee83f8b7c2b43cfca0\n",
" Stored in directory: c:\\users\\asus\\appdata\\local\\pip\\cache\\wheels\\a3\\01\\bd\\4c40ceb9d5354160cb186dcc153360f4ab7eb23e2b24daf96d\n",
"Successfully built pypika\n",
"Installing collected packages: pypika, monotonic, flatbuffers, durationpy, zstandard, websockets, tenacity, shellingham, rsa, pyreadline3, pyproject_hooks, protobuf, packaging, orjson, opentelemetry-util-http, oauthlib, mmh3, jsonpatch, importlib-resources, httptools, grpcio, deprecated, chroma-hnswlib, bcrypt, backoff, asgiref, watchfiles, uvicorn, starlette, requests-oauthlib, posthog, opentelemetry-proto, opentelemetry-api, humanfriendly, googleapis-common-protos, google-auth, build, typer, opentelemetry-semantic-conventions, opentelemetry-exporter-otlp-proto-common, langsmith, kubernetes, fastapi, coloredlogs, opentelemetry-sdk, opentelemetry-instrumentation, onnxruntime, langchain-core, opentelemetry-instrumentation-asgi, opentelemetry-exporter-otlp-proto-grpc, langchain-text-splitters, opentelemetry-instrumentation-fastapi, langchain, chromadb\n",
" Attempting uninstall: zstandard\n",
" Found existing installation: zstandard 0.19.0\n",
" Uninstalling zstandard-0.19.0:\n",
" Successfully uninstalled zstandard-0.19.0\n",
" Attempting uninstall: tenacity\n",
" Found existing installation: tenacity 8.2.2\n",
" Uninstalling tenacity-8.2.2:\n",
" Successfully uninstalled tenacity-8.2.2\n",
" Attempting uninstall: protobuf\n",
" Found existing installation: protobuf 3.20.3\n",
" Uninstalling protobuf-3.20.3:\n",
" Successfully uninstalled protobuf-3.20.3\n",
" Attempting uninstall: packaging\n",
" Found existing installation: packaging 23.1\n",
" Uninstalling packaging-23.1:\n",
" Successfully uninstalled packaging-23.1\n",
" Attempting uninstall: jsonpatch\n",
" Found existing installation: jsonpatch 1.32\n",
" Uninstalling jsonpatch-1.32:\n",
" Successfully uninstalled jsonpatch-1.32\n",
" Attempting uninstall: bcrypt\n",
" Found existing installation: bcrypt 3.2.0\n",
" Uninstalling bcrypt-3.2.0:\n",
" Successfully uninstalled bcrypt-3.2.0\n",
"Successfully installed asgiref-3.8.1 backoff-2.2.1 bcrypt-4.2.1 build-1.2.2.post1 chroma-hnswlib-0.7.6 chromadb-0.6.3 coloredlogs-15.0.1 deprecated-1.2.18 durationpy-0.9 fastapi-0.115.7 flatbuffers-25.1.24 google-auth-2.38.0 googleapis-common-protos-1.66.0 grpcio-1.70.0 httptools-0.6.4 humanfriendly-10.0 importlib-resources-6.5.2 jsonpatch-1.33 kubernetes-32.0.0 langchain-0.3.16 langchain-core-0.3.32 langchain-text-splitters-0.3.5 langsmith-0.3.2 mmh3-5.1.0 monotonic-1.6 oauthlib-3.2.2 onnxruntime-1.20.1 opentelemetry-api-1.29.0 opentelemetry-exporter-otlp-proto-common-1.29.0 opentelemetry-exporter-otlp-proto-grpc-1.29.0 opentelemetry-instrumentation-0.50b0 opentelemetry-instrumentation-asgi-0.50b0 opentelemetry-instrumentation-fastapi-0.50b0 opentelemetry-proto-1.29.0 opentelemetry-sdk-1.29.0 opentelemetry-semantic-conventions-0.50b0 opentelemetry-util-http-0.50b0 orjson-3.10.15 packaging-24.2 posthog-3.11.0 protobuf-5.29.3 pypika-0.48.9 pyproject_hooks-1.2.0 pyreadline3-3.5.4 requests-oauthlib-2.0.0 rsa-4.9 shellingham-1.5.4 starlette-0.45.3 tenacity-9.0.0 typer-0.15.1 uvicorn-0.34.0 watchfiles-1.0.4 websockets-14.2 zstandard-0.23.0\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" WARNING: Failed to remove contents in a temporary directory 'C:\\Users\\ASUS\\anaconda3\\Lib\\site-packages\\~standard'.\n",
" You can safely remove it manually.\n",
"ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\n",
"streamlit 1.30.0 requires packaging<24,>=16.8, but you have packaging 24.2 which is incompatible.\n",
"streamlit 1.30.0 requires protobuf<5,>=3.20, but you have protobuf 5.29.3 which is incompatible.\n",
"streamlit 1.30.0 requires tenacity<9,>=8.1.0, but you have tenacity 9.0.0 which is incompatible.\n"
]
}
],
"source": [
"!pip install langchain chromadb sentence-transformers ollama"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "b5fd21a3-d820-4e6e-aef4-9ce4955ce2ff",
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Collecting langchain-community\n",
" Downloading langchain_community-0.3.16-py3-none-any.whl.metadata (2.9 kB)\n",
"Requirement already satisfied: PyYAML>=5.3 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from langchain-community) (6.0.1)\n",
"Requirement already satisfied: SQLAlchemy<3,>=1.4 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from langchain-community) (2.0.25)\n",
"Requirement already satisfied: aiohttp<4.0.0,>=3.8.3 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from langchain-community) (3.9.3)\n",
"Collecting dataclasses-json<0.7,>=0.5.7 (from langchain-community)\n",
" Downloading dataclasses_json-0.6.7-py3-none-any.whl.metadata (25 kB)\n",
"Collecting httpx-sse<0.5.0,>=0.4.0 (from langchain-community)\n",
" Downloading httpx_sse-0.4.0-py3-none-any.whl.metadata (9.0 kB)\n",
"Requirement already satisfied: langchain<0.4.0,>=0.3.16 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from langchain-community) (0.3.16)\n",
"Requirement already satisfied: langchain-core<0.4.0,>=0.3.32 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from langchain-community) (0.3.32)\n",
"Requirement already satisfied: langsmith<0.4,>=0.1.125 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from langchain-community) (0.3.2)\n",
"Requirement already satisfied: numpy<2,>=1.22.4 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from langchain-community) (1.26.4)\n",
"Collecting pydantic-settings<3.0.0,>=2.4.0 (from langchain-community)\n",
" Downloading pydantic_settings-2.7.1-py3-none-any.whl.metadata (3.5 kB)\n",
"Requirement already satisfied: requests<3,>=2 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from langchain-community) (2.31.0)\n",
"Requirement already satisfied: tenacity!=8.4.0,<10,>=8.1.0 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from langchain-community) (9.0.0)\n",
"Requirement already satisfied: aiosignal>=1.1.2 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from aiohttp<4.0.0,>=3.8.3->langchain-community) (1.2.0)\n",
"Requirement already satisfied: attrs>=17.3.0 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from aiohttp<4.0.0,>=3.8.3->langchain-community) (23.1.0)\n",
"Requirement already satisfied: frozenlist>=1.1.1 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from aiohttp<4.0.0,>=3.8.3->langchain-community) (1.4.0)\n",
"Requirement already satisfied: multidict<7.0,>=4.5 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from aiohttp<4.0.0,>=3.8.3->langchain-community) (6.0.4)\n",
"Requirement already satisfied: yarl<2.0,>=1.0 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from aiohttp<4.0.0,>=3.8.3->langchain-community) (1.9.3)\n",
"Collecting marshmallow<4.0.0,>=3.18.0 (from dataclasses-json<0.7,>=0.5.7->langchain-community)\n",
" Downloading marshmallow-3.26.0-py3-none-any.whl.metadata (7.3 kB)\n",
"Collecting typing-inspect<1,>=0.4.0 (from dataclasses-json<0.7,>=0.5.7->langchain-community)\n",
" Downloading typing_inspect-0.9.0-py3-none-any.whl.metadata (1.5 kB)\n",
"Requirement already satisfied: langchain-text-splitters<0.4.0,>=0.3.3 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from langchain<0.4.0,>=0.3.16->langchain-community) (0.3.5)\n",
"Requirement already satisfied: pydantic<3.0.0,>=2.7.4 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from langchain<0.4.0,>=0.3.16->langchain-community) (2.10.5)\n",
"Requirement already satisfied: jsonpatch<2.0,>=1.33 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from langchain-core<0.4.0,>=0.3.32->langchain-community) (1.33)\n",
"Requirement already satisfied: packaging<25,>=23.2 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from langchain-core<0.4.0,>=0.3.32->langchain-community) (24.2)\n",
"Requirement already satisfied: typing-extensions>=4.7 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from langchain-core<0.4.0,>=0.3.32->langchain-community) (4.12.2)\n",
"Requirement already satisfied: httpx<1,>=0.23.0 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from langsmith<0.4,>=0.1.125->langchain-community) (0.28.1)\n",
"Requirement already satisfied: orjson<4.0.0,>=3.9.14 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from langsmith<0.4,>=0.1.125->langchain-community) (3.10.15)\n",
"Requirement already satisfied: requests-toolbelt<2.0.0,>=1.0.0 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from langsmith<0.4,>=0.1.125->langchain-community) (1.0.0)\n",
"Requirement already satisfied: zstandard<0.24.0,>=0.23.0 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from langsmith<0.4,>=0.1.125->langchain-community) (0.23.0)\n",
"Requirement already satisfied: python-dotenv>=0.21.0 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from pydantic-settings<3.0.0,>=2.4.0->langchain-community) (0.21.0)\n",
"Requirement already satisfied: charset-normalizer<4,>=2 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from requests<3,>=2->langchain-community) (2.0.4)\n",
"Requirement already satisfied: idna<4,>=2.5 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from requests<3,>=2->langchain-community) (3.4)\n",
"Requirement already satisfied: urllib3<3,>=1.21.1 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from requests<3,>=2->langchain-community) (2.0.7)\n",
"Requirement already satisfied: certifi>=2017.4.17 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from requests<3,>=2->langchain-community) (2024.2.2)\n",
"Requirement already satisfied: greenlet!=0.4.17 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from SQLAlchemy<3,>=1.4->langchain-community) (3.0.1)\n",
"Requirement already satisfied: anyio in c:\\users\\asus\\anaconda3\\lib\\site-packages (from httpx<1,>=0.23.0->langsmith<0.4,>=0.1.125->langchain-community) (4.2.0)\n",
"Requirement already satisfied: httpcore==1.* in c:\\users\\asus\\anaconda3\\lib\\site-packages (from httpx<1,>=0.23.0->langsmith<0.4,>=0.1.125->langchain-community) (1.0.7)\n",
"Requirement already satisfied: h11<0.15,>=0.13 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from httpcore==1.*->httpx<1,>=0.23.0->langsmith<0.4,>=0.1.125->langchain-community) (0.14.0)\n",
"Requirement already satisfied: jsonpointer>=1.9 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from jsonpatch<2.0,>=1.33->langchain-core<0.4.0,>=0.3.32->langchain-community) (2.1)\n",
"Requirement already satisfied: annotated-types>=0.6.0 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from pydantic<3.0.0,>=2.7.4->langchain<0.4.0,>=0.3.16->langchain-community) (0.7.0)\n",
"Requirement already satisfied: pydantic-core==2.27.2 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from pydantic<3.0.0,>=2.7.4->langchain<0.4.0,>=0.3.16->langchain-community) (2.27.2)\n",
"Requirement already satisfied: mypy-extensions>=0.3.0 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from typing-inspect<1,>=0.4.0->dataclasses-json<0.7,>=0.5.7->langchain-community) (1.0.0)\n",
"Requirement already satisfied: sniffio>=1.1 in c:\\users\\asus\\anaconda3\\lib\\site-packages (from anyio->httpx<1,>=0.23.0->langsmith<0.4,>=0.1.125->langchain-community) (1.3.0)\n",
"Downloading langchain_community-0.3.16-py3-none-any.whl (2.5 MB)\n",
" ---------------------------------------- 0.0/2.5 MB ? eta -:--:--\n",
" ---------------------------------------- 0.0/2.5 MB ? eta -:--:--\n",
" ---------------------------------------- 0.0/2.5 MB ? eta -:--:--\n",
" ---------------------------------------- 0.0/2.5 MB ? eta -:--:--\n",
" ---------------------------------------- 0.0/2.5 MB ? eta -:--:--\n",
" - -------------------------------------- 0.1/2.5 MB 651.6 kB/s eta 0:00:04\n",
" - -------------------------------------- 0.1/2.5 MB 651.6 kB/s eta 0:00:04\n",
" -- ------------------------------------- 0.1/2.5 MB 561.1 kB/s eta 0:00:05\n",
" --- ------------------------------------ 0.2/2.5 MB 827.9 kB/s eta 0:00:03\n",
" ----- ---------------------------------- 0.3/2.5 MB 933.7 kB/s eta 0:00:03\n",
" ------ --------------------------------- 0.4/2.5 MB 1.1 MB/s eta 0:00:02\n",
" -------- ------------------------------- 0.6/2.5 MB 1.4 MB/s eta 0:00:02\n",
" ----------- ---------------------------- 0.7/2.5 MB 1.5 MB/s eta 0:00:02\n",
" ----------- ---------------------------- 0.7/2.5 MB 1.5 MB/s eta 0:00:02\n",
" -------------- ------------------------- 0.9/2.5 MB 1.6 MB/s eta 0:00:02\n",
" --------------- ------------------------ 1.0/2.5 MB 1.7 MB/s eta 0:00:01\n",
" --------------- ------------------------ 1.0/2.5 MB 1.7 MB/s eta 0:00:01\n",
" --------------- ------------------------ 1.0/2.5 MB 1.7 MB/s eta 0:00:01\n",
" --------------- ------------------------ 1.0/2.5 MB 1.7 MB/s eta 0:00:01\n",
" --------------- ------------------------ 1.0/2.5 MB 1.7 MB/s eta 0:00:01\n",
" --------------- ------------------------ 1.0/2.5 MB 1.7 MB/s eta 0:00:01\n",
" ----------------- ---------------------- 1.1/2.5 MB 1.3 MB/s eta 0:00:02\n",
" --------------------------- ------------ 1.7/2.5 MB 1.9 MB/s eta 0:00:01\n",
" --------------------------- ------------ 1.7/2.5 MB 1.9 MB/s eta 0:00:01\n",
" ---------------------------------- ----- 2.2/2.5 MB 2.1 MB/s eta 0:00:01\n",
" ------------------------------------ --- 2.3/2.5 MB 2.1 MB/s eta 0:00:01\n",
" --------------------------------------- 2.5/2.5 MB 2.2 MB/s eta 0:00:01\n",
" ---------------------------------------- 2.5/2.5 MB 2.2 MB/s eta 0:00:00\n",
"Downloading dataclasses_json-0.6.7-py3-none-any.whl (28 kB)\n",
"Downloading httpx_sse-0.4.0-py3-none-any.whl (7.8 kB)\n",
"Downloading pydantic_settings-2.7.1-py3-none-any.whl (29 kB)\n",
"Downloading marshmallow-3.26.0-py3-none-any.whl (50 kB)\n",
" ---------------------------------------- 0.0/50.8 kB ? eta -:--:--\n",
" ---------------------------------------- 50.8/50.8 kB 1.3 MB/s eta 0:00:00\n",
"Downloading typing_inspect-0.9.0-py3-none-any.whl (8.8 kB)\n",
"Installing collected packages: typing-inspect, marshmallow, httpx-sse, dataclasses-json, pydantic-settings, langchain-community\n",
"Successfully installed dataclasses-json-0.6.7 httpx-sse-0.4.0 langchain-community-0.3.16 marshmallow-3.26.0 pydantic-settings-2.7.1 typing-inspect-0.9.0\n"
]
}
],
"source": [
"!pip install -U langchain-community"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "960bc8ae-5d3d-401c-93ae-85b45fe9adee",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"C:\\Users\\ASUS\\AppData\\Local\\Temp\\ipykernel_1004\\3712172232.py:26: LangChainDeprecationWarning: The class `HuggingFaceEmbeddings` was deprecated in LangChain 0.2.2 and will be removed in 1.0. An updated version of the class exists in the :class:`~langchain-huggingface package and should be used instead. To use it run `pip install -U :class:`~langchain-huggingface` and import as `from :class:`~langchain_huggingface import HuggingFaceEmbeddings``.\n",
" self.embeddings = SentenceTransformerEmbeddings(model_name=EMBEDDING_MODEL)\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Loading existing vector store...\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"C:\\Users\\ASUS\\AppData\\Local\\Temp\\ipykernel_1004\\3712172232.py:60: LangChainDeprecationWarning: The class `Chroma` was deprecated in LangChain 0.2.9 and will be removed in 1.0. An updated version of the class exists in the :class:`~langchain-chroma package and should be used instead. To use it run `pip install -U :class:`~langchain-chroma` and import as `from :class:`~langchain_chroma import Chroma``.\n",
" self.vector_db = Chroma(\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"پردازش سوال 1/6 تکمیل شد\n",
"پردازش سوال 2/6 تکمیل شد\n",
"پردازش سوال 3/6 تکمیل شد\n",
"پردازش سوال 4/6 تکمیل شد\n",
"پردازش سوال 5/6 تکمیل شد\n",
"پردازش سوال 6/6 تکمیل شد\n",
"تمامی سوالات با موفقیت پردازش شدند!\n"
]
}
],
"source": [
"# CHROMOA\n",
"from langchain.vectorstores import Chroma\n",
"from langchain.embeddings import SentenceTransformerEmbeddings\n",
"from langchain.schema import Document\n",
"from ollama import chat\n",
"import os\n",
"import re\n",
"\n",
"DOCUMENT_PATHS = [\n",
" r'C:\\Users\\ASUS\\Downloads\\Hamrah.txt', #replace path\n",
" r'C:\\Users\\ASUS\\Downloads\\vape.txt',\n",
" r'C:\\Users\\ASUS\\Downloads\\Shah.txt',\n",
" r'C:\\Users\\ASUS\\Downloads\\Khalife.txt',\n",
" r'C:\\Users\\ASUS\\Downloads\\carbon.txt',\n",
" r'C:\\Users\\ASUS\\Downloads\\takapoo.txt'\n",
"]\n",
"\n",
"EMBEDDING_MODEL = 'sentence-transformers/paraphrase-multilingual-mpnet-base-v2'\n",
"LLM_MODEL = 'partai/dorna-llama3'\n",
"CHUNK_SIZE = 1000\n",
"OVERLAP = 200\n",
"CHROMA_PERSIST_DIR = r'C:\\Users\\ASUS\\Downloads\\chroma_db' \n",
"\n",
"class ChromaRAGSystem:\n",
" def __init__(self):\n",
" # Init embedding model\n",
" self.embeddings = SentenceTransformerEmbeddings(model_name=EMBEDDING_MODEL)\n",
" # Vector store instance\n",
" self.vector_db = None\n",
" \n",
" def build_vector_store(self):\n",
" \"\"\"Process documents and create Chroma vector store\"\"\"\n",
" all_docs = []\n",
" \n",
"\n",
" for doc_idx, path in enumerate(DOCUMENT_PATHS):\n",
" with open(path, 'r', encoding='utf-8') as f:\n",
" text = re.sub(r'\\s+', ' ', f.read()).strip()\n",
" # sliding window chunking\n",
" chunks = [\n",
" text[i:i+CHUNK_SIZE] \n",
" for i in range(0, len(text), CHUNK_SIZE - OVERLAP)\n",
" ]\n",
" # LangChain documents with metadata\n",
" for chunk in chunks:\n",
" all_docs.append(Document(\n",
" page_content=chunk,\n",
" metadata={\"source_doc\": doc_idx}\n",
" ))\n",
" \n",
" # Chroma vector store\n",
" self.vector_db = Chroma.from_documents(\n",
" documents=all_docs,\n",
" embedding=self.embeddings,\n",
" persist_directory=CHROMA_PERSIST_DIR\n",
" )\n",
" self.vector_db.persist()\n",
" \n",
" def load_vector_store(self):\n",
" \"\"\"Load existing Chroma vector store\"\"\"\n",
" self.vector_db = Chroma(\n",
" persist_directory=CHROMA_PERSIST_DIR,\n",
" embedding_function=self.embeddings\n",
" )\n",
" \n",
" def document_query(self, query, doc_index, top_k=5):\n",
" \"\"\"Retrieve context from specific document\"\"\"\n",
" # Chroma metadata filtering\n",
" results = self.vector_db.similarity_search(\n",
" query=query,\n",
" k=top_k,\n",
" filter={\"source_doc\": doc_index}\n",
" )\n",
" return [doc.page_content for doc in results]\n",
"\n",
"class AnswerGenerator:\n",
" def __init__(self, rag_system):\n",
" self.rag = rag_system\n",
" \n",
" def generate_response(self, question, doc_index):\n",
" \"\"\"Generate context-aware answer using LLM\"\"\"\n",
" # Retrieve relevant context\n",
" context_chunks = self.rag.document_query(question, doc_index)\n",
" context = \"\\n\".join(context_chunks)\n",
" \n",
" prompt = f\"\"\"با استفاده از متن زیر به سوال پاسخ دهید:\n",
"{context}\n",
"\n",
"اگر پاسخ در متن وجود ندارد عبارت 'پاسخی یافت نشد' را برگردانید\n",
"\n",
"سوال: {question}\n",
"پاسخ:\"\"\"\n",
" \n",
" response = chat(model=LLM_MODEL, messages=[{'role': 'user', 'content': prompt}])\n",
" return response['message']['content']\n",
"\n",
"if __name__ == \"__main__\":\n",
" rag_system = ChromaRAGSystem()\n",
" \n",
" # Init vector store\n",
" if not os.path.exists(CHROMA_PERSIST_DIR):\n",
" print(\"Creating new vector store...\")\n",
" rag_system.build_vector_store()\n",
" else:\n",
" print(\"Loading existing vector store...\")\n",
" rag_system.load_vector_store()\n",
" \n",
" # Init answer generator\n",
" answer_engine = AnswerGenerator(rag_system)\n",
"\n",
" queries = [\n",
" (\"چرا اینترنت همراه اول گوشی وصل نمیشود؟\", 0),\n",
" (\"چطوری ویپ مورد نظرمو پیدا کنم؟\", 1),\n",
" (\"شاه عباس که بود؟\", 2),\n",
" (\"خلیفه سلطان که بود و چه کرد؟\", 3),\n",
" (\"کربن اکتیو و کربن بلک چه هستند و چه تفاوتی دارند و برای چه استفاده میشن؟\", 4),\n",
" (\"شرکت تکاپو صنعت نامی چه محصولاتی ارایه میدهد؟ چه چیزی این شرکت را منحصر به فرد میسازد؟ سهام این شرکت صعودی است یا نزولی؟\", 5)\n",
" ]\n",
" \n",
" with open(r'C:\\Users\\ASUS\\Downloads\\representation2.txt', 'w', encoding='utf-8') as output_file: #repalce path\n",
" for q_num, (query, doc_idx) in enumerate(queries):\n",
" answer = answer_engine.generate_response(query, doc_idx)\n",
" output_file.write(f\"سوال {q_num+1} ({doc_idx+1}):\\n{query}\\n\\nپاسخ:\\n{answer}\\n\\n{'='*50}\\n\\n\")\n",
" print(f\"پردازش سوال {q_num+1}/{len(queries)} تکمیل شد\")\n",
"\n",
"print(\"تمامی سوالات با موفقیت پردازش شدند!\")"
]
}
],
"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.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}