{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "7896ff7a", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'c:\\\\code\\\\Bajaj HackRx\\\\Rag_app'" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "%pwd" ] }, { "cell_type": "code", "execution_count": 5, "id": "8638c1e6", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Created: c:\\code\\Bajaj HackRx\\Rag_app\\app\\__init__.py\n", "Created: c:\\code\\Bajaj HackRx\\Rag_app\\app\\config\\__init__.py\n", "Created: c:\\code\\Bajaj HackRx\\Rag_app\\app\\embedding\\__init__.py\n", "Created: c:\\code\\Bajaj HackRx\\Rag_app\\app\\ingestion\\__init__.py\n", "Created: c:\\code\\Bajaj HackRx\\Rag_app\\app\\reseasoning\\__init__.py\n", "Created: c:\\code\\Bajaj HackRx\\Rag_app\\app\\retrieval\\__init__.py\n", "Created: c:\\code\\Bajaj HackRx\\Rag_app\\app\\schemas\\__init__.py\n", "Created: c:\\code\\Bajaj HackRx\\Rag_app\\app\\utils\\__init__.py\n" ] } ], "source": [ "import os \n", "\n", "for directories in os.walk(\"c:\\\\code\\\\Bajaj HackRx\\\\Rag_app\\\\app\"):\n", " init_path = os.path.join(directories[0], '__init__.py')\n", " if not os.path.exists(init_path):\n", " with open(init_path, 'w') as init_file:\n", " init_file.write(\"init file\")\n", " print(f\"Created: {init_path}\")" ] }, { "cell_type": "markdown", "id": "4fedace2", "metadata": {}, "source": [ "## 1. Input document\n", "### Input Requirements:\n", "\n", "- Process PDFs, DOCX, and email documents\n", "- Handle policy/contract data efficiently\n", "- Parse natural language queries" ] }, { "cell_type": "code", "execution_count": 1, "id": "d47f278d", "metadata": {}, "outputs": [], "source": [ "import fitz\n", "from langchain_core.documents import Document\n", "from langchain_groq import ChatGroq\n", "from langchain.text_splitter import RecursiveCharacterTextSplitter\n", "from langchain.schema.messages import HumanMessage\n", "from langchain_community.vectorstores import FAISS\n", "import os \n", "from langchain.prompts import PromptTemplate\n", "from sklearn.metrics.pairwise import cosine_similarity\n", "from dotenv import load_dotenv\n", "load_dotenv()\n", "import pymupdf" ] }, { "cell_type": "code", "execution_count": 2, "id": "b7a58fc9", "metadata": {}, "outputs": [], "source": [ "api_key= os.getenv(\"GEMINI_API_KEY\")" ] }, { "cell_type": "code", "execution_count": 3, "id": "6d065c7c", "metadata": {}, "outputs": [], "source": [ "from langchain_google_genai import GoogleGenerativeAIEmbeddings\n", "\n", "embeddings = GoogleGenerativeAIEmbeddings(model = \"models/gemini-embedding-001\",google_api_key = api_key)\n", "vector = embeddings.embed_query(\"hello, world\")" ] }, { "cell_type": "code", "execution_count": 9, "id": "d0706163", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[-0.02842607907950878,\n", " 0.004132709465920925,\n", " 0.010386144742369652,\n", " -0.09004563093185425,\n", " -0.0044305226765573025]" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "vector[:5]" ] }, { "cell_type": "code", "execution_count": 5, "id": "01d64928", "metadata": {}, "outputs": [], "source": [ "import requests\n", "url = \"https://hackrx.blob.core.windows.net/assets/policy.pdf?sv=2023-01-03&st=2025-07-04T09%3A11%3A24Z&se=2027-07-05T09%3A11%3A00Z&sr=b&sp=r&sig=N4a9OU0w0QXO6AOIBiu4bpl7AXvEZogeT%2FjUHNO7HzQ%3D\"\n", "response = requests.get(url)" ] }, { "cell_type": "code", "execution_count": 94, "id": "80cf7260", "metadata": {}, "outputs": [], "source": [ "import requests\n", "url = \"https://docs.google.com/document/d/13pujQKEZS37mEHEfWDnaqb2FlvDnDwzkuJX88Y9w9EA/edit?usp=sharing\"\n", "response = requests.get(url)" ] }, { "cell_type": "code", "execution_count": 95, "id": "56afd5c0", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'text/html; charset=utf-8'" ] }, "execution_count": 95, "metadata": {}, "output_type": "execute_result" } ], "source": [ "response.headers['Content-Type']" ] }, { "cell_type": "code", "execution_count": 8, "id": "4d3fe1fb", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "157" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\n", "response.raise_for_status()\n", "pdf_bytes = response.content\n", "doc = pymupdf.open(stream=pdf_bytes, filetype=\"pdf\")\n", "text = \"\"\n", "splitter = RecursiveCharacterTextSplitter(chunk_size=800, chunk_overlap=100)\n", "pages = 0\n", "from uuid import uuid4\n", "uuid = str(uuid4())\n", "for i,page in enumerate(doc): \n", " text += page.get_text()\n", " uuid = str(uuid4())\n", " if text.strip():\n", " temp_doc = Document(page_content = text, metadata={\n", " \"doc_id\": uuid,\n", " \"page\":i,\n", " \"chunk_id\": f\"{uuid}_p{i}\",\n", " \"type\":\"text\"\n", " })\n", " text_chunks = splitter.split_documents([temp_doc])\n", "\n", "len(text_chunks)" ] }, { "cell_type": "code", "execution_count": 9, "id": "08cfbca7", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "list" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type(text_chunks)" ] }, { "cell_type": "code", "execution_count": null, "id": "c8f47031", "metadata": {}, "outputs": [], "source": [ "splitter = RecursiveCharacterTextSplitter(chunk_size=800, chunk_overlap=100)\n", "pages = 0\n", "from uuid import uuid4\n", "uuid = str(uuid4())\n", "for i,page in enumerate(doc): \n", " text += page.get_text()\n", " uuid = str(uuid4())\n", " if text.strip():\n", " temp_doc = Document(page_content = text, metadata={\n", " \"doc_id\": uuid,\n", " \"page\":i,\n", " \"chunk_id\": f\"{uuid}_p{i}\",\n", " \"type\":\"text\"\n", " })\n", " text_chunks = splitter.split_documents([temp_doc])\n", "\n", "len(text_chunks)" ] }, { "cell_type": "code", "execution_count": 5, "id": "6fe8d9ab", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "157" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pages = 0\n", "from uuid import uuid4\n", "uuid = str(uuid4())\n", "for i,page in enumerate(doc): \n", " text += page.get_text()\n", " uuid = str(uuid4())\n", " if text.strip():\n", " temp_doc = Document(page_content = text, metadata={\n", " \"doc_id\": uuid,\n", " \"page\":i,\n", " \"chunk_id\": f\"{uuid}_p{i}\",\n", " \"type\":\"text\"\n", " })\n", " text_chunks = splitter.split_documents([temp_doc])\n", "\n", "len(text_chunks)" ] }, { "cell_type": "code", "execution_count": 124, "id": "b7456368", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "National Insurance Co. Ltd. \n", "Premises No. 18-0374, Plot no. CBD-81, \n", "New Town, Kolkata - 700156 \n", "Page 1 of 25 \n", "National Parivar Mediclaim Plus Policy \n", "UIN: NICHLIP25039V032425 \n", " \n", "National Insurance Company Limited \n", " \n", " \n", " \n", " \n", " \n", "CIN - U10200WB1906GOI001713 \n", "IRDAI Regn. No. – 58 \n", " \n", " Issuing Office \n", "National Parivar Mediclaim Plus Policy \n", " \n", "Whereas the Proposer designated in the schedule hereto has by a Proposal together with Declaration, which shall be the basis of \n", "this contract and is deemed to be incorporated herein, has applied to National Insurance Company Ltd. (hereinafter called the \n", "Company), for the insurance hereinafter set forth, in respect of person(s)/ family members named in the schedule hereto\n" ] } ], "source": [ "print(text_chunks[0].page_content)" ] }, { "cell_type": "code", "execution_count": 125, "id": "84e3b7e6", "metadata": {}, "outputs": [], "source": [ "from uuid import uuid4\n", "uuids = [str(uuid4()) for _ in range(len(text_chunks)) ]" ] }, { "cell_type": "markdown", "id": "a7b3a0a7", "metadata": {}, "source": [ "### Setting up Pinecone Vectore Store" ] }, { "cell_type": "code", "execution_count": 1, "id": "6a98c3e3", "metadata": {}, "outputs": [], "source": [ "import os\n", "from dotenv import load_dotenv\n", "load_dotenv()\n", "pinecone_key = os.getenv(\"PINECONE_API_KEY\")\n" ] }, { "cell_type": "code", "execution_count": 2, "id": "e9bd7561", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from pinecone import Pinecone\n", "pc = Pinecone(api_key=pinecone_key)\n", "pc\n" ] }, { "cell_type": "code", "execution_count": 105, "id": "07746b7f", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "2025-08-13-16-36\n" ] } ], "source": [ "from pinecone import ServerlessSpec\n", "from datetime import datetime\n", "current_time = datetime.now()\n", "time_string = current_time.strftime(\"%Y-%m-%d-%H-%M\")\n", "print(time_string)\n", "index_name = f\"hackrx-index{time_string}\"\n", "# index_name = \"hackrx-index\"\n", "if not pc.has_index(index_name):\n", " pc.create_index(\n", " name = index_name,\n", " dimension=1536,\n", " metric=\"cosine\",\n", " spec = ServerlessSpec(cloud=\"aws\", region=\"us-east-1\")\n", " )\n", "\n", "index = pc.Index(index_name)" ] }, { "cell_type": "code", "execution_count": 4, "id": "e6af117d", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "index" ] }, { "cell_type": "code", "execution_count": 109, "id": "7ee7c02b", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "C:\\Users\\hp\\AppData\\Local\\Temp\\ipykernel_9600\\2571001968.py:7: LangChainDeprecationWarning: The class `OpenAIEmbeddings` was deprecated in LangChain 0.0.9 and will be removed in 1.0. An updated version of the class exists in the :class:`~langchain-openai package and should be used instead. To use it run `pip install -U :class:`~langchain-openai` and import as `from :class:`~langchain_openai import OpenAIEmbeddings``.\n", " embeddings = OpenAIEmbeddings(model=\"text-embedding-3-small\")\n" ] } ], "source": [ "# from langchain_openai import \n", "from langchain.embeddings import OpenAIEmbeddings\n", "\n", "from dotenv import load_dotenv\n", "load_dotenv()\n", "os.environ[\"OPENAI_API_KEY\"] = os.getenv(\"OPENAI_API_KEY\")\n", "embeddings = OpenAIEmbeddings(model=\"text-embedding-3-small\")" ] }, { "cell_type": "code", "execution_count": 6, "id": "43151b5f", "metadata": {}, "outputs": [], "source": [ "from langchain_pinecone import PineconeVectorStore\n", "vector_store = PineconeVectorStore(index = index, embedding=embeddings)" ] }, { "cell_type": "code", "execution_count": 133, "id": "03fb29a9", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['174168c5-ee26-4f4a-9aac-82c890cae977',\n", " 'cd33ff12-209e-4d3b-9ac9-cfffbb2f160f',\n", " '8f7cf61f-8b6a-4412-a45e-90614b04e4bf',\n", " '8696beaa-fa55-4ac6-9000-0f2be8f1a39b',\n", " 'f89f37a0-5382-4202-a320-c3374ca97470',\n", " '38e86c9f-a9a1-49a1-b1b6-0e0fd9242012',\n", " '9239c5e9-493e-45cc-b621-962c7cdd18ff',\n", " '1e3c9771-f5f2-45fd-b979-a0851d6285ff',\n", " '54a9e37f-84d9-4ea5-8a47-be7a500d94b6',\n", " '2ed09d29-6900-44d8-83e4-d503a5dcde15',\n", " '8103e53c-1a21-47aa-9e23-0a817ddbdca5',\n", " '0e879567-5c16-42b1-bd9c-bf919ef5b394',\n", " 'fe2003c6-8409-4045-acda-1f1c6c6a6699',\n", " '516acaa0-5a4d-4b0e-ac3c-5f03db8084b7',\n", " '4bca0e17-ca5a-43bf-b0c9-6f2572bd2f5f',\n", " '09a0a182-ee47-4569-a77e-b4a8adb82682',\n", " '3239e274-c789-410f-845e-791c0c4b6b03',\n", " 'fe825c23-84d9-4ad2-a853-74f8a1d02928',\n", " 'e5404438-f6ec-4af5-8a5c-4fa884e7022f',\n", " 'c9aeb34b-b556-46cf-b762-56ea338653e8',\n", " '9b6d478d-32fa-4ffd-96ca-95822c255cf1',\n", " '6652b6b8-1da2-4b15-9aea-26f79bc0a6d5',\n", " 'e8d57256-a599-4f9e-93e8-392334098dcb',\n", " '5491919b-0aa5-4080-9ee5-c319bc53749b',\n", " 'a00fec0d-79bc-47be-97ea-dbdcfefb828f',\n", " '71645e15-9440-40f2-b982-0376da83d0e3',\n", " '6df619c8-ef76-44de-b74a-2116148d89aa',\n", " 'f8151f79-56be-4fed-b364-b22ea4f2a2d0',\n", " '739c7bc6-0f9d-45ce-9bf0-db7c7dbc939b',\n", " '791401f5-46fe-4a9c-992b-da0135d72ae8',\n", " '1e67b489-9e3f-4e48-8807-d694963ede5b',\n", " '8e3892a6-7e26-4ecb-b8d0-c6a48126dbca',\n", " 'ffbcd2e2-8eb3-4e1b-997d-f0b8f004b95f',\n", " 'ac57e24d-8641-46d4-93aa-596664ed5a63',\n", " 'fc31c598-4716-4312-9091-75d9c879cac5',\n", " 'b08141e7-0519-4e92-bf5c-56849bc45c7f',\n", " '2e7a4727-f118-461d-a4aa-7f223ffeffcb',\n", " '1dcdf7e5-9d2f-4360-b9a9-ea00b9398fb4',\n", " '716f55ba-b624-43ae-98ce-0f77b063f17f',\n", " 'a42dbb78-85dc-4ee6-9b9c-c7a77093bae8',\n", " '57d5d937-2fef-4aae-86bb-6002523fa30f',\n", " '3400762f-1110-4e5f-a726-4f3edea01f02',\n", " '2d5b5f30-63d6-4399-8e69-806697e64307',\n", " '8feb1525-189a-45c1-ac23-0b33ba4994f3',\n", " '0a503b10-b5da-4cb5-a1b8-bd6f0f34ce64',\n", " '725010be-ebc8-45ee-be3e-2af2a8d1a5ee',\n", " '52016839-2213-4db2-b397-a51e7bca1882',\n", " '661398e1-eff3-4e1a-9ff4-b738bd2ce606',\n", " '5a37f469-e018-4866-9224-30734dda0161',\n", " '8028ec15-908a-4e98-8756-bff08d3ae96f',\n", " 'd8541648-8d20-4f79-a5bb-4160106b0795',\n", " '57aa5fb9-a383-4174-b88c-fd26e0c2e1e9',\n", " '8d539cf3-12bd-4844-b306-9ead1cb12540',\n", " '30e4322e-cf5e-4cd7-a56d-5529391d1b48',\n", " '81f18135-fb7e-49d5-b1ce-1c833246b7e6',\n", " 'c8f70828-1fc6-40cf-acd8-f7910841a3f6',\n", " '2ea87054-e3cb-436b-a418-e7dde7b66488',\n", " 'ec8797e6-1e89-403d-8f4b-a7528b856a9a',\n", " '9ec0c175-c01a-4713-8042-a9dc5057cd6e',\n", " 'df1dcb67-07a8-49d6-8bfa-2a0b857907ca',\n", " 'ce065535-e2ca-45f4-b278-96d46356f511',\n", " '161f51df-b3ca-4c54-b686-c8b68543da7e',\n", " '9528a8fc-45e0-43bc-9933-20a0e5d25a91',\n", " '6c3840f5-8d8f-4ed2-bf17-f82a88f8cfc4',\n", " '46a9b7b4-c460-4ae4-afa7-6bb8478f6072',\n", " '76df9287-461a-4cc8-9f34-7420f44ff0bf',\n", " '80265ffa-ef7c-4721-956b-6010745f577c',\n", " 'd09fc759-c639-4f5c-9a01-5f0f3bc359af',\n", " '78b04c1b-38ed-493a-b04c-aebb454c87e0',\n", " 'b6e68d75-11fe-428c-898f-56c58a6f2206',\n", " '45255213-2a89-428e-a97a-371a1f78bfdd',\n", " '516b872e-3c3c-442d-8be3-254da689bc13',\n", " 'e16f0153-1bd8-45a0-af2b-35d581e23e66',\n", " 'c36378f3-8839-48ba-ac46-86916439de77',\n", " '82261df7-bbbc-47d6-9124-386e12f28c63',\n", " 'ebd9c5d0-9bec-4901-946d-d663d1e66e89',\n", " 'd33ef9e8-db28-4f12-9e1e-45041b0b0193',\n", " '867171b7-f18f-451b-8fe0-879fedc98c11',\n", " 'fcbed948-b63d-4462-adc5-e3d48cd3f27c',\n", " 'c21c5ccd-c110-4790-8a83-6a6f1d6d5bab',\n", " '38d43887-22f9-4d11-b94d-dc96de2f3313',\n", " 'fdfa031f-8160-4623-8b9a-1e6d2ad9ac0b',\n", " 'd51bbdba-7403-4a33-8c3b-e98931fc41a9',\n", " 'a11eca40-2a42-4213-9996-d7d4242f41f3',\n", " '1e159458-4db8-407f-9729-3b79f57870b2',\n", " 'dc3582df-3f5b-4865-b9b3-8122455b22d8',\n", " 'd51ea955-c3f9-4b68-a4d8-6f36f0087e90',\n", " '8c0b67e8-1355-489f-bdbb-e16eae04a585',\n", " '7c35e509-23d3-4d80-9863-3172bc1c7963',\n", " '94b2eb43-5a75-4e1f-a9ff-58029cf50431',\n", " '9e885f6e-67d6-4fc7-9fc0-25c2443628d6',\n", " 'b3cd4d17-6feb-417a-a34d-4fab409e22b3',\n", " 'bead51f3-b31f-47b1-b290-1616a3ed8008',\n", " '1e197e22-0230-4c09-80ae-c7d63433ac64',\n", " '68395eb4-67a4-4262-af1c-9961c787f8cc',\n", " '84c5b8dd-098b-40e4-b86f-c341dcf8395d',\n", " '1361b7ee-849f-4d68-b3c3-42e9103ec6fa',\n", " '4fbe5da0-6f3e-42f3-b99e-6081f44e0cd8',\n", " 'ac1975b1-d034-488f-b613-28cf3782d0a8',\n", " '0017d512-f135-4123-b694-665bc6e11e64',\n", " 'f13798aa-3424-4b38-a7bf-f5abe366120f',\n", " '9dfcec61-f8a7-46be-98ae-7f54a5b53e7b',\n", " '44f6beba-fca5-4509-b814-662ddf5fad29',\n", " 'd87aedeb-16f1-4ccf-8728-fbbdfde6310f',\n", " '3eeb99d0-9c2f-4854-befd-3001154ca693',\n", " 'dbb2f8f2-d0a4-4288-8bbf-be24cb25360e',\n", " '0afd4ed7-a742-4230-a3e8-f59b4ed3af0f',\n", " '68cc2545-e9ee-4772-a968-5affe4eb80b7',\n", " '772df9fb-4da6-45a3-9cfc-fb5fec014153',\n", " 'a5bf6d49-afad-48a6-8ec7-d3b3e1c945d4',\n", " '3c4e4cfe-ce5f-48e4-bb2e-7d7080a6d9df',\n", " 'fdd184e8-2c0c-4a0d-aad1-425625c0acd8',\n", " '6059f8f3-bb47-4e8e-82f1-3b3cf42293ce',\n", " '32e22ff0-133e-4f0c-b9f0-d18108eada71',\n", " 'cd3a73dc-b2df-494a-80c1-7edd34655e6b',\n", " '081bb658-b2de-4470-9bf0-599595e32070',\n", " '9c9089be-1648-49ee-a296-4a2b0e629962',\n", " 'f90feeb1-dbb3-45c4-a141-aaffac9e9735',\n", " '931dbe4e-27ae-407c-b0a1-552cfadcf124',\n", " '5d1afa42-297f-475b-bbb3-d82b03b972f8',\n", " '75e2ee6b-9b59-4067-b59d-e12a6a29fb1f',\n", " 'd1f10078-a911-40d3-8def-36e11119d18b',\n", " '7380d7e5-8d51-492e-b6fe-042863fdb84e',\n", " '25d829a5-e681-4605-91b3-84b5589bca85',\n", " 'b901a4ad-11fa-4241-b6c0-2f1ce4ab5913',\n", " 'bcd5b4b2-efa6-4b89-a639-aae6afea19bf',\n", " '4f657335-b7e7-4918-b597-664db98ab9e5',\n", " '6b21048e-5bde-481a-9450-ea92c219741e',\n", " 'e209717c-6925-4cdd-b4a6-26230031d4b3',\n", " '2795137e-f3db-4c3a-a8be-4a4a62e2d83c',\n", " '43660962-d892-4a23-bdac-9825c5e00623',\n", " 'de594872-f941-4575-b7ec-6e66a222ca9d',\n", " '8dd521bd-02d5-44d0-b35b-2bc82c68ca87',\n", " 'de06a779-7d61-4240-a0e2-ac0b559469b1',\n", " '7892dcff-1b29-495e-a2a4-17cef5a7904d',\n", " 'a646b497-4d7a-4f4e-9b5d-4b989da6e26d',\n", " '2d9453bd-381f-4e20-bac4-27edbab64a5b',\n", " '45b2ff28-1a2b-4ac1-b30c-8e19dbd95943',\n", " '1f229b56-0839-495f-8ecb-a281eaaaa452',\n", " '763e5982-0827-41f9-b077-054d13782e69',\n", " 'c48d5c1b-6a70-41f2-8263-ac35244768e7',\n", " '65c4c939-b2a3-4dd8-b9c1-8a4585277859',\n", " 'c0954e09-6856-4a52-be96-059b9ad381d2',\n", " '484985c8-0f45-4289-904c-6143be565287',\n", " 'efedb28c-cc8e-4aad-ae86-e1126dfc960a',\n", " 'c41269f7-6a1a-4122-9326-9d4f08f7fa46',\n", " '8b53ddf1-8f7f-4902-b7f7-8059725ffb2b',\n", " '21ae63cb-649f-4b10-a67d-7f900a4185eb',\n", " '80610c06-6a16-44e7-9a43-dd95fd89e720',\n", " '8af13230-ea5f-425d-a4f0-e37acd8e7242',\n", " '3b8c80fa-a860-4324-9faa-d46848cd62c2',\n", " 'd358125e-6b25-4845-9303-b9f94ee9b1d9',\n", " '6dea7e26-2408-411f-8867-8251fe672319',\n", " '98564a4c-aeda-4556-af00-4ebd23cb407b',\n", " '7553a543-572c-4418-917f-9a6e7e62d155',\n", " 'c44444d0-f3a6-4f0d-b907-666d0b6c0d08',\n", " '12b11de7-032b-404e-9cfe-3d9ba260abd7',\n", " '9ac75c85-77d7-4418-8842-7997895d4400',\n", " 'e5d580eb-7c8c-451b-9e44-00386a72f47c',\n", " '923710d5-ff8f-44ed-97a7-ee40cb69ffba',\n", " 'b2990aa7-2b84-48cb-8abc-ee30719c5c86',\n", " 'f65e8225-3b98-4702-8b46-74b6703407b7',\n", " '992a965a-1c9c-46c7-bfca-4f0c99f33bf6',\n", " '18a1af9f-a788-45c7-9827-d6fb07c283d1',\n", " '5833c1f7-6d17-4308-919c-9c022e4cf98d',\n", " '3541476d-4fd7-4249-ae4f-c86d734001ca',\n", " '5f66b974-37ae-4e8a-a2eb-7d72f0d75d3c',\n", " '400717e9-430e-4bfc-9deb-f019dd5055a9',\n", " '356d2916-f094-48f2-8f5d-4658dd4209a5',\n", " '3de80d7b-42c5-456e-9a1b-7cdb75749df4',\n", " '156e996d-302b-4dbc-a3a5-db7a518f4a4c',\n", " '606c46a9-808c-4d33-bcd4-deac1e3b55a8',\n", " 'd9a44989-531c-4237-838a-8393479da64d',\n", " '2c26cc4c-251c-4d4f-ba17-309692015c4e',\n", " '74d76b64-1674-40c0-8b41-19b1eebe05a7',\n", " '71d03984-c626-4160-9430-528be9fedf59',\n", " 'cd48ebdf-7d40-4e61-87ab-f9eea638a74d',\n", " '8e8b2c73-ce6b-456c-897d-89fbfd75fa26',\n", " '9434a9f5-8909-45fb-a023-a4c61e8d4764',\n", " '7bd524c2-489a-4594-95bc-01b964c2c64d',\n", " 'f8e787dd-ad34-464d-b21f-ed6111c3fa30',\n", " '1a79c0b3-9b64-4809-813b-0480de369971',\n", " '89aa9b61-59e5-4f78-9f94-c145c753625c',\n", " '165c1f92-6a6b-4cce-b088-3a73c8c72c24',\n", " 'b7e1f173-6f42-4f91-a5f5-cdc2289548b4',\n", " '5320958c-6b8d-4445-9aa8-fb8e652198a5',\n", " '8efdbae0-1a07-4278-a657-e05cd1435753',\n", " '71a4c5c4-93a3-4839-acc7-d80bbcd4f774',\n", " '97463e5d-cecf-4cfa-bef5-5d6e9c8f0791',\n", " 'fbbd1d5a-7390-4011-b6c6-701fe5cfc1da',\n", " '09b40129-1ddc-4e93-bb40-c93865f4219e',\n", " '5569a342-0bde-4356-a38e-af426c796693',\n", " 'b09d66b0-245f-440f-a7f4-213bff7ba8ca',\n", " '5f62dabc-c220-44ce-b6f8-04adf37186c6',\n", " '273d9cd4-590d-4ece-9715-1ed201d3b53d',\n", " 'eb5c2c74-0de4-4870-aef4-b65a59fa502d',\n", " '5f7f5339-9919-44aa-b10f-449f16ed5df4',\n", " '3a890f5b-b380-4ab8-bfa9-f67f74dceac3',\n", " 'b47959e7-6038-4733-9e72-beaf98a731e4',\n", " 'bb1e60c2-bf86-4e9b-b0d0-8e1b859ff220',\n", " 'c6afbf5e-857a-48c7-84f2-9c5cb9a1ef00',\n", " '808ddb34-ecc5-4c7e-bb4d-0cd5487f8b84',\n", " '3c120e24-5edf-4a53-99e4-5b929162f849',\n", " '22a911c4-fe04-43e5-867c-c4529501131d',\n", " '0295a993-3a58-4550-a522-66004a6dd0fc',\n", " 'a54e8316-67d4-4ab7-9747-876ac1413eb3',\n", " 'b5068009-bef5-4bce-af38-081905babf3a',\n", " '7d57b14e-fcc6-4bc4-8ed7-9f8616268464',\n", " 'f119914b-dda3-4fab-92ed-ac7d45be674c',\n", " 'a13eb99f-bf84-4918-8308-6aaebfa44522',\n", " '02425f7d-3f2c-4f99-b4b3-dae251f79f9a',\n", " '8c070a7b-b0fe-4cad-9b25-e1f703c08041',\n", " '458439d7-1a8e-4808-b4bf-fe0a75b569a9',\n", " '1db0a9d9-dccd-4347-9cf3-283815f1bc05',\n", " '5ecc0797-280b-450a-b6db-fd8352c855bc',\n", " '85f323ea-ded5-4cea-87d5-e07e951b1fea',\n", " 'd5c87f7b-695b-4f80-8502-5e7116721e67',\n", " 'a2fd76f1-a851-495a-b463-44fc537d62cd',\n", " '737a76b0-d8d8-49a6-b433-f553a8aa2b58',\n", " '5b0db327-3234-468a-ba12-734a481d7e73',\n", " '70c8cf89-29fe-4349-b7d3-b3293267fd10',\n", " '635b04dd-fa10-4dde-bfcb-168cc8a9bd39',\n", " '152b468a-b307-4b8d-b7b3-ee7e152aac78',\n", " '8942236c-0e8c-42c5-8e95-7fcf84e89677',\n", " '2de3d06a-9d37-4e1f-a4ce-45a3e2cdcf08',\n", " '4c1dff30-a002-43e8-b47f-f66855fc13e4',\n", " '9254fd90-3ffc-48f8-b091-b9fe81d3b56d',\n", " 'b4befb2a-8746-4d75-8397-66010d1baf2c',\n", " '97ba14a5-ace8-45b7-b25b-be774aa25410',\n", " '25d27bce-5d31-430c-93c6-2c30025a030c',\n", " 'c15c3ada-bb90-43f3-a41d-f85a832673b8',\n", " '4a353418-e1db-4c6e-ab8e-f3a534b03d2e',\n", " '668dfef9-37da-4619-8a0b-71ba993c7ac3',\n", " 'ba8233d0-1601-4167-886c-f632e3d077bf',\n", " '49cf3301-80b4-46e5-93bd-55712adfae99',\n", " '51ced038-b27b-46d1-96e6-923867ca4774',\n", " 'ac4e9a83-8715-4a7d-b4a3-b4e7b2ecef9e',\n", " '6fe1361f-ede5-4359-90be-d007f6eb03e2',\n", " 'cf49d0cc-a941-486f-88ab-88c93cc3f211',\n", " 'ee21070d-e45e-4f61-ae1c-a412b659035b',\n", " '3744d911-37cc-4645-ba2b-b376718e0afd',\n", " 'efff5713-c6cf-4e9a-b5ce-ccd4e443a8b9',\n", " 'aeae7c83-6a90-40c6-9fa5-65a8488865af',\n", " '3b349ca6-fac5-41c1-b8de-5ee32161f023',\n", " '39703730-8667-432f-aceb-8a569bb7d3c7',\n", " 'd021eee3-ea5f-454e-a5f9-8ff2b354e05f',\n", " '29fab8ce-8c8c-4f76-a59e-00291af854df',\n", " '186e7eef-e3ab-4f05-b6ee-2ae65d871393',\n", " 'c8b02b23-9dc6-43a9-b0ea-fd42533165cf',\n", " '48734804-8b5e-45e8-9576-16f5f3d5da13',\n", " '56f12823-504b-46b1-a239-78ebf589063e',\n", " '5cea0d13-04f6-4b8a-9b71-ec1a2a5eb191',\n", " '147a6f26-3ad6-4929-a074-7e397d3ac134',\n", " '4e725c5a-f457-437b-ae47-d5e544a058d3',\n", " '39b0e4b9-74ea-461f-8375-31a38af1db59',\n", " '2d90a41d-20bc-4f87-adbd-8c5ef5d8f33f',\n", " '0108b65b-f4b5-4839-80bc-b5a2f61c35c6',\n", " '8002651d-7f26-4c99-a60c-d8df30aadd79',\n", " 'bef4b953-c0e3-4822-85e0-94d3a41a2a65',\n", " '6b02df41-38d7-4a11-bb14-a87ef004a191',\n", " '84c9570a-06ee-4edd-b767-dc2ce45603d9',\n", " '71a0f38c-4764-428a-a9a9-f3353fd7c768',\n", " '15e8567b-4f1c-4f80-8ce7-aaf83a489933',\n", " '0dbdae26-1e9d-4b2c-8957-3f0fd056fb6f',\n", " '2888971e-530b-44b5-b38a-ba00b8667439',\n", " 'c99e5ddc-0741-4a24-8cd8-cab974c32dbc',\n", " '5365117a-4e5e-4683-9cf6-5c9015b328c8',\n", " '62194dec-507c-49d8-b809-20c03d5caf0b',\n", " '358b61b1-e962-4443-9240-835bc75146cc',\n", " '10c92ff4-a8cb-483b-ad78-6dc680d50cd8',\n", " 'a6cc759f-2599-4199-a08d-3f3b142af66f',\n", " '035bb626-5d0a-4a43-a9cb-66b2bd940d2c',\n", " '1a1da71a-e9b8-466d-b5e0-b7e10847b857',\n", " '09fe8139-5029-4782-bff9-a0edfce73e2f',\n", " '939af366-34d7-47c5-8937-59f0122df0d4',\n", " 'f74a0d54-0d45-459d-b988-b2c398cacfd5',\n", " 'bbe495a3-7964-4dd0-8c6d-b2a22a8494b2',\n", " '11616f61-808c-43a4-8c38-9de0db923d68',\n", " '65b9f618-b8aa-42d0-b7e4-321207cf81eb',\n", " '7d964d73-3b58-49ab-8a13-fe9add8f015e',\n", " '90ac205f-f322-431d-a097-a7fce1729cb2',\n", " 'ce338839-0430-47a7-b426-87feabab5320',\n", " '09cc0450-5e49-43a2-b7c0-c79afb049eb0',\n", " '80500abe-37ef-4483-a40c-aa1ac451cf95',\n", " '64b77e67-7115-4941-a04b-2ff4771aa71e',\n", " 'cc9a5ffa-2c9c-4096-972a-e5fa9b3cefe9',\n", " 'be907e7c-f601-4119-b68c-35a24eb9acfa',\n", " '79fee5a5-3d8a-46e9-96bc-340ac4a324aa',\n", " 'db7c23df-6888-4b4e-a4b6-58a953c174d3',\n", " 'f54d787e-5dfb-4801-bfed-842cd18fa332',\n", " 'e18688f1-15fc-400d-8ea3-59d313181cb0',\n", " 'f7fba163-e8ea-451f-b1f8-cc70f599f23d',\n", " '7f7f8847-1483-4801-96da-8c789d6ac93a',\n", " 'e356cda5-b603-4e15-9995-e9411bd8f4f4',\n", " 'ab3bdbe6-d223-420d-b66b-d572bf4b14d1',\n", " 'b2e2ed1a-e738-4197-a878-d8762814c860',\n", " 'b0d31fab-a0f8-4978-a3fd-00fc9754f327',\n", " 'af6d58f7-3d4d-4a32-96ba-0376dc945960',\n", " '863b5fd8-fedc-42c9-8a8e-2d07670d676c',\n", " 'dcc803bf-0601-4a82-a90b-3481b7188b73',\n", " 'cefcc7ee-9b1b-4586-983c-fceda1417772',\n", " 'b895c11d-3f5d-49f5-b4d8-9f0f9307ee3e',\n", " '06a62e87-e561-46af-94f3-9657d2a8e0c2',\n", " 'f34de4a4-b5e0-4a7e-81e1-5c7abc066221',\n", " '3ad33f70-faaa-4ae2-8660-bf7972a401e0',\n", " 'b170a51a-cc14-4a3d-9c39-23f18e7405f5',\n", " '4d89bda3-00d8-4db7-a89b-da2b06b29a24',\n", " 'e28be583-da3a-4b82-bc86-e25dde6fb02b',\n", " 'db982e3e-c076-4e06-9ba6-faed32db3527',\n", " '86c5d471-60af-4e96-9cf1-a3b7f5295c47',\n", " '9e010af0-ea9d-40f0-aad3-973c0789768c',\n", " 'e5baba45-762a-42b5-b32d-4f64a4753b27',\n", " '772ee256-aa86-4ae5-925e-acfff2ec76f0',\n", " '0ad3ab0a-0bae-46ab-92d3-caf165cefed5']" ] }, "execution_count": 133, "metadata": {}, "output_type": "execute_result" } ], "source": [ "vector_store.add_documents(documents=text_chunks, ids = uuids)" ] }, { "cell_type": "code", "execution_count": 11, "id": "7b8b7a46", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "* Page 16 of 25 \n", "National Parivar Mediclaim Plus Policy \n", "UIN: NICHLIP25039V032425 \n", " \n", "ii. The policyholder may cancel his/her policy at any time during the term, by giving 7 days’ notice in writing. The Insurer shall: \n", "a) refund proportionate premium for unexpired policy period, if the term of policy upto one year and there is no claim (s) \n", "made during the policy period. \n", "b) refund premium for the unexpired policy period, in respect of policies with term more than 1 year and risk coverage for \n", "such policy years has not commenced and refund proportionate premium for unexpired policy period for the current \n", "policy year. \n", "There shall be no refund for the completed policy year elapsed. [{'chunk_id': 'b0a34a7d-f5a1-4777-93aa-c59269013de5_p24', 'doc_id': 'b0a34a7d-f5a1-4777-93aa-c59269013de5', 'page': 24.0, 'type': 'text'}]\n", "* Page 16 of 25 \n", "National Parivar Mediclaim Plus Policy \n", "UIN: NICHLIP25039V032425 \n", " \n", "ii. The policyholder may cancel his/her policy at any time during the term, by giving 7 days’ notice in writing. The Insurer shall: \n", "a) refund proportionate premium for unexpired policy period, if the term of policy upto one year and there is no claim (s) \n", "made during the policy period. \n", "b) refund premium for the unexpired policy period, in respect of policies with term more than 1 year and risk coverage for \n", "such policy years has not commenced and refund proportionate premium for unexpired policy period for the current \n", "policy year. \n", "There shall be no refund for the completed policy year elapsed. [{'chunk_id': 'b0a34a7d-f5a1-4777-93aa-c59269013de5_p24', 'doc_id': 'b0a34a7d-f5a1-4777-93aa-c59269013de5', 'page': 24.0, 'type': 'text'}]\n" ] } ], "source": [ "results = vector_store.similarity_search(\n", " \"What is the grace period for premium payment under the National Parivar Mediclaim Plus Policy?\",\n", " k=2\n", ")\n", "for res in results:\n", " print(f\"* {res.page_content} [{res.metadata}]\")" ] }, { "cell_type": "code", "execution_count": 135, "id": "41f27c21", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[Document(id='f13798aa-3424-4b38-a7bf-f5abe366120f', metadata={'chunk_id': 'b0a34a7d-f5a1-4777-93aa-c59269013de5_p24', 'doc_id': 'b0a34a7d-f5a1-4777-93aa-c59269013de5', 'page': 24.0, 'type': 'text'}, page_content='Page 16 of 25 \\nNational Parivar Mediclaim Plus Policy \\nUIN: NICHLIP25039V032425 \\n \\nii. The policyholder may cancel his/her policy at any time during the term, by giving 7 days’ notice in writing. The Insurer shall: \\na) refund proportionate premium for unexpired policy period, if the term of policy upto one year and there is no claim (s) \\nmade during the policy period. \\nb) refund premium for the unexpired policy period, in respect of policies with term more than 1 year and risk coverage for \\nsuch policy years has not commenced and refund proportionate premium for unexpired policy period for the current \\npolicy year. \\nThere shall be no refund for the completed policy year elapsed.'), Document(id='8002651d-7f26-4c99-a60c-d8df30aadd79', metadata={'chunk_id': 'b0a34a7d-f5a1-4777-93aa-c59269013de5_p24', 'doc_id': 'b0a34a7d-f5a1-4777-93aa-c59269013de5', 'page': 24.0, 'type': 'text'}, page_content='Page 16 of 25 \\nNational Parivar Mediclaim Plus Policy \\nUIN: NICHLIP25039V032425 \\n \\nii. The policyholder may cancel his/her policy at any time during the term, by giving 7 days’ notice in writing. The Insurer shall: \\na) refund proportionate premium for unexpired policy period, if the term of policy upto one year and there is no claim (s) \\nmade during the policy period. \\nb) refund premium for the unexpired policy period, in respect of policies with term more than 1 year and risk coverage for \\nsuch policy years has not commenced and refund proportionate premium for unexpired policy period for the current \\npolicy year. \\nThere shall be no refund for the completed policy year elapsed.')]\n" ] } ], "source": [ "print(results)" ] }, { "cell_type": "code", "execution_count": 136, "id": "cf7b7568", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "* [SIM=0.678520] Page 16 of 25 \n", "National Parivar Mediclaim Plus Policy \n", "UIN: NICHLIP25039V032425 \n", " \n", "ii. The policyholder may cancel his/her policy at any time during the term, by giving 7 days’ notice in writing. The Insurer shall: \n", "a) refund proportionate premium for unexpired policy period, if the term of policy upto one year and there is no claim (s) \n", "made during the policy period. \n", "b) refund premium for the unexpired policy period, in respect of policies with term more than 1 year and risk coverage for \n", "such policy years has not commenced and refund proportionate premium for unexpired policy period for the current \n", "policy year. \n", "There shall be no refund for the completed policy year elapsed. [{'chunk_id': 'b0a34a7d-f5a1-4777-93aa-c59269013de5_p24', 'doc_id': 'b0a34a7d-f5a1-4777-93aa-c59269013de5', 'page': 24.0, 'type': 'text'}]\n" ] } ], "source": [ "results = vector_store.similarity_search_with_score(\n", " \"What is the grace period for premium payment under the National Parivar Mediclaim Plus Policy?\", k=1\n", ")\n", "for res, score in results:\n", " print(f\"* [SIM={score:3f}] {res.page_content} [{res.metadata}]\")" ] }, { "cell_type": "markdown", "id": "7fde8a22", "metadata": {}, "source": [ "### QUERY PARSING " ] }, { "cell_type": "code", "execution_count": 62, "id": "20452e98", "metadata": {}, "outputs": [], "source": [ "from pydantic import BaseModel, model_validator,field_validator\n", "from typing import List, Dict, Any, Optional\n", "import json\n", "class QuerySpec(BaseModel):\n", " raw_query: str \n", " intent: str \n", " entities: Dict[str, str]\n", " constraints : Dict[str, Any]\n", " answer_type: str \n", " followups: Optional[List[str]] = []\n", "\n", " @model_validator(mode = \"before\")\n", " @classmethod\n", " def parse_nested_json(cls, values):\n", " for field in ['entities', 'constraints']:\n", " val = values.get(field)\n", " if isinstance(val, str):\n", " try:\n", " values[field] = json.loads(val)\n", " except json.JSONDecodeError:\n", " pass\n", " return values\n", "\n", "class ClauseHit(BaseModel):\n", " doc_id : str\n", " page: int\n", " chunk_id: str \n", " text: str \n", " metadata: Dict[str, Any]\n", " score: float \n", " boost: Optional[float] = None\n", " combined_score: Optional[float] = None\n", "\n", " @field_validator(\"metadata\", mode=\"before\")\n", " def parse_metadata(cls, v):\n", " if isinstance(v, str):\n", " try:\n", " return json.loads(v) if v.strip() else {}\n", " except json.JSONDecodeError:\n", " return {}\n", " return v\n", "\n", "class LogicResult(BaseModel):\n", " answer: str\n", " decision: str # \"covered\"/\"not_covered\"/\"conditional\"\n", " confidence: float\n", " evidence: List[ClauseHit]\n", " rationale: str\n", " \n", "\n", "class APIResponse(BaseModel):\n", " query_spec: QuerySpec\n", " logic_result: LogicResult\n", " debug: Optional[Dict[str, Any]] = None\n", "\n", "\n", "\n" ] }, { "cell_type": "code", "execution_count": 8, "id": "3ac1f99f", "metadata": {}, "outputs": [], "source": [ "user_question = \"What is the grace period for premium payment under the National Parivar Mediclaim Plus Policy?\"" ] }, { "cell_type": "code", "execution_count": 9, "id": "2961e184", "metadata": {}, "outputs": [], "source": [ "PARSER_PROMPT = f\"\"\"You receive a user's question about an insurance/contract document. Produce a JSON with keys:\n", "- intent (one of: coverage_check, definition, limit_query, waiting_period, exclusions, other)\n", "- entities (map of entity_name -> canonical string)\n", "- constraints (map: plan, time_window, eligible_person, numerical_constraints)\n", "- answer_type (one of: yes_no, short_explain, detailed, clause_list)\n", "Return ONLY the JSON.Make sure that nested fields like \"entities\" and \"constraints\" are JSON objects, not strings.\n", "\"\"\"" ] }, { "cell_type": "code", "execution_count": 10, "id": "a9123e2a", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "ChatGoogleGenerativeAI(model='models/gemini-2.5-flash', google_api_key=SecretStr('**********'), client=, default_metadata=(), model_kwargs={})" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from langchain_google_genai import ChatGoogleGenerativeAI\n", "api_key = os.getenv(\"GEMINI_API_KEY\")\n", "llm = ChatGoogleGenerativeAI(\n", " model=\"gemini-2.5-flash\",\n", " google_api_key = api_key\n", " \n", " )\n", "llm" ] }, { "cell_type": "code", "execution_count": 30, "id": "290081a1", "metadata": {}, "outputs": [], "source": [ "def parsing_query(query:str) -> QuerySpec:\n", " # Bind the schema to the model\n", " structured_llm = llm.with_structured_output(QuerySpec)\n", "\n", " # Compose the full prompt with instructions and user question\n", " full_prompt = PARSER_PROMPT + \"\\n\" + query\n", "\n", " # Invoke the model to get structured output parsed as QuerySpec\n", " result: QuerySpec = structured_llm.invoke(full_prompt)\n", " return result\n", " # print(result.json()) # This will print the JSON output matching your schema\n" ] }, { "cell_type": "markdown", "id": "b5cecc42", "metadata": {}, "source": [ "## Embedding + Retrieval and Clause Matching" ] }, { "cell_type": "code", "execution_count": 38, "id": "11fdd288", "metadata": {}, "outputs": [], "source": [ "def get_query_embedding(embedding_client, query_spec: QuerySpec):\n", " q = query_spec.raw_query\n", " e_main = embedding_client.embed_query(q)\n", " expansions = []\n", " if \"procedure\" in query_spec.entities:\n", " expansions.append(f\"{q} OR {query_spec.entities['procedure']} procedures related\")\n", " return e_main, expansions\n", "\n", "def retrieval_from_pinecone_vectoreStore(pinecone_index, embeddings, top_k= 3, filter_meta = None):\n", " \"\"\"\n", " Retrieve the top matching chunks from Pinecone.\n", " \n", " Args:\n", " pinecone_index: Your Pinecone index object.\n", " embedding: The vector embedding of the query.\n", " top_k: How many chunks to retrieve.\n", " filter_meta: Optional metadata filter dict.\n", " \n", " Returns:\n", " List of ClauseHit objects (lightweight container for chunk info).\n", " \"\"\"\n", " res = pinecone_index.query(\n", " vector= embeddings,\n", " top_k =top_k ,\n", " include_metadata = True, \n", " include_values = False, \n", " filter = filter_meta \n", " )\n", " hits= []\n", " for match in res['matches']:\n", " hits.append(ClauseHit(\n", " doc_id=match['metadata']['doc_id'],\n", " page=match['metadata'].get('page', -1),\n", " chunk_id=match['metadata'].get('chunk_id', ''),\n", " text=match['metadata']['text'],\n", " metadata=match['metadata'],\n", " score=match['score']\n", " ))\n", " return hits\n", "\n", " " ] }, { "cell_type": "markdown", "id": "9707521f", "metadata": {}, "source": [ "## Logic Evaluation\n", "### Decision processing" ] }, { "cell_type": "code", "execution_count": 74, "id": "74e49132", "metadata": {}, "outputs": [], "source": [ "def evaluate_with_llm(raw_query: str, top_clauses: list):\n", " \"\"\"\n", " Use the LLM to analyze retrieved clauses and return structured decision.\n", " \"\"\"\n", "\n", " # Prepare context for the prompt\n", " context_clauses = []\n", " for i, c in enumerate(top_clauses, 1):\n", " context_clauses.append(f\"{i}) [source:{c.doc_id} page:{c.page}] {c.text}\")\n", " print(chr(10).join(context_clauses))\n", " \n", " # Build prompt\n", " prompt = f\"\"\"\n", " You are an insurance policy analyst. Question: \"{raw_query}\"\n", "\n", " Provided clauses (numbered):\n", " {chr(10).join(context_clauses)}\n", "\n", " Task:\n", " 1) Decide: COVERED / NOT_COVERED / CONDITIONAL\n", " 2) Summarize the exact clause(s) that justify your decision.\n", " 3) List any conditions, waiting periods, sublimits, or exclusions relevant.\n", " 4) Provide a concise final answer (1-2 sentences).\n", "\n", " Return JSON with these exact keys:\n", " {{\n", " \"decision\": \"...\",\n", " \"evidence\": [\n", " {{\"doc_id\": \"...\", \"page\": 0, \"snippet\": \"...\", \"reason\": \"...\"}}\n", " ],\n", " \"confidence\": 0.0,\n", " \"rationale\": \"...\",\n", " \"answer\": \"...\"\n", " }}\n", " \"\"\"\n", "\n", " # Directly parse to LogicResult using structured output\n", " structured_llm = llm.with_structured_output(LogicResult)\n", " result: LogicResult = structured_llm.invoke(prompt)\n", " # print(f\"result: {result}\\n result_type{type(result)}\")\n", "\n", " # Attach full text for each evidence\n", " enriched_evidence = []\n", " for ev in result.evidence:\n", " matched = next((c for c in top_clauses if c.doc_id == ev.doc_id and str(c.page) == str(ev.page)), None)\n", " if matched:\n", " ev.text = matched.text # or use a different field if needed\n", " enriched_evidence.append(ev)\n", "\n", " result.evidence = enriched_evidence\n", " # print(enriched_evidence[0])\n", " return result\n" ] }, { "cell_type": "code", "execution_count": 14, "id": "fe78ab38", "metadata": {}, "outputs": [], "source": [ "query = \"What is the grace period for premium payment under the National Parivar Mediclaim Plus Policy?\"" ] }, { "cell_type": "code", "execution_count": 36, "id": "fea3b1be", "metadata": {}, "outputs": [], "source": [ "parsed_query = parsing_query(query)\n" ] }, { "cell_type": "code", "execution_count": 32, "id": "82fcb8bb", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "__main__.QuerySpec" ] }, "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type(parsed_query)" ] }, { "cell_type": "code", "execution_count": 39, "id": "9b8292f0", "metadata": {}, "outputs": [], "source": [ "\n", "# Step 1 — Embed\n", "embedding = get_query_embedding(embeddings, parsed_query)" ] }, { "cell_type": "code", "execution_count": 44, "id": "46790137", "metadata": {}, "outputs": [], "source": [ "\n", "# Step 2 — Retrieve\n", "top_hits = retrieval_from_pinecone_vectoreStore(index, embedding, top_k=3)" ] }, { "cell_type": "code", "execution_count": 48, "id": "9c3f4e68", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[ClauseHit(doc_id='b0a34a7d-f5a1-4777-93aa-c59269013de5', page=24, chunk_id='b0a34a7d-f5a1-4777-93aa-c59269013de5_p24', text='Page 16 of 25 \\nNational Parivar Mediclaim Plus Policy \\nUIN: NICHLIP25039V032425 \\n \\nii. The policyholder may cancel his/her policy at any time during the term, by giving 7 days’ notice in writing. The Insurer shall: \\na) refund proportionate premium for unexpired policy period, if the term of policy upto one year and there is no claim (s) \\nmade during the policy period. \\nb) refund premium for the unexpired policy period, in respect of policies with term more than 1 year and risk coverage for \\nsuch policy years has not commenced and refund proportionate premium for unexpired policy period for the current \\npolicy year. \\nThere shall be no refund for the completed policy year elapsed.', metadata={'chunk_id': 'b0a34a7d-f5a1-4777-93aa-c59269013de5_p24', 'doc_id': 'b0a34a7d-f5a1-4777-93aa-c59269013de5', 'page': 24.0, 'text': 'Page 16 of 25 \\nNational Parivar Mediclaim Plus Policy \\nUIN: NICHLIP25039V032425 \\n \\nii. The policyholder may cancel his/her policy at any time during the term, by giving 7 days’ notice in writing. The Insurer shall: \\na) refund proportionate premium for unexpired policy period, if the term of policy upto one year and there is no claim (s) \\nmade during the policy period. \\nb) refund premium for the unexpired policy period, in respect of policies with term more than 1 year and risk coverage for \\nsuch policy years has not commenced and refund proportionate premium for unexpired policy period for the current \\npolicy year. \\nThere shall be no refund for the completed policy year elapsed.', 'type': 'text'}, score=0.678843796, boost=None, combined_score=None),\n", " ClauseHit(doc_id='b0a34a7d-f5a1-4777-93aa-c59269013de5', page=24, chunk_id='b0a34a7d-f5a1-4777-93aa-c59269013de5_p24', text='Page 16 of 25 \\nNational Parivar Mediclaim Plus Policy \\nUIN: NICHLIP25039V032425 \\n \\nii. The policyholder may cancel his/her policy at any time during the term, by giving 7 days’ notice in writing. The Insurer shall: \\na) refund proportionate premium for unexpired policy period, if the term of policy upto one year and there is no claim (s) \\nmade during the policy period. \\nb) refund premium for the unexpired policy period, in respect of policies with term more than 1 year and risk coverage for \\nsuch policy years has not commenced and refund proportionate premium for unexpired policy period for the current \\npolicy year. \\nThere shall be no refund for the completed policy year elapsed.', metadata={'chunk_id': 'b0a34a7d-f5a1-4777-93aa-c59269013de5_p24', 'doc_id': 'b0a34a7d-f5a1-4777-93aa-c59269013de5', 'page': 24.0, 'text': 'Page 16 of 25 \\nNational Parivar Mediclaim Plus Policy \\nUIN: NICHLIP25039V032425 \\n \\nii. The policyholder may cancel his/her policy at any time during the term, by giving 7 days’ notice in writing. The Insurer shall: \\na) refund proportionate premium for unexpired policy period, if the term of policy upto one year and there is no claim (s) \\nmade during the policy period. \\nb) refund premium for the unexpired policy period, in respect of policies with term more than 1 year and risk coverage for \\nsuch policy years has not commenced and refund proportionate premium for unexpired policy period for the current \\npolicy year. \\nThere shall be no refund for the completed policy year elapsed.', 'type': 'text'}, score=0.677854538, boost=None, combined_score=None),\n", " ClauseHit(doc_id='b0a34a7d-f5a1-4777-93aa-c59269013de5', page=24, chunk_id='b0a34a7d-f5a1-4777-93aa-c59269013de5_p24', text='all claims made in the aggregate during each policy year. \\n \\n2.21 Grace Period means the specified period of time, immediately following the premium due date during which premium \\npayment can be made to renew or continue a policy in force without loss of continuity benefits pertaining to Waiting Periods \\nand coverage of Pre-Existing Diseases. The Grace Period for payment of the premium shall be thirty days. \\nCoverage shall not be available during the period for which no premium is received. \\n \\n2.22 Hospital means any institution established for in-patient care and day care treatment of disease/ injuries and which has been \\nregistered as a hospital with the local authorities under the Clinical Establishments (Registration and Regulation) Act, 2010 or', metadata={'chunk_id': 'b0a34a7d-f5a1-4777-93aa-c59269013de5_p24', 'doc_id': 'b0a34a7d-f5a1-4777-93aa-c59269013de5', 'page': 24.0, 'text': 'all claims made in the aggregate during each policy year. \\n \\n2.21 Grace Period means the specified period of time, immediately following the premium due date during which premium \\npayment can be made to renew or continue a policy in force without loss of continuity benefits pertaining to Waiting Periods \\nand coverage of Pre-Existing Diseases. The Grace Period for payment of the premium shall be thirty days. \\nCoverage shall not be available during the period for which no premium is received. \\n \\n2.22 Hospital means any institution established for in-patient care and day care treatment of disease/ injuries and which has been \\nregistered as a hospital with the local authorities under the Clinical Establishments (Registration and Regulation) Act, 2010 or', 'type': 'text'}, score=0.64794, boost=None, combined_score=None)]" ] }, "execution_count": 48, "metadata": {}, "output_type": "execute_result" } ], "source": [ "top_hits" ] }, { "cell_type": "code", "execution_count": 75, "id": "05cb7ca5", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1) [source:b0a34a7d-f5a1-4777-93aa-c59269013de5 page:24] Page 16 of 25 \n", "National Parivar Mediclaim Plus Policy \n", "UIN: NICHLIP25039V032425 \n", " \n", "ii. The policyholder may cancel his/her policy at any time during the term, by giving 7 days’ notice in writing. The Insurer shall: \n", "a) refund proportionate premium for unexpired policy period, if the term of policy upto one year and there is no claim (s) \n", "made during the policy period. \n", "b) refund premium for the unexpired policy period, in respect of policies with term more than 1 year and risk coverage for \n", "such policy years has not commenced and refund proportionate premium for unexpired policy period for the current \n", "policy year. \n", "There shall be no refund for the completed policy year elapsed.\n", "2) [source:b0a34a7d-f5a1-4777-93aa-c59269013de5 page:24] Page 16 of 25 \n", "National Parivar Mediclaim Plus Policy \n", "UIN: NICHLIP25039V032425 \n", " \n", "ii. The policyholder may cancel his/her policy at any time during the term, by giving 7 days’ notice in writing. The Insurer shall: \n", "a) refund proportionate premium for unexpired policy period, if the term of policy upto one year and there is no claim (s) \n", "made during the policy period. \n", "b) refund premium for the unexpired policy period, in respect of policies with term more than 1 year and risk coverage for \n", "such policy years has not commenced and refund proportionate premium for unexpired policy period for the current \n", "policy year. \n", "There shall be no refund for the completed policy year elapsed.\n", "3) [source:b0a34a7d-f5a1-4777-93aa-c59269013de5 page:24] all claims made in the aggregate during each policy year. \n", " \n", "2.21 Grace Period means the specified period of time, immediately following the premium due date during which premium \n", "payment can be made to renew or continue a policy in force without loss of continuity benefits pertaining to Waiting Periods \n", "and coverage of Pre-Existing Diseases. The Grace Period for payment of the premium shall be thirty days. \n", "Coverage shall not be available during the period for which no premium is received. \n", " \n", "2.22 Hospital means any institution established for in-patient care and day care treatment of disease/ injuries and which has been \n", "registered as a hospital with the local authorities under the Clinical Establishments (Registration and Regulation) Act, 2010 or\n" ] } ], "source": [ "# Step 3 — Evaluate with LLM\n", "result = evaluate_with_llm(query, top_hits)" ] }, { "cell_type": "code", "execution_count": 73, "id": "40c7075b", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'The grace period for premium payment under the National Parivar Mediclaim Plus Policy is thirty days. However, coverage is not available during this period if no premium is received.'" ] }, "execution_count": 73, "metadata": {}, "output_type": "execute_result" } ], "source": [ "result.answer" ] }, { "cell_type": "code", "execution_count": 82, "id": "46ff44ac", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "C:\\Users\\hp\\AppData\\Local\\Temp\\ipykernel_9600\\3651844483.py:1: PydanticDeprecatedSince20: The `__fields__` attribute is deprecated, use `model_fields` instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.11/migration/\n", " result.evidence[0].__fields__\n" ] }, { "data": { "text/plain": [ "{'doc_id': FieldInfo(annotation=str, required=True),\n", " 'page': FieldInfo(annotation=int, required=True),\n", " 'chunk_id': FieldInfo(annotation=str, required=True),\n", " 'text': FieldInfo(annotation=str, required=True),\n", " 'metadata': FieldInfo(annotation=Dict[str, Any], required=True),\n", " 'score': FieldInfo(annotation=float, required=True),\n", " 'boost': FieldInfo(annotation=Union[float, NoneType], required=False, default=None),\n", " 'combined_score': FieldInfo(annotation=Union[float, NoneType], required=False, default=None)}" ] }, "execution_count": 82, "metadata": {}, "output_type": "execute_result" } ], "source": [ "result.evidence[0].__fields__" ] }, { "cell_type": "markdown", "id": "5e804911", "metadata": {}, "source": [ "## Uploading multiple types of files\n", "1. PDF \n", "2. docx \n", "3. url \n", "3. txt " ] }, { "cell_type": "code", "execution_count": 1, "id": "85c5c485", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'c:\\\\code\\\\Bajaj HackRx\\\\Rag_app'" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "%pwd" ] }, { "cell_type": "code", "execution_count": 16, "id": "b1acc792", "metadata": {}, "outputs": [], "source": [ "from langchain_community.document_loaders import (\n", " PyPDFLoader,\n", " PyMuPDFLoader,\n", " UnstructuredPDFLoader\n", ")\n", "\n", "pypdf_loader = PyPDFLoader(r\"C:\\code\\Bajaj HackRx\\Rag_app\\app\\uploads\\CHOTGDP23004V012223.pdf\")\n", "doc = pypdf_loader.load()\n" ] }, { "cell_type": "code", "execution_count": null, "id": "f0587d86", "metadata": {}, "outputs": [], "source": [ "pypdf_loader = PyMuPDFLoader(r\"C:\\code\\Bajaj HackRx\\Rag_app\\app\\uploads\\CHOTGDP23004V012223.pdf\")\n", "doc = pypdf_loader.load()" ] }, { "cell_type": "code", "execution_count": 18, "id": "b2106c8d", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "langchain_core.documents.base.Document" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type(doc[0])" ] }, { "cell_type": "code", "execution_count": 19, "id": "079ed7e3", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'producer': 'Microsoft® Word 2013',\n", " 'creator': 'Microsoft® Word 2013',\n", " 'creationdate': '2022-07-12T15:10:23+05:30',\n", " 'source': 'C:\\\\code\\\\Bajaj HackRx\\\\Rag_app\\\\app\\\\uploads\\\\CHOTGDP23004V012223.pdf',\n", " 'file_path': 'C:\\\\code\\\\Bajaj HackRx\\\\Rag_app\\\\app\\\\uploads\\\\CHOTGDP23004V012223.pdf',\n", " 'total_pages': 101,\n", " 'format': 'PDF 1.5',\n", " 'title': '',\n", " 'author': 'Padmapriya C-Manager-Product Management-HO-Chola Ms',\n", " 'subject': '',\n", " 'keywords': '',\n", " 'moddate': '2022-07-12T15:10:23+05:30',\n", " 'trapped': '',\n", " 'modDate': \"D:20220712151023+05'30'\",\n", " 'creationDate': \"D:20220712151023+05'30'\",\n", " 'page': 0}" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "doc[0].metadata" ] }, { "cell_type": "code", "execution_count": 201, "id": "67f0ec51", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n" ] } ], "source": [ "import requests\n", "from langchain_community.document_loaders import PyMuPDFLoader\n", "import os\n", "from langchain_community.document_loaders import Docx2txtLoader\n", "import io\n", "import tempfile\n", "\n", "\n", "class fileloader: \n", " def __init__(self):\n", " self.pdf_document = None\n", "\n", " def load_documents_from_url(self, url: str):\n", " response = requests.get(url)\n", " response.raise_for_status()\n", " if response.headers['Content-Type'] == 'application/pdf':\n", " # Save PDF to a temporary file\n", " with tempfile.NamedTemporaryFile(suffix=\".pdf\", delete=False) as tmp_file:\n", " tmp_file.write(response.content)\n", " tmp_file_path = tmp_file.name\n", " \n", " # Load PDF from the temporary file path\n", " loader = PyMuPDFLoader(tmp_file_path)\n", " docs = loader.load()\n", " return docs\n", " else:\n", " raise ValueError(\"File type not supported, expected a PDF.\")\n", " \n", " \n", " \n", " def load_pdf(self, path:str):\n", " \"\"\" Load PDF from a local path and return its content.\"\"\"\n", " if not os.path.exists(path):\n", " raise FileNotFoundError(f\"The file {path} does not exist.\")\n", " loader = PyMuPDFLoader(path)\n", " pdf_document = loader.load()\n", " return pdf_document\n", " \n", " ## word document processing\n", "\n", " def load_word_document(self, path: str):\n", " try: \n", " docx_loader = Docx2txtLoader(path)\n", " docs = docx_loader.load()\n", " return docs\n", " except Exception as e:\n", " print(e)\n", " \n", "\n", " \n", "objec = fileloader()\n", "url =\"https://hackrx.blob.core.windows.net/assets/policy.pdf?sv=2023-01-03&st=2025-07-04T09%3A11%3A24Z&se=2027-07-05T09%3A11%3A00Z&sr=b&sp=r&sig=N4a9OU0w0QXO6AOIBiu4bpl7AXvEZogeT%2FjUHNO7HzQ%3D\"\n", "\n", "pdf_doc = objec.load_documents_from_url(url= url)\n", "len(pdf_doc)\n", "print(type(pdf_doc[0]))\n", "\n", "# doc = objec.load_pdf(r\"C:\\code\\Bajaj HackRx\\Rag_app\\app\\uploads\\CHOTGDP23004V012223.pdf\")\n", "# print(len(doc))\n", "# print(type(doc[0]))\n", "\n", "# doc = objec.load_word_document(r\"C:\\code\\Bajaj HackRx\\Rag_app\\app\\uploads\\hhh.docx\")\n", "# print(len(doc))\n", "# print(type(doc[0]))\n", "\n", "\n" ] }, { "cell_type": "code", "execution_count": 202, "id": "c682496a", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "25" ] }, "execution_count": 202, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len(pdf_doc)" ] }, { "cell_type": "code", "execution_count": 77, "id": "415f5a76", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "6" ] }, "execution_count": 77, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len(doc)" ] }, { "cell_type": "code", "execution_count": 2, "id": "c50c0eb0", "metadata": {}, "outputs": [], "source": [ "## creating chunks\n", "from langchain_core.documents import Document\n", "from langchain.text_splitter import RecursiveCharacterTextSplitter\n", "from langchain.prompts import PromptTemplate\n", "from uuid import uuid4\n", "from typing import List, Dict\n", "\n", "\n", "class splitting_text:\n", "\n", " def _clean_text(self, text:str)-> str: \n", " \"\"\"Clean extracted page content\"\"\"\n", " # remove excessive whitespace \n", " text = \" \".join(text.split())\n", " return text\n", "\n", " def text_splitting(self, doc_content: List[Document]) -> List[Document]:\n", " splitter = RecursiveCharacterTextSplitter(chunk_size=800, chunk_overlap=100)\n", " all_chunks = []\n", "\n", " for i, page in enumerate(doc_content): \n", " # reset per page\n", " try:\n", " text = page.get_text()\n", " except:\n", " text = page.page_content\n", " \n", " text = self._clean_text(text)\n", " if text.strip():\n", " uuid = str(uuid4())\n", " temp_doc = Document(\n", " page_content=text,\n", " metadata={\n", " **page.metadata,\n", " \"page_no\": i,\n", " \"doc_id\": uuid,\n", " \"chunk_id\": f\"{uuid}_p{i}\",\n", " \"type\": \"text\"\n", " }\n", " )\n", " chunks = splitter.split_documents([temp_doc])\n", " all_chunks.extend(chunks)\n", "\n", " return all_chunks\n", "\n", "# objec2 = splitting_text()\n", "# chunk= objec2.text_splitting(doc)" ] }, { "cell_type": "code", "execution_count": 80, "id": "cbc639be", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Document(metadata={'source': 'C:\\\\code\\\\Bajaj HackRx\\\\Rag_app\\\\app\\\\uploads\\\\hhh.docx', 'page_no': 0, 'doc_id': 'f35e1a03-df9d-43c4-91bd-f389a5ccf765', 'chunk_id': 'f35e1a03-df9d-43c4-91bd-f389a5ccf765_p0', 'type': 'text'}, page_content='Daily All Day Sea Buckthorn Juice (500ml) Key Ingredients of Daily All Day Sea Buckthorn Juice (500ml) Sea Buckthorn (Raw Pulp)- Rich in Omega 3 6 9 and rare Omega 7, Vitamin C, E, flavonoids, carotenoids; supports skin, heart, immunity, heart health and metabolism. Benefits of Daily All Day Sea Buckthorn Juice (500ml) Glowing Skin & Hair- Boosts collagen production, maintains skin hydration, reverse wrinkles and brings a natural glow on skin.. Boosts Immunity- Its high antioxidants helps protect against infections and oxidative stress. Supports Heart Health- Helps in maintaining healthy cholesterol. Metabolism- Supports the body and digestion. 100% Natural- Made with raw pulp; no artificial sugar, colors, or ingredients added. Certified Quality- Lab-tested, FSSAI approved, ISO, HACCP, and')" ] }, "execution_count": 80, "metadata": {}, "output_type": "execute_result" } ], "source": [ "chunk[0]" ] }, { "cell_type": "code", "execution_count": 47, "id": "5b34ea42", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'producer': 'Microsoft® Word 2013',\n", " 'creator': 'Microsoft® Word 2013',\n", " 'creationdate': '2022-07-12T15:10:23+05:30',\n", " 'source': 'C:\\\\code\\\\Bajaj HackRx\\\\Rag_app\\\\app\\\\uploads\\\\CHOTGDP23004V012223.pdf',\n", " 'file_path': 'C:\\\\code\\\\Bajaj HackRx\\\\Rag_app\\\\app\\\\uploads\\\\CHOTGDP23004V012223.pdf',\n", " 'total_pages': 101,\n", " 'format': 'PDF 1.5',\n", " 'title': '',\n", " 'author': 'Padmapriya C-Manager-Product Management-HO-Chola Ms',\n", " 'subject': '',\n", " 'keywords': '',\n", " 'moddate': '2022-07-12T15:10:23+05:30',\n", " 'trapped': '',\n", " 'modDate': \"D:20220712151023+05'30'\",\n", " 'creationDate': \"D:20220712151023+05'30'\",\n", " 'page': 1,\n", " 'page_no': 1,\n", " 'doc_id': 'd3f28693-f71c-4a39-91e3-a77b8d9f8eea',\n", " 'chunk_id': 'd3f28693-f71c-4a39-91e3-a77b8d9f8eea_p1',\n", " 'type': 'text'}" ] }, "execution_count": 47, "metadata": {}, "output_type": "execute_result" } ], "source": [ "chunk[2].metadata" ] }, { "cell_type": "code", "execution_count": 71, "id": "4d9f8da9", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Document(metadata={'source': 'C:\\\\code\\\\Bajaj HackRx\\\\Rag_app\\\\app\\\\uploads\\\\hhh.docx'}, page_content='Daily All Day Sea Buckthorn Juice (500ml)\\n\\nKey Ingredients of Daily All Day Sea Buckthorn Juice (500ml)\\n\\nSea Buckthorn (Raw Pulp)- Rich in Omega 3 6 9 and rare Omega 7, Vitamin C, E, flavonoids, carotenoids; supports skin, heart, immunity, heart health and metabolism.\\n\\nBenefits of Daily All Day Sea Buckthorn Juice (500ml)\\n\\nGlowing Skin & Hair- Boosts collagen production, maintains skin hydration, reverse wrinkles and brings a natural glow on skin..\\n\\nBoosts Immunity- Its high antioxidants helps protect against infections and oxidative stress.\\n\\nSupports Heart Health- Helps in maintaining healthy cholesterol.\\n\\nMetabolism- Supports the body and digestion.\\n\\n\\n\\n100% Natural- Made with raw pulp; no artificial sugar, colors, or ingredients added.\\n\\nCertified Quality- Lab-tested, FSSAI approved, ISO, HACCP, and GMP certified.\\n\\nHolistic Formula- A functional superfruit juice supporting skin glow, immune resilience, and digestive balance.\\n\\nUnlike conventional capsules made with gelatin (animal-derived), our capsules are 100% plant-based, made from cellulose, a natural, vegan-friendly alternative.\\n\\nUnique Point- Our sea buckthorn juice is made from pure raw pulp with no additives, preserving its full-spectrum nutrients for real results.\\n\\nHow to Consume- Mix 3 spoons of juice in a glass of water, twice a day. Not to be taken on an empty stomach.\\n\\nResults- For best results, use consistently for at least 6-8 weeks. Individual responses may vary, and supplements work best when combined with a balanced diet and healthy lifestyle.\\n\\nCaution & Avoid- Not for use during pregnancy or for lactating mothers.\\nAvoid if you are on medication or have known allergies or reactions to any ingredients. Keep out of reach of children. This product is not intended to diagnose, treat, cure, or prevent any disease.\\n\\n\\n\\nLink Daily All Day Sea Buckthorn Juice (500ml) https://dailyallday.in/products/sea-buckthorn-juice-for-clear-skin-hydration-glow\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nDaily All Day Strength Essence (90 Capsules)\\n\\n\\n\\nKey Ingredients Daily All Day Strength Essence (90 Capsules)\\n\\nAshwagandha- Supports stress relief and boosts stamina; Shilajit- Enhances energy and endurance; Gokhru- Aids in muscle building and vitality; Kaunch Beej- Promotes strength and reduces fatigue.\\n\\n\\n\\nBenefits Daily All Day Strength Essence (90 Capsules)\\n\\nBuilds Muscle- Supports lean muscle development.\\n\\nReduces Stress- Helps combat mental and physical stress.\\n\\nFights Fatigue- Keeps you energized and productive.\\n\\nBoosts Stamina- Enhances overall performance.\\n\\n\\n\\n100% Vegetarian and free from toxins.\\n\\nCertified Quality- Lab-tested, FSSAI approved, ISO, HACCP, and GMP certified.\\n\\nTrusted Formula- A blend of Ayurvedic herbs for strength and wellness.\\n\\nUnlike conventional capsules made with gelatin (animal-derived), our capsules are 100% plant-based, made from cellulose; a natural, vegan-friendly alternative.\\n\\nUnique Point- Builds muscles and restores energy with a rare formulation of Ashwagandha, Shilajit, Kaunch and Gokhru together.\\n\\nQuantity/ Formulation of each ingredient of 500mg capsule is: Ashwagandha-150mg, Shilajit- 100mg, Gokhru- 125mg, Kaunch Beej- 125mg\\nHow to Consume- Take 1 capsule twice daily, after meals — one in the morning and one in the evening.\\n\\nResults- For best results, use consistently for at least 6-8 weeks. Individual responses may vary, and supplements work best when combined with a balanced diet and healthy lifestyle.\\n\\nTotal Serving- 90 capsules per bottle; 2 capsules daily; 45-day supply.\\n\\nRDA- All ingredients that have an RDA are used within safe, approved limits as per FSSAI guidelines.\\n\\nCaution & Avoid- Not for use during pregnancy or for lactating mothers.\\nAvoid if you are on medication or have known allergies or reactions to any ingredients.\\nKeep out of reach of children.\\nThis product is not intended to diagnose, treat, cure, or prevent any disease.\\n\\n\\n\\nLink- Daily All Day Strength Essence (90 Capsules)')" ] }, "execution_count": 71, "metadata": {}, "output_type": "execute_result" } ], "source": [ "## word document processing\n", "from langchain_community.document_loaders import Docx2txtLoader\n", "\n", "def load_word_document(path: str):\n", " try: \n", " docx_loader = Docx2txtLoader(path)\n", " docs = docx_loader.load_and_split()\n", " return docs\n", " except Exception as e:\n", " print(e)\n", "\n", "word_doc = load_word_document(r\"C:\\code\\Bajaj HackRx\\Rag_app\\app\\uploads\\hhh.docx\")\n", "# len(word_doc)\n", "word_doc[0]" ] }, { "cell_type": "code", "execution_count": 72, "id": "f4eccb0c", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "6" ] }, "execution_count": 72, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len(word_doc)" ] }, { "cell_type": "code", "execution_count": 75, "id": "c18fdc98", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'source': 'C:\\\\code\\\\Bajaj HackRx\\\\Rag_app\\\\app\\\\uploads\\\\hhh.docx'}" ] }, "execution_count": 75, "metadata": {}, "output_type": "execute_result" } ], "source": [ "word_doc" ] }, { "cell_type": "markdown", "id": "5fc3ca9d", "metadata": {}, "source": [ "## Augmentation\n", "### adding metadata in chunks with langextract\n", "1. upload the document\n", "2. detect the type of document\n", "- Hr/Employment\n", "- Insuarance\n", "- Legal / Compliance\n", "- Financial / Regulatory\n", "- Government / Public Policy\n", "- Technical / IT Policies\n", "\n", "3. extract metadata per page using langextract\n", "4. split into chunks as langchain document\n", "5. add into vectore store" ] }, { "cell_type": "markdown", "id": "2d4a836a", "metadata": {}, "source": [ "1. upload the document" ] }, { "cell_type": "code", "execution_count": 1, "id": "1336a106", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "File type: pdf\n" ] } ], "source": [ "import os\n", "\n", "def get_file_type_by_extension(filename):\n", " _, extension = os.path.splitext(filename)\n", " extension = extension.lower()\n", " if extension == \".txt\":\n", " return \"text\"\n", " elif extension == \".pdf\":\n", " return \"pdf\"\n", " elif extension in [\".doc\", \".docx\"]:\n", " return \"word\"\n", " else:\n", " return \"unknown\"\n", "\n", "# Example usage \n", "# to be added in main.py\n", "uploaded_file_path = r\"app\\uploads\\policy.pdf\"\n", "file_type = get_file_type_by_extension(uploaded_file_path)\n", "print(f\"File type: {file_type}\")" ] }, { "cell_type": "code", "execution_count": 3, "id": "00213601", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[Document(metadata={'producer': 'Microsoft® Word LTSC', 'creator': 'Microsoft® Word LTSC', 'creationdate': '2025-02-11T11:39:19+05:30', 'source': 'app\\\\uploads\\\\policy.pdf', 'file_path': 'app\\\\uploads\\\\policy.pdf', 'total_pages': 25, 'format': 'PDF 1.7', 'title': 'National Parivar Mediclaim Plus Policy (NPMPP)', 'author': 'Avishek Banerjee', 'subject': '', 'keywords': '', 'moddate': '2025-02-11T11:39:19+05:30', 'trapped': '', 'modDate': \"D:20250211113919+05'30'\", 'creationDate': \"D:20250211113919+05'30'\", 'page': 0}, page_content='National Insurance Co. Ltd. \\nPremises No. 18-0374, Plot no. CBD-81, \\nNew Town, Kolkata - 700156 \\nPage 1 of 25 \\nNational Parivar Mediclaim Plus Policy \\nUIN: NICHLIP25039V032425 \\n \\nNational Insurance Company Limited \\n \\n \\n \\n \\n \\nCIN - U10200WB1906GOI001713 \\nIRDAI Regn. No. – 58 \\n \\n Issuing Office \\nNational Parivar Mediclaim Plus Policy \\n \\nWhereas the Proposer designated in the schedule hereto has by a Proposal together with Declaration, which shall be the basis of \\nthis contract and is deemed to be incorporated herein, has applied to National Insurance Company Ltd. (hereinafter called the \\nCompany), for the insurance hereinafter set forth, in respect of person(s)/ family members named in the schedule hereto \\n(hereinafter called the Insured Persons) and has paid the premium as consideration for such insurance. \\n \\n1 PREAMBLE \\nThe Company undertakes that if during the Policy Period, any Insured Person shall suffer any illness or disease (hereinafter called \\nIllness) or sustain any bodily injury due to an Accident (hereinafter called Injury) requiring Hospitalisation of such Insured \\nPerson(s) for In-Patient Care at any hospital/nursing home (hereinafter called Hospital) or for Day Care Treatment at any Day \\nCare Center or to undergo treatment under Domiciliary Hospitalisation, following the Medical Advice of a duly qualified Medical \\nPractitioner, the Company shall indemnify the Hospital or the Insured, Reasonable and Customary Charges incurred for Medically \\nNecessary Treatment towards the Coverage mentioned herein. \\nProvided further that, the amount payable under the Policy in respect of all such claims during each Policy Year of the Policy \\nPeriod shall be subject to the Definitions, Terms, Exclusions, Conditions contained herein and limits as shown in the Table of \\nBenefits, and shall not exceed the Floater Sum Insured in respect of the Insured family. \\n \\n2 DEFINITIONS \\n2.1 Accident means a sudden, unforeseen and involuntary event caused by external, visible and violent means. \\n \\n2.2 Age / Aged means completed years on last birthday as on Policy commencement date. \\n \\n2.3 AIDS means Acquired Immune Deficiency Syndrome, a condition characterised by a combination of signs and symptoms, \\ncaused by Human Immunodeficiency Virus (HIV), which attacks and weakens the body’s immune system making the HIV-\\npositive person susceptible to life threatening conditions or other conditions, as may be specified from time to time. \\n \\n2.4 Any One Illness means continuous period of illness and it includes relapse within forty five days from the date of last \\nconsultation with the hospital where treatment has been taken. \\n \\n2.5 AYUSH Day Care Centre means and includes Community Health Centre (CHC), Primary Health Centre (PHC), Dispensary, \\nClinic, Polyclinic or any such health centre which is registered with the local authorities, wherever applicable and having \\nfacilities for carrying out treatment procedures and medical or surgical / para-surgical interventions or both under the \\nsupervision of registered AYUSH Medical Practitioner(s) on day care basis without in-patient services and must comply with \\nall the following criterion: \\ni. Having qualified registered AYUSH Medical Practitioner in charge round the clock; \\nii. Having dedicated AYUSH therapy sections as required and/or has equipped operation theatre where surgical procedures \\nare to be carried out; \\niii. Maintaining daily records of the patients and making them accessible to the insurance company’s authorized \\nrepresentative. \\n \\n2.6 AYUSH Treatment refers to the medical and / or Hospitalisation treatments given Ayurveda, Yoga and Naturopathy, Unani, \\nSiddha and Homeopathy systems. \\n \\n2.7 AYUSH Hospital is a healthcare facility wherein medical/surgical/para-surgical treatment procedures and interventions are \\ncarried out by AYUSH Medical Practitioner(s) comprising of any of the following: \\na. Central or State Government AYUSH Hospital or \\nb. Teaching hospital attached to AYUSH College recognized by the Central Government/ Central Council of Indian \\nMedicine/ Central Council for Homeopathy; or \\nc. AYUSH Hospital, standalone or co-located with in-patient healthcare facility of any recognized system of medicine, \\nregistered with the local authorities, wherever applicable, and is under the supervision of a qualified registered \\nAYUSH Medical Practitioner and must comply with all the following criterion: \\ni. Having at least 5 in-patient beds; \\nii. Having qualified AYUSH Medical Practitioner in charge round the clock; \\niii. Having dedicated AYUSH therapy sections as required; \\niv. Maintaining daily records of the patients and making them accessible to the insurance company’s authorized \\nrepresentative \\n \\n2.8 Break in policy means the period of gap that occurs at the end of the existing Policy Period due date, when the premium due \\nfor renewal on a given policy or instalment premium due is not paid on or before the premium renewal date or grace period.'),\n", " Document(metadata={'producer': 'Microsoft® Word LTSC', 'creator': 'Microsoft® Word LTSC', 'creationdate': '2025-02-11T11:39:19+05:30', 'source': 'app\\\\uploads\\\\policy.pdf', 'file_path': 'app\\\\uploads\\\\policy.pdf', 'total_pages': 25, 'format': 'PDF 1.7', 'title': 'National Parivar Mediclaim Plus Policy (NPMPP)', 'author': 'Avishek Banerjee', 'subject': '', 'keywords': '', 'moddate': '2025-02-11T11:39:19+05:30', 'trapped': '', 'modDate': \"D:20250211113919+05'30'\", 'creationDate': \"D:20250211113919+05'30'\", 'page': 1}, page_content='National Insurance Co. Ltd. \\nPremises No. 18-0374, Plot no. CBD-81, \\nNew Town, Kolkata - 700156 \\nPage 2 of 25 \\nNational Parivar Mediclaim Plus Policy \\nUIN: NICHLIP25039V032425 \\n \\n2.9 Cashless Facility means a facility extended by the Company to the Insured where the payments of the costs of treatment \\nundergone by the Insured in accordance with the Policy terms and conditions, are directly made to the Network Provider or a \\nNon Network Provider to the extent pre-authorization approved. \\n \\n2.10 Condition Precedent means a Policy term or condition upon which the Company’s liability by the Policy is conditional upon. \\n \\n2.11 Contract means prospectus, proposal, Policy, and the policy schedule. Any alteration with the mutual consent of the insured \\nperson and the insurer can be made only by a duly signed and sealed endorsement on the Policy. \\n \\n2.12 Congenital anomaly refers to a condition(s) which is present since birth, and which is abnormal with reference to form, \\nstructure or position: \\na) Internal Congenital Anomaly \\nCongenital anomaly which is not in the visible and accessible parts of the body. \\nb) External Congenital Anomaly \\nCongenital anomaly which is in the visible and accessible parts of the body. \\n \\n2.13 Co-payment means a cost-sharing requirement by the Policy that provides that the insured shall bear a specified percentage of \\nthe admissible claim amount. A co-payment does not reduce the Sum Insured. \\n \\n2.14 Day Care Centre means any institution established for day care treatment of disease/ injuries or a medical setup within a \\nhospital and which has been registered with the local authorities, wherever applicable, and is under the supervision of a \\nregistered and qualified medical practitioner AND must comply with all minimum criteria as under: \\ni. \\nhas qualified nursing staff under its employment; \\nii. has qualified medical practitioner (s) in charge; \\niii. has a fully equipped operation theatre of its own where surgical procedures are carried out \\niv. maintains daily records of patients and shall make these accessible to the Company’s authorized personnel. \\n \\n2.15 Day Care Treatment means medical treatment, and/or surgical procedure which is: \\ni. \\nundertaken under general or local anesthesia in a hospital/day care centre in less than twenty-four hrs because of \\ntechnological advancement, and \\nii. which would have otherwise required a hospitalisation of more than twenty-four hours. \\nTreatment normally taken on an out-patient basis is not included in the scope of this definition. \\n \\n2.16 Dental Treatment means a treatment carried out by a dental practitioner including examinations, fillings (where appropriate), \\ncrowns, extractions and surgery excluding any form of cosmetic surgery/implants. \\n \\n2.17 Diagnosis means diagnosis by a medical practitioner, supported by clinical, radiological, histological and laboratory evidence, \\nacceptable to the Company. \\n \\n2.18 Domiciliary Hospitalisation means medical treatment for an illness /injury which in the normal course would require care \\nand treatment at a hospital but is actually taken while confined at home under any of the following circumstances. \\ni. \\nthe condition of the patient is such that he/she is not in a condition to be removed to a hospital, or \\nii. the patient takes treatment at home on account of non availability of bed/ room in a hospital. \\n \\n2.19 Family members means spouse, children and parents of the insured, covered by the Policy. \\n \\n2.20 Floater Sum Insured means the sum insured, as mentioned in the Schedule, available to all the insured persons, for any and \\nall claims made in the aggregate during each policy year. \\n \\n2.21 Grace Period means the specified period of time, immediately following the premium due date during which premium \\npayment can be made to renew or continue a policy in force without loss of continuity benefits pertaining to Waiting Periods \\nand coverage of Pre-Existing Diseases. The Grace Period for payment of the premium shall be thirty days. \\nCoverage shall not be available during the period for which no premium is received. \\n \\n2.22 Hospital means any institution established for in-patient care and day care treatment of disease/ injuries and which has been \\nregistered as a hospital with the local authorities under the Clinical Establishments (Registration and Regulation) Act, 2010 or \\nunder the enactments specified under Schedule of Section 56(1) of the said Act, OR complies with all minimum criteria as \\nunder: \\ni. \\nhas qualified nursing staff under its employment round the clock; \\nii. has at least ten inpatient beds, in those towns having a population of less than ten lacs and fifteen inpatient beds in \\nall other places; \\niii. has qualified medical practitioner (s) in charge round the clock; \\niv. has a fully equipped operation theatre of its own where surgical procedures are carried out \\nv. maintains daily records of patients and shall make these accessible to the Company’s authorized personnel.'),\n", " Document(metadata={'producer': 'Microsoft® Word LTSC', 'creator': 'Microsoft® Word LTSC', 'creationdate': '2025-02-11T11:39:19+05:30', 'source': 'app\\\\uploads\\\\policy.pdf', 'file_path': 'app\\\\uploads\\\\policy.pdf', 'total_pages': 25, 'format': 'PDF 1.7', 'title': 'National Parivar Mediclaim Plus Policy (NPMPP)', 'author': 'Avishek Banerjee', 'subject': '', 'keywords': '', 'moddate': '2025-02-11T11:39:19+05:30', 'trapped': '', 'modDate': \"D:20250211113919+05'30'\", 'creationDate': \"D:20250211113919+05'30'\", 'page': 2}, page_content='National Insurance Co. Ltd. \\nPremises No. 18-0374, Plot no. CBD-81, \\nNew Town, Kolkata - 700156 \\nPage 3 of 25 \\nNational Parivar Mediclaim Plus Policy \\nUIN: NICHLIP25039V032425 \\n \\n2.23 Hospitalisation means admission in a Hospital or mental health establishment for a minimum period of twenty four (24) \\nconsecutive ‘Inpatient care’ hours except for procedures/ treatments, where such admission could be for a period of less than \\ntwenty four (24) consecutive hours. \\n \\n2.24 ICU (Intensive Care Unit) Charges means the amount charged by a Hospital towards ICU expenses which shall include the \\nexpenses for ICU bed, general medical support services provided to any ICU patient including monitoring devices, critical care \\nnursing and intensivist charges. \\n \\n2.25 ID Card means the card issued to the insured person by the TPA for availing Cashless Facility. \\n \\n2.26 Illness means a sickness or a disease or pathological condition leading to the impairment of normal physiological function \\nwhich manifests itself during the policy period and requires medical treatment. \\ni. \\nAcute Condition means a disease, illness or injury that is likely to response quickly to treatment which aims to return \\nthe person to his or her state of health immediately before suffering the disease/ illness/ injury which leads to full \\nrecovery. \\nii. Chronic Condition means a disease, illness, or injury that has one or more of the following characteristics \\na) it needs ongoing or long-term monitoring through consultations, examinations, check-ups, and / or tests \\nb) it needs ongoing or long-term control or relief of symptoms \\nc) it requires your rehabilitation or for you to be specially trained to cope with it \\nd) it continues indefinitely \\ne) it comes back or is likely to come back. \\n \\n2.27 In-patient Care means treatment for which the insured person has to stay in a hospital for more than 24 hours for a covered \\nevent. \\n \\n2.28 Insured / Insured Person means person(s) named in the schedule of the Policy. \\n \\n2.29 Intensive Care Unit means an identified section, ward or wing of a hospital which is under the constant supervision of a \\ndedicated medical practitioner(s), and which is specially equipped for the continuous monitoring and treatment of patients who \\nare in a critical condition, or require life support facilities and where the level of care and supervision is considerably more \\nsophisticated and intensive than in the ordinary and other wards. \\n \\n2.30 Injury means accidental physical bodily harm excluding disease solely and directly caused by external, violent and visible and \\nevident means which is verified and certified by a medical practitioner. \\n \\n2.31 Medical Advice means any consultation or advice from a Medical Practitioner including the issue of any prescription or repeat \\nprescription. \\n \\n2.32 Medical Expenses means those expenses that an insured person has necessarily and actually incurred for medical treatment \\non account of disease/ injury on the advice of a medical practitioner, as long as these are no more than would have been payable \\nif the insured person had not been insured and no more than other hospitals or doctors in the same locality would have charged \\nfor the same medical treatment. \\n \\n2.33 Medically Necessary Treatment means any treatment, tests, medication, or stay in hospital or part of a stay in hospital which: \\ni. \\nis required for the medical management of the disease/ injuries suffered by the insured person; \\nii. must not exceed the level of care necessary to provide safe, adequate and appropriate medical care in scope, duration, \\nor intensity; \\niii. must have been prescribed by a medical practitioner; \\niv. must conform to the professional standards widely accepted in international medical practice or by the medical \\ncommunity in India. \\n \\n2.34 Medical Practitioner means a person who holds a valid registration from the medical council of any state or Medical Council \\nof India or Council for Indian Medicine or for Homeopathy set up by the Government of India or a State Government and is \\nthereby entitled to practice medicine within its jurisdiction; and is acting within the scope and jurisdiction of the licence. \\n \\n2.35 Migration means a facility provided to policyholders (including all members under family cover and group policies), to \\ntransfer the credits gained for pre-existing diseases and specific waiting periods from one health insurance policy to another \\nwith the same insurer. \\n \\n2.36 Network Provider means Hospitals or Day Care Centres enlisted by the Company or jointly by the Company and a TPA to \\nprovide medical services to an insured person on payment by a cashless facility. \\n \\n2.37 New Born Baby means baby born during the policy period and is aged upto 90 days. \\n \\n2.38 Non- Network means any Hospital, Day Care Centre that is not part of the network.'),\n", " Document(metadata={'producer': 'Microsoft® Word LTSC', 'creator': 'Microsoft® Word LTSC', 'creationdate': '2025-02-11T11:39:19+05:30', 'source': 'app\\\\uploads\\\\policy.pdf', 'file_path': 'app\\\\uploads\\\\policy.pdf', 'total_pages': 25, 'format': 'PDF 1.7', 'title': 'National Parivar Mediclaim Plus Policy (NPMPP)', 'author': 'Avishek Banerjee', 'subject': '', 'keywords': '', 'moddate': '2025-02-11T11:39:19+05:30', 'trapped': '', 'modDate': \"D:20250211113919+05'30'\", 'creationDate': \"D:20250211113919+05'30'\", 'page': 3}, page_content='National Insurance Co. Ltd. \\nPremises No. 18-0374, Plot no. CBD-81, \\nNew Town, Kolkata - 700156 \\nPage 4 of 25 \\nNational Parivar Mediclaim Plus Policy \\nUIN: NICHLIP25039V032425 \\n \\n2.39 Notification of Claim means the process of intimating a claim to the Company or TPA through any of the recognized modes \\nof communication. \\n \\n2.40 Out-Patient Treatment means treatment in which the insured person visits a clinic / hospital or associated facility like a \\nconsultation room for diagnosis and treatment based on the advise of a medical practitioner and the insured person is not \\nadmitted as a day care patient or in-patient. \\n \\n2.41 Policy Period means period of one policy year/ two policy years/ three policy years as mentioned in the schedule for which \\nthe Policy is issued. \\n \\n2.42 Policy Year means a period of twelve months beginning from the date of commencement of the policy period and ending on \\nthe last day of such twelve month period. For the purpose of subsequent years, policy year shall mean a period of twelve months \\ncommencing from the end of the previous policy year and lapsing on the last day of such twelve-month period, till the policy \\nperiod, as mentioned in the schedule. \\n \\n2.43 Preferred Provider Network (PPN) means a network of hospitals which have agreed to a cashless packaged pricing for listed \\nprocedures for the insured person. The list is available on the website of the Company/TPA and subject to amendment from \\ntime to time. For the updated list please visit the website of the Company/TPA. Reimbursement of expenses incurred in PPN \\nfor the procedures (as listed under PPN package) shall be subject to the rates applicable to PPN package pricing. \\n \\n2.44 Pre existing disease means any condition, ailment, injury or disease \\na) That is/are diagnosed by a physician within 36 months prior to the effective date of the Policy issued by the Company or \\nits reinstatement, or \\nb) For which Medical Advice or treatment was recommended by, or received from, a physician within 36 months prior \\nto the effective date of the Policy issued by the Company or its reinstatement. \\n \\n2.45 Portability means a facility provided to the policyholders (including all members under family cover), to transfer the credits \\ngained for, Pre-Existing Diseases and Specific Waiting Periods from one insurer to another insurer. \\n \\n2.46 Psychiatrist means a medical practitioner possessing a post-graduate degree or diploma in psychiatry awarded by an university \\nrecognised by the University Grants Commission established under the University Grants Commission Act, 1956, or awarded \\nor recognised by the National Board of Examinations and included in the First Schedule to the Indian Medical Council Act, \\n1956, or recognised by the Medical Council of India, constituted under the Indian Medical Council Act, 1956, and includes, in \\nrelation to any State, any medical officer who having regard to his knowledge and experience in psychiatry, has been declared \\nby the Government of that State to be a psychiatrist. \\n \\n2.47 Qualified Nurse means a person who holds a valid registration from the Nursing Council of India or the Nursing Council of \\nany state in India. \\n \\n2.48 Reasonable and Customary Charges means the charges for services or supplies, which are the standard charges for the \\nspecific provider and consistent with the prevailing charges in the geographical area for identical or similar services, taking into \\naccount the nature of the disease/ injury involved. \\n \\n2.49 Room Rent means the amount charged by a Hospital towards Room and boarding expenses and shall include the associated \\ncharges. \\n \\n2.50 Schedule means a document forming part of the Policy, containing details including name of the insured person, age, relation \\nof the insured person, sum insured, premium paid and the policy period. \\n \\n2.51 Surgery or Surgical Procedure means manual and / or operative procedure (s) required for treatment of a disease or injury, \\ncorrection of deformities and defects, diagnosis and cure of diseases, relief of suffering or prolongation of life, performed in a \\nhospital or day care centre by a medical practitioner. \\n \\n2.52 Third Party Administrator (TPA) means any entity, licenced under the IRDA (Third Party Administrators - Health Services) \\nRegulations, 2001 by the Authority, and is engaged, for a fee by the Company for the purpose of providing health services. \\n \\n2.53 Unproven/ Experimental Treatment means treatment, including drug therapy, which is not based on established medical \\npractice in India, is experimental or unproven. \\n \\n2.54 Waiting Period means a period from the inception of this Policy during which specified diseases/treatment is not covered. On \\ncompletion of the period, diseases/treatment shall be covered provided the Policy has been continuously renewed without any \\nbreak.'),\n", " Document(metadata={'producer': 'Microsoft® Word LTSC', 'creator': 'Microsoft® Word LTSC', 'creationdate': '2025-02-11T11:39:19+05:30', 'source': 'app\\\\uploads\\\\policy.pdf', 'file_path': 'app\\\\uploads\\\\policy.pdf', 'total_pages': 25, 'format': 'PDF 1.7', 'title': 'National Parivar Mediclaim Plus Policy (NPMPP)', 'author': 'Avishek Banerjee', 'subject': '', 'keywords': '', 'moddate': '2025-02-11T11:39:19+05:30', 'trapped': '', 'modDate': \"D:20250211113919+05'30'\", 'creationDate': \"D:20250211113919+05'30'\", 'page': 4}, page_content='National Insurance Co. Ltd. \\nPremises No. 18-0374, Plot no. CBD-81, \\nNew Town, Kolkata - 700156 \\nPage 5 of 25 \\nNational Parivar Mediclaim Plus Policy \\nUIN: NICHLIP25039V032425 \\n \\n3 BENEFITS COVERED UNDER THE POLICY \\n3.1COVERAGE \\n3.1.1 In-patient Treatment \\nThe Company shall indemnify the medical expenses for: \\ni. \\nRoom charges and intensive care unit charges (including diet charges, nursing care by qualified nurse, RMO charges, \\nadministration charges for IV fluids/blood transfusion/injection), subject to limit as per Section 3.1.1.1 \\nii. Medical practitioner(s) \\niii. Anaesthesia, blood, oxygen, operation theatre charges, surgical appliances \\niv. Medicines and drugs \\nv. Diagnostic procedures \\nvi. Prosthetics and other devices or equipment if implanted internally during a surgical procedure. \\nvii. Dental treatment, necessitated due to an injury \\nviii. Plastic surgery, necessitated due to disease or injury \\nix. Hormone replacement therapy, if medically necessary \\nx. Vitamins and tonics, forming part of treatment for disease/injury as certified by the attending medical practitioner \\nxi. Circumcision, necessitated for treatment of a disease or injury \\n \\n3.1.1.1 Limit for Room Charges and Intensive Care Unit Charges \\nRoom charges and intensive care unit charges per day shall be payable up to the limit as shown in the Table of Benefits, for Plan A \\nonly. However, the limit shall not apply if the treatment is undergone for a listed procedure in a Preferred Provider Network (PPN) \\nas a package. \\n \\nNote: \\nListed procedures and Preferred Provider Network list are dynamic in nature, and will be updated in the Company’s website from \\ntime to time. \\n \\n \\n3.1.1.2 Limit for Cataract Surgery \\nThe Company’s liability for cataract surgery shall be up to the limit as shown in the Table of Benefits, for Plan A only. However, \\nthe limit shall not apply if the treatment is undergone for a listed procedure in a Preferred Provider Network (PPN) as a package. \\n \\n3.1.1.3 Treatment related to participation as a non-professional in hazardous or adventure sports \\nExpenses related to treatment necessitated due to participation as a non-professional in hazardous or adventure sports, subject to \\nMaximum amount admissible for Any One Illness shall be lower of 25% of Sum Insured. \\n \\n3.1.2 Pre Hospitalisation \\nThe Company shall indemnify the medical expenses incurred up to thirty days immediately before the insured person is hospitalised, \\nprovided that: \\ni. \\nsuch medical expenses are incurred for the same condition for which the insured person’s hospitalisation was required, and \\nii. the in-patient hospitalisation claim for such hospitalisation is admissible by the Company \\nPre hospitalisation shall be considered as part of the Hospitalisation claim. \\n \\n3.1.3 Post Hospitalisation \\nThe Company shall indemnify the medical expenses incurred up to sixty days immediately after the insured person is discharged \\nfrom hospital, provided that: \\ni. \\nsuch medical expenses are incurred for the same condition for which the insured person’s hospitalisation was required, and \\nii. the in-patient hospitalisation claim for such hospitalisation is admissible by the Company \\nPost hospitalisation shall be considered as part of the hospitalisation claim. \\n \\n3.1.4 Domiciliary Hospitalisation \\nThe Company shall Company shall indemnify the medical expenses incurred under domiciliary hospitalization, including Pre \\nHospitalisation expenses and Post Hospitalisation expenses, up to the limit as shown in the Table of Benefits. \\n \\nExclusions \\nDomiciliary hospitalisation shall not cover: \\ni. \\nTreatment of less than three days \\nii. Expenses incurred for alternative treatment \\niii. Expenses incurred for maternity or infertility \\niv. Expenses incurred for any of the following diseases; \\na) Asthma \\nb) Bronchitis \\nc) Chronic nephritis and nephritic syndrome \\nd) Diarrhoea and all type of dysenteries including \\ngastroenteritis \\ne) Epilepsy \\nf) \\nInfluenza, cough and cold \\ng) All psychiatric or psychosomatic disorders \\nh) Pyrexia of unknown origin for less than ten days \\ni) \\nTonsillitis and upper respiratory tract infection \\nincluding laryngitis and pharingitis \\nj) \\nArthritis, gout and rheumatism'),\n", " Document(metadata={'producer': 'Microsoft® Word LTSC', 'creator': 'Microsoft® Word LTSC', 'creationdate': '2025-02-11T11:39:19+05:30', 'source': 'app\\\\uploads\\\\policy.pdf', 'file_path': 'app\\\\uploads\\\\policy.pdf', 'total_pages': 25, 'format': 'PDF 1.7', 'title': 'National Parivar Mediclaim Plus Policy (NPMPP)', 'author': 'Avishek Banerjee', 'subject': '', 'keywords': '', 'moddate': '2025-02-11T11:39:19+05:30', 'trapped': '', 'modDate': \"D:20250211113919+05'30'\", 'creationDate': \"D:20250211113919+05'30'\", 'page': 5}, page_content=\"National Insurance Co. Ltd. \\nPremises No. 18-0374, Plot no. CBD-81, \\nNew Town, Kolkata - 700156 \\nPage 6 of 25 \\nNational Parivar Mediclaim Plus Policy \\nUIN: NICHLIP25039V032425 \\n \\n3.1.5 Day Care Procedure \\nThe Company shall indemnify the Medical Expenses (including Pre and Post Hospitalisation Expenses) for Day Care Treatments \\nrequiring Hospitalization as an In-Patient for less than 24 hours undergone by the Insured Person in a Hospital/ Day Care Centre, \\nbut not in the Outpatient department of a Hospital. \\n3.1.6 AYUSH Treatment \\nThe Company shall indemnify Medical Expenses incurred for Inpatient Care treatment under Ayurveda, Yoga and Naturopathy, \\nUnani, Siddha and Homeopathy systems of medicines during each Policy Period up to the limit of Sum Insured as specified in the \\nPolicy Schedule in any AYUSH Hospital. \\n \\n \\n3.1.7 Organ Donor’s Medical Expenses \\nOrgan Donor's Hospitalisation Expenses \\nThe Company shall indemnify the Medical Expenses incurred in respect of an organ donor’s Hospitalisation during the Policy \\nPeriod for harvesting of the organ donated to an Insured Person, provided that: \\ni. The organ donation confirms to the Transplantation of Human Organs Act 1994 (and its amendments from time to time) \\nii. The organ is used for an Insured Person and the Insured Person has been medically advised to undergo an organ transplant \\niii. The Medical Expenses shall be incurred in respect of the organ donor as an in-patient in a Hospital. \\niv. Claim has been admitted under In-patient Treatment Section in respect of the Insured Person undergoing the organ \\ntransplant. \\n \\nExclusions \\nThe Company shall not be liable to make payment for any claim under this Cover which arises for or in connection with any of the \\nfollowing: \\ni. Pre-hospitalization Medical Expenses or Post- Hospitalization Medical Expenses of the organ donor. \\nii. Costs directly or indirectly associated with the acquisition of the donor’s organ. \\niii. Medical Expenses where the organ transplant is experimental or investigational. \\niv. Any medical treatment or complication in respect of the donor, consequent to harvesting. \\nv. Any expenses related to organ transportation or preservation. \\n \\n3.1.8 Hospital Cash \\nThe Company shall pay the insured a daily hospital cash allowance up to the limit as shown in the Table of Benefits for a maximum \\nof five days, provided: \\ni. \\nthe hospitalisation exceeds three days. \\nii. a claim has been admitted under In-patient Treatment Section \\nHospital Cash shall be payable for each day from the 4th day of Hospitalisation up to the 8th day of Hospitalisation only. \\nHospitalisation of less than 24 hours shall not be considered for the purpose of payment of Hospital Cash \\n \\n3.1.9 Ambulance \\n \\nThe Company shall reimburse the insured the expenses incurred for ambulance charges for transportation to the hospital, or from \\none hospital to another hospital, up to the limit as shown in the Table of Benefits, provided a claim has been admitted under In-\\npatient Treatment Section. \\n \\n3.1.10 Air Ambulance \\nThe Company shall reimburse the insured the expenses incurred for medical evacuation of the insured person by air ambulance to \\nthe nearest hospital or from one hospital to another hospital following an emergency up to the limit as per the Table of Benefits, \\nprovided prior intimation is given to the Company/TPA, and a claim has been admitted under In-patient Treatment Section. \\n \\n3.1.11 Medical Emergency Reunion \\nIn the event of the insured person being hospitalised in a place away from the place of residence for more than five continuous days \\nin an intensive care unit for any life threatening condition, the Company after obtaining confirmation from the attending medical \\npractitioner, of the need of a ‘family member’ to be present, shall reimburse the expenses of a round trip economy class air ticket \\nfor Plan B and Plan C to allow a family member, provided a claim has been admitted under In-patient Treatment Section. \\nFor the purpose of the Section, ‘family member’ shall mean spouse, children and parents of the insured person. \\n \\n3.1.12 Doctor’s Home Visit and Nursing Care during Post Hospitalisation \\nThe Company shall reimburse the insured, for medically necessary expenses incurred for doctor’s home visit charges, nursing care \\nby qualified nurse during post hospitalisation up to the limit as shown in the Table of Benefits. \\n \\n3.1.13 Anti Rabies Vaccination \\nThe Company shall reimburse the insured medically necessary expenses incurred for anti-rabies vaccination up to the limit as shown \\nin the Table of Benefits. Hospitalisation is not required for vaccination. \\n \\n3.1.14 Maternity \\n \\nThe Company shall indemnify Maternity Expenses as described below for any female Insured Person, and also Pre-Natal and Post-\\nNatal Hospitalisation expenses per delivery, including expenses for necessary vaccination for New Born Baby, subject to the limit\"),\n", " Document(metadata={'producer': 'Microsoft® Word LTSC', 'creator': 'Microsoft® Word LTSC', 'creationdate': '2025-02-11T11:39:19+05:30', 'source': 'app\\\\uploads\\\\policy.pdf', 'file_path': 'app\\\\uploads\\\\policy.pdf', 'total_pages': 25, 'format': 'PDF 1.7', 'title': 'National Parivar Mediclaim Plus Policy (NPMPP)', 'author': 'Avishek Banerjee', 'subject': '', 'keywords': '', 'moddate': '2025-02-11T11:39:19+05:30', 'trapped': '', 'modDate': \"D:20250211113919+05'30'\", 'creationDate': \"D:20250211113919+05'30'\", 'page': 6}, page_content='National Insurance Co. Ltd. \\nPremises No. 18-0374, Plot no. CBD-81, \\nNew Town, Kolkata - 700156 \\nPage 7 of 25 \\nNational Parivar Mediclaim Plus Policy \\nUIN: NICHLIP25039V032425 \\n \\nas shown in the Table of Benefits. The female Insured Person should have been continuously covered for at least 24 months before \\navailing this benefit. \\nThe New Born Baby shall be automatically covered from birth under the Sum Insured available to the mother during the \\ncorresponding Policy Period, for up to 3 months of age. On attaining 3 months of age, the New Born Baby shall be covered only if \\nspecifically included in the Policy mid-term and requisite premium paid to the Company. \\n \\nCover \\nMaternity Expenses means; \\na) Medical treatment expenses traceable to childbirth (including complicated deliveries and caesarean sections incurred during \\nHospitalization); \\nb) Expenses towards lawful medical termination of pregnancy during the Policy Period. \\nNote: Ectopic pregnancy is covered under ‘In-patient treatment’, provided such pregnancy is established by medical reports. \\n \\nExclusions \\nThe Company shall not be liable to make any payment under the cover in respect of Maternity Expenses incurred in connection with \\nor in respect of: \\n1. Covered female Insured Person below eighteen (18) years and above forty-five (45) years of age. \\n2. Delivery or termination within a Waiting Period of twenty-four (24) months. However, the Waiting Period may be waived \\nonly in the case of delivery, miscarriage or abortion induced by accident. \\n3. Delivery or lawful medical termination of pregnancy limited to two deliveries or terminations or either has been paid under \\nthe Policy and its Renewals. \\n4. More than one delivery or lawful medical termination of pregnancy during a single Policy Period. \\n5. Maternity Expenses of Surrogate Mother, unless claim is admitted under Section 3.1.15 (Infertility) \\n6. Ectopic pregnancy \\n7. Pre and post hospitalisation expenses, other than pre and post natal treatment. \\n \\n3.1.15 Infertility \\nThe Company shall pay to the hospital or reimburse the insured, in respect of the medical expenses of the insured and his spouse, \\nif covered by the Policy, for treatment undergone as an in-patient or as a day care treatment, for procedures and/ or treatment of \\ninfertility, provided the Policy has been continuously in force for twenty four (24) months from the inception of the Policy or from \\nthe date of inclusion of the insured person, whichever is later. The medical expenses for either or both the insured person shall be \\nsubject to the limit as shown in the Table of Benefits. \\n \\nExclusions \\nThe Company shall not be liable to make any payment in respect of any expenses incurred in connection with or in respect of \\n1. Insured and insured persons above forty five years of age. \\n2. Diagnostic tests related to infertility \\n3. Reversing a tubal ligation or vasectomy \\n4. Preserving and storing sperms, eggs and embryos \\n5. An egg donor or sperm donor \\n6. Experimental treatments \\n7. Any disease/ injury, other than traceable to maternity, of the surrogate mother. \\n \\nConditions \\n1. Expenses for advanced procedures, including IVF, GIFT, ZIFT or ICSI, shall be payable only if the Insured person has been \\nunable to attain or sustain a successful pregnancy through reasonable, and medically necessary infertility treatment. \\n2. Maternity expenses of the surrogate mother shall be payable under Section 3.1.14 (Maternity). Legal affidavit regarding \\nintimation of surrogacy shall be submitted to the Company. \\n3. Maximum of two claims shall be admissible by the Policy during the lifetime of the insured person if he has no living child \\nand one claim if the insured has one living child. \\n4. Any one illness limit shall not apply. \\n \\nDefinitions for the purpose of the Section \\n1. Donor means an oocyte donor or sperm donor. \\n2. Embryo means a fertilized egg where cell division has commenced/ under the process and has completed the pre-embryonic \\nstage. \\n3. Gamete Intra-Fallopian Transfer (GIFT) means a procedure where the sperm and egg are placed inside a catheter separated \\nby an air bubble and then transferred to the fallopian tube. Fertilization takes place naturally. \\n4. Infertility means the inability to conceive after one year of unprotected sexual intercourse or the inability to sustain a \\nsuccessful pregnancy. However the one year period may be waived, provided a medical practitioner determines existence of a \\nmedical condition rendering conception impossible through unprotected sexual intercourse, including but not limited to \\ncongenital absence of the uterus or ovaries, absence of the uterus or ovaries due to surgical removal due to a medical condition, \\nor involuntary sterilization due to chemotherapy or radiation treatments. \\n5. Intra-Cytoplasmic Sperm Injection (ICSI) means an injection of sperm into an egg for fertilisation. \\n6. In Vitro Fertilization (IVF) means a process in which an egg and sperm are combined in a laboratory dish where fertilization \\noccurs. The fertilized and dividing egg is transferred into the uterus of the woman.'),\n", " Document(metadata={'producer': 'Microsoft® Word LTSC', 'creator': 'Microsoft® Word LTSC', 'creationdate': '2025-02-11T11:39:19+05:30', 'source': 'app\\\\uploads\\\\policy.pdf', 'file_path': 'app\\\\uploads\\\\policy.pdf', 'total_pages': 25, 'format': 'PDF 1.7', 'title': 'National Parivar Mediclaim Plus Policy (NPMPP)', 'author': 'Avishek Banerjee', 'subject': '', 'keywords': '', 'moddate': '2025-02-11T11:39:19+05:30', 'trapped': '', 'modDate': \"D:20250211113919+05'30'\", 'creationDate': \"D:20250211113919+05'30'\", 'page': 7}, page_content='National Insurance Co. Ltd. \\nPremises No. 18-0374, Plot no. CBD-81, \\nNew Town, Kolkata - 700156 \\nPage 8 of 25 \\nNational Parivar Mediclaim Plus Policy \\nUIN: NICHLIP25039V032425 \\n \\n7. Surrogate means a woman who carries a pregnancy for the insured person. \\n8. Zygote Intra-Fallopian Transfer (ZIFT) means a procedure where the egg is fertilized in vitro and transferred to the \\nfallopian tube before dividing. \\n \\n3.1.16 Vaccination for Children \\nThe Company shall reimburse the insured, the expenses incurred for vaccinations of children (up to twelve years for male child and \\nup to fourteen years for female child), as listed in Annexure I, up to the limit as shown in the Table of Benefits, provided the children \\nare covered by the Policy. Hospitalisation is not required for this benefit. \\n \\n3.1.17 HIV/ AIDS Cover \\nThe Company shall indemnify the Hospital or the Insured the Medical Expenses (including Pre and Post Hospitalisation Expenses) \\nrelated to following stages of HIV infection: \\ni. \\nAcute HIV infection – acute flu-like symptoms \\nii. Clinical latency – usually asymptomatic or mild symptoms \\niii. AIDS – full-blown disease; CD4 < 200 \\n \\n3.1.18 Mental Illness Cover \\nThe Company shall indemnify the Hospital or the Insured the Medical Expenses (including Pre and Post Hospitalisation Expenses) \\nrelated to Mental Illnesses, provided the treatment shall be undertaken at a Hospital with a specific department for Mental Illness, \\nunder a Medical Practitioner qualified as Psychiatrist or a professional having a post-graduate degree (Ayurveda) in Mano Vigyan \\nAvum Manas Roga or a post-graduate degree (Homoeopathy) in Psychiatry or a post-graduate degree (Unani) in Moalijat \\n(Nafasiyatt) or a post-graduate degree (Siddha) in Sirappu Maruthuvam. \\n \\nExclusions \\nAny kind of Psychological counselling, cognitive/ family/ group/ behavior/ palliative therapy or other kinds of psychotherapy for \\nwhich Hospitalisation is not necessary shall not be covered. \\n \\n3.1.19 Modern Treatment \\nThe Company shall indemnify the Medical Expenses for In-Patient Care, Domiciliary Hospitalisation or Day Care Procedure along \\nwith Pre Hospitalisation expenses and Post Hospitalisation expenses incurred for following Modern Treatments (wherever \\nmedically indicated), subject to the limit of 25% of the Sum Insured for the related modern procedure/ component/ medicine of each \\nModern Treatment during the Policy Period. \\n \\nModern Treatment \\nCoverage \\nUAE & HIFU \\nLimit is for Procedure cost only \\nBalloon Sinuplasty \\nLimit is for Balloon cost only \\nDeep Brain Stimulation \\nLimit is for implants including batteries only \\nOral Chemotherapy \\nOnly cost of medicines payable under this limit, other incidental charges like investigations and consultation \\ncharges not payable. \\nImmunotherapy \\nLimit is for cost of injections only. \\nIntravitreal injections \\nLimit is for complete treatment, including Pre & Post Hospitalization \\nRobotic Surgery \\nLimit is for robotic component only. \\nStereotactic Radio \\nsurgeries \\nLimit is for radiation procedure. \\nBronchial Thermoplasty \\nLimit is for complete treatment, including Pre & Post Hospitalization \\nVaporization of the \\nprostrate \\nLimit is for LASER component only. \\nIONM \\nLimit is for IONM procedure only. \\nStem cell therapy \\nLimit is for complete treatment, including Pre & Post Hospitalization \\n \\n3.1.20 Morbid Obesity Treatment \\nThe Company shall indemnify the Hospital or the Insured the Medical Expenses, including Pre Hospitalisation expenses and Post \\nHospitalisation expenses incurred for surgical treatment of obesity that fulfils all the following conditions and subject to Waiting \\nPeriod of three (03) years as per Section 4.2.f.iv: \\n1. Treatment has been conducted is upon the advice of the Medical Practitioner, and \\n \\n2. The surgery/Procedure conducted should be supported by clinical protocols, and \\n3. The Insured Person is 18 years of age or older, and \\n \\n4. Body Mass Index (BMI) is; \\na) greater than or equal to 40 or \\n \\nb) greater than or equal to 35 in conjunction with any of the following severe co-morbidities following failure of less invasive \\nmethods of weight loss: \\ni. Obesity-related cardiomyopathy \\nii. Coronary heart disease \\niii. Severe Sleep Apnea \\niv. Uncontrolled Type 2 Diabetes'),\n", " Document(metadata={'producer': 'Microsoft® Word LTSC', 'creator': 'Microsoft® Word LTSC', 'creationdate': '2025-02-11T11:39:19+05:30', 'source': 'app\\\\uploads\\\\policy.pdf', 'file_path': 'app\\\\uploads\\\\policy.pdf', 'total_pages': 25, 'format': 'PDF 1.7', 'title': 'National Parivar Mediclaim Plus Policy (NPMPP)', 'author': 'Avishek Banerjee', 'subject': '', 'keywords': '', 'moddate': '2025-02-11T11:39:19+05:30', 'trapped': '', 'modDate': \"D:20250211113919+05'30'\", 'creationDate': \"D:20250211113919+05'30'\", 'page': 8}, page_content='National Insurance Co. Ltd. \\nPremises No. 18-0374, Plot no. CBD-81, \\nNew Town, Kolkata - 700156 \\nPage 9 of 25 \\nNational Parivar Mediclaim Plus Policy \\nUIN: NICHLIP25039V032425 \\n \\n3.1.21 Correction of Refractive Error \\nThe Company shall indemnify the Hospital or the Insured the Medical Expenses, including Pre Hospitalisation expenses and Post \\nHospitalisation expenses incurred for expenses related to the treatment for correction of eye sight due to refractive error equal to or \\nmore than 7.5 dioptres, subject to Waiting Period of two (02) years as per Section 4.2.f.iii. \\n \\nNote: The expenses that are not covered in this policy are placed under List-l of Annexure-II of the Policy. The list of expenses that \\nare to be subsumed into room charges, or procedure charges or costs of treatment are placed under List-II, List-III and List-IV of \\nAnnexure-II of the Policy respectively \\nAggregate of all the benefits under 3.1.1 to 3.1.21 are subject to the Floater Sum Insured opted. \\n \\n3.1.22 Reinstatement of Sum Insured due to Road Traffic Accident \\nIn the event of the sum insured being exhausted on account of claims arising out of any injury due to road traffic accident during a \\npolicy year, if the Insured and/or Insured Person (s) has to subsequently incur any expenses on hospitalisation due to any other \\ndisease/ injury, the Company shall reinstate the sum insured as mentioned in the schedule. Reinstatement shall be allowed only once \\nduring the policy year and the maximum amount payable under a single claim shall not exceed the sum insured as mentioned in the \\nschedule. \\n \\n3.2 GOOD HEALTH INCENTIVES \\n3.2.1 No Claim Discount (NCD) \\nOn renewal of policies with a term of one year, a NCD of flat 5% shall be allowed on the * base premium, provided claims are not \\nreported in the expiring Policy. \\nOn renewal of policies with a term exceeding one year, the NCD amount with respect to each claim free policy year shall be \\naggregated and allowed on renewal. Aggregate amount of NCD allowed shall not exceed flat 5% of the total base premium for the \\nterm of the policy. \\n* Base premium depends on the zone and sum insured and is the aggregate of the premium for senior most insured person and other insured \\npersons for a year. \\n \\n3.2.2 Health Check Up \\nExpenses of health check up shall be reimbursed (irrespective of past claims) at the end of a block of two continuous policy years, \\nprovided the Policy has been continuously renewed with the Company without a break. Expenses payable are subject to the limit \\nstated in the Table of Benefits. \\n \\n \\n4 EXCLUSIONS \\nThe Company shall not be liable to make any payment by the Policy, in respect of any expenses incurred in connection with or in \\nrespect of: \\n \\n4.1. Pre-Existing Diseases (Excl 01) \\na) Expenses related to the treatment of a Pre-Existing Disease (PED) and its direct complications shall be excluded until the \\nexpiry of thirty six (36) months of continuous coverage after the date of inception of the first policy with us. \\nb) In case of enhancement of sum insured the exclusion shall apply afresh to the extent of sum insured increase. \\nc) If the Insured Person is continuously covered without any break as defined under the portability norms of the extant IRDAI \\n(Health Insurance) Regulations then waiting period for the same would be reduced to the extent of prior coverage. \\nd) Coverage under the policy after the expiry of thirty six (36) months for any pre-existing disease is subject to the same being \\ndeclared at the time of application and accepted by us. \\n \\n4.2. Specified disease/procedure waiting period (Excl 02) \\na) Expenses related to the treatment of the listed Conditions, surgeries/treatments shall be excluded until the expiry of 90 days/ \\none year/ two year/ three years (as specified against specific disease/ procedure) of continuous coverage after the date of \\ninception of the first policy with us. This exclusion shall not be applicable for claims arising due to an accident \\nb) In case of enhancement of sum insured the exclusion shall apply afresh to the extent of sum insured increase. \\nc) If any of the specified disease/procedure falls under the waiting period specified for Pre-Existing Diseases, then the longer \\nof the two waiting periods shall apply. \\nd) The waiting period for listed conditions shall apply even if contracted after the policy or declared and accepted without a \\nspecific exclusion. \\ne) If the Insured Person is continuously covered without any break as defined under the applicable norms on portability \\nstipulated by IRDAI, then waiting period for the same would be reduced to the extent of prior coverage. \\nf) \\nList of specific diseases/procedures \\ni. \\n90 Days Waiting Period (Life style conditions) \\na. \\nHypertension and related complications \\nb. Diabetes and related complications \\nc. \\nCardiac conditions \\nii. One year waiting period \\na. \\nBenign ENT disorders \\nb. Tonsillectomy \\nc. \\nAdenoidectomy \\nd. Mastoidectomy \\ne. \\nTympanoplasty'),\n", " Document(metadata={'producer': 'Microsoft® Word LTSC', 'creator': 'Microsoft® Word LTSC', 'creationdate': '2025-02-11T11:39:19+05:30', 'source': 'app\\\\uploads\\\\policy.pdf', 'file_path': 'app\\\\uploads\\\\policy.pdf', 'total_pages': 25, 'format': 'PDF 1.7', 'title': 'National Parivar Mediclaim Plus Policy (NPMPP)', 'author': 'Avishek Banerjee', 'subject': '', 'keywords': '', 'moddate': '2025-02-11T11:39:19+05:30', 'trapped': '', 'modDate': \"D:20250211113919+05'30'\", 'creationDate': \"D:20250211113919+05'30'\", 'page': 9}, page_content='National Insurance Co. Ltd. \\nPremises No. 18-0374, Plot no. CBD-81, \\nNew Town, Kolkata - 700156 \\nPage 10 of 25 \\nNational Parivar Mediclaim Plus Policy \\nUIN: NICHLIP25039V032425 \\n \\niii. Two years waiting period \\na. \\nCataract \\nb. Benign prostatic hypertrophy \\nc. \\nHernia \\nd. Hydrocele \\ne. \\nFissure/Fistula in anus \\nf. \\nPiles (Haemorrhoids) \\ng. Sinusitis and related disorders \\nh. Polycystic ovarian disease \\ni. \\nNon-infective arthritis \\nj. \\nPilonidal sinus \\nk. Gout and Rheumatism \\nl. \\nCalculus diseases \\nm. Surgery of gall bladder and bile duct excluding \\nmalignancy \\nn. Surgery \\nof \\ngenito-urinary \\nsystem \\nexcluding \\nmalignancy \\no. Surgery for prolapsed intervertebral disc unless \\narising from accident \\np. Surgery of varicose vein \\nq. Hysterectomy \\nr. \\nRefractive error of the eye more than 7.5 dioptres \\ns. \\nCongenital Internal Anomaly (not applicable for \\nnew born baby) \\nAbove diseases/treatments under 4.2.f).i, ii, iii shall be covered after the specified Waiting Period, provided they are not Pre Existing \\nDiseases. \\n \\niv. Three years waiting period \\nFollowing diseases shall be covered after three years of continuous cover from the inception of the policy: \\na. \\nTreatment for joint replacement unless arising from accident \\nb. Osteoarthritis and osteoporosis \\nc. \\nMorbid Obesity and its complications \\nd. Stem Cell Therapy: Hematopoietic stem cells for bone marrow transplant for haematological conditions to be covered. \\n \\n4.3. First 30 days waiting period (Excl 03) \\na) Expenses related to the treatment of any illness within thirty (30) days from the first policy commencement date shall be \\nexcluded except claims arising due to an accident, provided the same are covered. \\nb) This exclusion shall not, however, apply if the Insured Person has Continuous Coverage for more than twelve (12) months. \\nc) The within referred waiting period is made applicable to the enhanced sum insured in the event of granting higher sum \\ninsured subsequently. \\n \\n4.4. Investigation & Evaluation (Excl 04) \\na) Expenses related to any admission primarily for diagnostics and evaluation purposes only are excluded. \\nb) Any diagnostic expenses which are not related or not incidental to the current diagnosis and treatment are excluded. \\n \\n4.5. Rest Cure, Rehabilitation and Respite Care (Excl 05) \\na) Expenses related to any admission primarily for enforced bed rest and not for receiving treatment. This also includes: \\ni. Custodial care either at home or in a nursing facility for personal care such as help with activities of daily living such as \\nbathing, dressing, moving around either by skilled nurses or assistant or non-skilled persons. \\nii. Any services for people who are terminally ill to address physical, social, emotional and spiritual needs. \\n \\n4.6. Obesity/ Weight Control (Excl 06) \\nExpenses related to the surgical treatment of obesity that does not fulfil all the below conditions: \\n1) Surgery to be conducted is upon the advice of the Doctor \\n2) The surgery/Procedure conducted should be supported by clinical protocols \\n3) The member has to be 18 years of age or older and \\n4) Body Mass Index (BMI): \\na. \\ngreater than or equal to 40, or \\nb. greater than or equal to 35 in conjunction with any of the following severe co-morbidities following failure of less \\ninvasive methods of weight loss: \\n \\ni. Obesity-related cardiomyopathy \\nii. Coronary heart disease \\niii. Severe Sleep Apnea \\niv. Uncontrolled Type2 Diabetes \\n \\n4.7. Change-of-Gender Treatments (Excl 07) \\nExpenses related to any treatment, including surgical management, to change characteristics of the body to those of the opposite \\nsex. \\n \\n4.8. Cosmetic or Plastic Surgery (Excl 08) \\nExpenses for cosmetic or plastic surgery or any treatment to change appearance unless for reconstruction following an Accident, \\nBurn(s) or Cancer or as part of medically necessary treatment to remove a direct and immediate health risk to the insured. For this \\nto be considered a medical necessity, it must be certified by the attending Medical Practitioner. \\n \\n4.9. Hazardous or Adventure Sports (Excl 09) \\nExpenses related to any treatment necessitated due to participation as a professional in hazardous or adventure sports, including \\nbut not limited to, para-jumping, rock climbing, mountaineering, rafting, motor racing, horse racing or scuba diving, hand gliding, \\nsky diving, deep-sea diving.'),\n", " Document(metadata={'producer': 'Microsoft® Word LTSC', 'creator': 'Microsoft® Word LTSC', 'creationdate': '2025-02-11T11:39:19+05:30', 'source': 'app\\\\uploads\\\\policy.pdf', 'file_path': 'app\\\\uploads\\\\policy.pdf', 'total_pages': 25, 'format': 'PDF 1.7', 'title': 'National Parivar Mediclaim Plus Policy (NPMPP)', 'author': 'Avishek Banerjee', 'subject': '', 'keywords': '', 'moddate': '2025-02-11T11:39:19+05:30', 'trapped': '', 'modDate': \"D:20250211113919+05'30'\", 'creationDate': \"D:20250211113919+05'30'\", 'page': 10}, page_content='National Insurance Co. Ltd. \\nPremises No. 18-0374, Plot no. CBD-81, \\nNew Town, Kolkata - 700156 \\nPage 11 of 25 \\nNational Parivar Mediclaim Plus Policy \\nUIN: NICHLIP25039V032425 \\n \\n4.10. \\nBreach of Law (Excl 10) \\nExpenses for treatment directly arising from or consequent upon any Insured Person committing or attempting to commit a breach \\nof law with criminal intent. \\n \\n4.11. \\nExcluded Providers (Excl11) \\nExpenses incurred towards treatment in any hospital or by any Medical Practitioner or any other provider specifically excluded by \\nthe Company and disclosed in its website / notified to the policyholders are not admissible. However, in case of life threatening \\nsituations following an accident, expenses up to the stage of stabilization are payable but not the complete claim. \\n \\n4.12. \\nDrug/Alcohol Abuse (Excl 12) \\nTreatment for, Alcoholism, drug or substance abuse or any addictive condition and consequences thereof (Excl 12) \\n \\n4.13. \\nNon Medical Admissions (Excl 13) \\nTreatments received in health hydros, nature cure clinics, spas or similar establishments or private beds registered as a nursing \\nhome attached to such establishments or where admission is arranged wholly or partly for domestic reasons (Excl 13) \\n \\n4.14. \\nVitamins, Tonics (Excl 14) \\nDietary supplements and substances that can be purchased without prescription, including but not limited to Vitamins, minerals \\nand organic substances unless prescribed by a medical practitioners part of hospitalization claim or day care procedure \\n \\n4.15. \\nRefractive Error (Excl 15) \\nExpenses related to the treatment for correction of eye sight due to refractive error less than 7.5 dioptres. \\n \\n4.16. \\nUnproven Treatments (Excl16) \\nExpenses related to any unproven treatment, services and supplies for or in connection with any treatment. Unproven treatments \\nare treatments, procedures or supplies that lack significant medical documentation to support their effectiveness. \\n \\n4.17. \\nHormone Replacement Therapy \\nExpenses for hormone replacement therapy, unless part of Medically Necessary Treatment, except for Puberty and Menopause \\nrelated Disorders \\n \\n4.18. \\nGeneral Debility, Congenital External Anomaly \\nGeneral debility, Congenital external anomaly. \\n \\n4.19. \\nSelf Inflicted Injury \\nTreatment for intentional self-inflicted injury, attempted suicide. \\n \\n4.20. \\nStem Cell Surgery \\nStem Cell Surgery (except Hematopoietic stem cells for bone marrow transplant for haematological conditions). \\n \\n4.21. \\nCircumcision \\nCircumcision unless necessary for treatment of a disease (if not excluded otherwise) or necessitated due to an accident. \\n \\n4.22. \\nVaccination or Inoculation. \\nVaccination or inoculation unless forming part of treatment and requires Hospitalisation, except as and to the extent provided for \\nunder Section 3.1.13 (Anti Rabies Vaccination), Section 3.1.14.iv and Section 3.1.16 (Vaccination for Children). \\n \\n4.23. \\nMassages, Steam Bath, Alternative Treatment (Other than AYUSH treatment) \\nMassages, steam bath, expenses for alternative treatments (other than AYUSH treatment), acupuncture, acupressure, magneto-\\ntherapy and similar treatment. \\n \\n \\n4.24. \\nDental treatment \\nDental treatment, unless necessitated due to an Injury. \\n \\n4.25. \\nOut Patient Department (OPD) \\nAny expenses incurred on OPD. \\n \\n \\n4.26. \\nStay in Hospital which is not Medically Necessary. \\nStay in hospital which is not medically necessary. \\n \\n4.27. \\nSpectacles, Contact Lens, Hearing Aid, Cochlear Implants \\nSpectacles, contact lens, hearing aid, cochlear implants. \\n \\n4.28. \\nNon Prescription Drug \\nDrugs not supported by a prescription, private nursing charges, referral fee to family physician, outstation \\ndoctor/surgeon/consultants’ fees and similar expenses.'),\n", " Document(metadata={'producer': 'Microsoft® Word LTSC', 'creator': 'Microsoft® Word LTSC', 'creationdate': '2025-02-11T11:39:19+05:30', 'source': 'app\\\\uploads\\\\policy.pdf', 'file_path': 'app\\\\uploads\\\\policy.pdf', 'total_pages': 25, 'format': 'PDF 1.7', 'title': 'National Parivar Mediclaim Plus Policy (NPMPP)', 'author': 'Avishek Banerjee', 'subject': '', 'keywords': '', 'moddate': '2025-02-11T11:39:19+05:30', 'trapped': '', 'modDate': \"D:20250211113919+05'30'\", 'creationDate': \"D:20250211113919+05'30'\", 'page': 11}, page_content='National Insurance Co. Ltd. \\nPremises No. 18-0374, Plot no. CBD-81, \\nNew Town, Kolkata - 700156 \\nPage 12 of 25 \\nNational Parivar Mediclaim Plus Policy \\nUIN: NICHLIP25039V032425 \\n \\n4.29. \\nTreatment not Related to Disease for which Claim is Made \\nTreatment which the insured person was on before Hospitalisation for the Illness/Injury, different from the one for which claim for \\nHospitalisation has been made. \\n \\n4.30. \\nEquipments \\nExternal/durable medical/non-medical equipments/instruments of any kind used for diagnosis/ treatment including CPAP, CAPD, \\ninfusion pump, ambulatory devices such as walker, crutches, belts, collars, caps, splints, slings, braces, stockings, diabetic foot-\\nwear, glucometer, thermometer and similar related items and any medical equipment which could be used at home subsequently. \\n \\n4.31. \\nItems of personal comfort \\nItems of personal comfort and convenience including telephone, television, aya, barber, beauty services, baby food, cosmetics, \\nnapkins, toiletries, guest services. \\n \\n4.32. \\nService charge/ registration fee \\nAny kind of service charges including surcharges, admission fees, registration charges and similar charges levied by the hospital. \\n \\n4.33. \\nHome visit charges \\nHome visit charges during Pre and Post Hospitalisation of doctor, attendant and nurse, except as and to the extent provided for under \\nSection 3.1.12 (Doctor’s Home Visit and Nursing Care during Post Hospitalisation). \\n \\n4.34. \\nWar \\nWar (whether declared or not) and war like occurrence or invasion, acts of foreign enemies, hostilities, civil war, rebellion, \\nrevolutions, insurrections, mutiny, military or usurped power, seizure, capture, arrest, restraints and detainment of all kinds. \\n \\n4.35. \\nRadioactivity \\nNuclear, chemical or biological attack or weapons, contributed to, caused by, resulting from or from any other cause or event \\ncontributing concurrently or in any other sequence to the loss, claim or expense. For the purpose of this exclusion: \\n \\na) Nuclear attack or weapons means the use of any nuclear weapon or device or waste or combustion of nuclear fuel or the \\nemission, discharge, dispersal, release or escape of fissile/ fusion material emitting a level of radioactivity capable of causing \\nany Illness, incapacitating disablement or death. \\nb) Chemical attack or weapons means the emission, discharge, dispersal, release or escape of any solid, liquid or gaseous \\nchemical compound which, when suitably distributed, is capable of causing any Illness, incapacitating disablement or death. \\nc) Biological attack or weapons means the emission, discharge, dispersal, release or escape of any pathogenic (disease \\nproducing) micro-organisms and/or biologically produced toxins (including genetically modified organisms and chemically \\nsynthesized toxins) which are capable of causing any Illness, incapacitating disablement or death. \\n \\n4.36. \\nTreatment taken outside the geographical limits of India \\n \\n5 CONDITIONS \\n \\n5.1 Disclosure of Information \\nThe policy shall be void and all premium paid thereon shall be forfeited to the Company in the event of misrepresentation, mis \\ndescription or non-disclosure of any material fact by the policyholder. \\n(Explanation: \"Material facts\" for the purpose of this policy shall mean all relevant information sought by the company in the \\nproposal form and other connected documents to enable it to take informed decision in the context of underwriting the risk) \\n \\n5.2 Condition Precedent to Admission of Liability \\nThe terms and conditions of the policy must be fulfilled by the insured person for the Company to make any payment for claim(s) \\narising under the policy. \\n \\n5.3 Communication \\ni. \\nAll communication should be made in writing. \\nii. For policies serviced by TPA, ID card, PPN/network provider related issues to be communicated to the TPA at the address \\nmentioned in the schedule. For claim serviced by the Company, the Policy related issues to be communicated to the Policy \\nissuing office of the Company at the address mentioned in the schedule. \\niii. Any change of address, state of health or any other change affecting any of the insured person, shall be communicated to the \\nPolicy issuing office of the Company at the address mentioned in the schedule \\niv. The Company or TPA shall communicate to the insured at the address mentioned in the schedule. \\n \\n5.4 Physical Examination \\nAny medical practitioner authorised by the Company shall be allowed to examine the insured person in the event of any alleged \\ninjury or disease requiring hospitalisation when and as often as the same may reasonably be required on behalf of the Company. \\n \\n5.5 Claim Procedure \\n5.5.1 Notification of Claim'),\n", " Document(metadata={'producer': 'Microsoft® Word LTSC', 'creator': 'Microsoft® Word LTSC', 'creationdate': '2025-02-11T11:39:19+05:30', 'source': 'app\\\\uploads\\\\policy.pdf', 'file_path': 'app\\\\uploads\\\\policy.pdf', 'total_pages': 25, 'format': 'PDF 1.7', 'title': 'National Parivar Mediclaim Plus Policy (NPMPP)', 'author': 'Avishek Banerjee', 'subject': '', 'keywords': '', 'moddate': '2025-02-11T11:39:19+05:30', 'trapped': '', 'modDate': \"D:20250211113919+05'30'\", 'creationDate': \"D:20250211113919+05'30'\", 'page': 12}, page_content='National Insurance Co. Ltd. \\nPremises No. 18-0374, Plot no. CBD-81, \\nNew Town, Kolkata - 700156 \\nPage 13 of 25 \\nNational Parivar Mediclaim Plus Policy \\nUIN: NICHLIP25039V032425 \\n \\nIn the event of hospitalisation/ domiciliary hospitalisation, the insured person/insured person’s representative shall notify the TPA \\n(if claim is processed by TPA)/Company (if claim is processed by the Company) in writing by letter, e-mail, fax providing all \\nrelevant information relating to claim including plan of treatment, policy number etc. within the prescribed time limit. \\n \\nNotification of claim for Cashless facility \\nTPA must be informed: \\nIn the event of planned hospitalization \\nAt least seventy two hours prior to the insured person’s \\nadmission \\nIn the event of emergency hospitalization \\nWithin twenty four hours of the insured person’s admission \\n \\nNotification of claim for Reimbursement \\nCompany/TPA must be informed: \\nIn the event of planned hospitalisation/ domiciliary \\nhospitalistion/ \\nAt least seventy two hours prior to the insured person’s \\nadmission to hospital/ inception of domiciliary hospitalisation \\nIn the event of emergency hospitalisation/ domiciliary \\nhospitalistion \\nWithin twenty four hours of the insured person’s admission to \\nhospital/ inception of domiciliary hospitalisation \\n \\nNotification of claim for vaccination \\nCompany/TPA must be informed: \\nIn the event of Anti Rabies Vaccination/ Vaccination for \\nChildren \\nAt least twenty four hours prior to the vaccination \\n \\n5.5.2 Procedure for Cashless Claims \\ni. \\nCashless facility can be availed, if TPA service is opted. \\nii. Treatment may be taken in a Network Provider / PPN or Non Network Provider and is subject to pre-authorisation by the TPA. \\nUpdated list of network provider/PPN is available on the website of the Company and the TPA mentioned in the schedule. \\niii. Cashless request form available with the network provider/PPN and TPA shall be completed and sent to the TPA for \\nauthorization. \\niv. The TPA upon getting cashless request form and related medical information from the insured person/ network provider/PPN \\nshall issue a pre-authorization letter within an hour to the hospital after verification. \\nv. At the time of discharge, the insured person has to verify and sign the discharge papers, pay for non-medical and inadmissible \\nexpenses. \\nvi. The TPA shall grant the final authorization within three hours of the receipt of discharge authorization request from the \\nHospital \\nvii. The TPA reserves the right to deny pre-authorization in case the insured person is unable to provide the relevant medical details. \\nviii. In case of denial of cashless access, the insured person may obtain the treatment as per treating doctor’s advice and submit the \\nclaim documents to the TPA for processing. \\n \\n5.5.3 Procedure for Reimbursement of Claims \\nFor reimbursement of claims the insured may submit the necessary documents to TPA (if claim is processed by TPA)/Company (if \\nclaim is processed by the Company) within the prescribed time limit. \\n \\n5.5.3.1 Procedure for Reimbursement of Claims under Domiciliary Hospitalisation \\nFor reimbursement of claims under domiciliary hospitalisation, the insured may submit the necessary documents to TPA (if claim \\nis processed by TPA)/Company (if claim is processed by the Company) within the prescribed time limit. \\n \\n5.5.4 Documents \\nThe claim is to be supported by the following documents in original and submitted within the prescribed time limit. \\ni. \\nCompleted claim form \\nii. Bills, payment receipts, medical history of the patient recorded, discharge certificate/ summary from the hospital etc. \\niii. Cash-memo from the hospital (s)/chemist (s) supported by proper prescription \\niv. Payment receipt, investigation test reports etc. supported by the prescription from the attending medical practitioner \\nv. Attending medical practitioner’s certificate regarding diagnosis along with date of diagnosis and bill receipts etc. \\nvi. Certificate from the surgeon stating diagnosis and nature of operation and bills/receipts etc. \\nvii. For claim under Domiciliary Hospitalisation in addition to documents listed above (as applicable), medical certificate stating \\nthe circumstances requiring for Domiciliary hospitalisation and fitness certificate from treating medical practitioner. \\nviii. For claim under Maternity for surrogacy under Infertility in addition to documents listed above (as applicable), legal affidavit \\nregarding intimation of surrogacy. \\nix. For claim under Medical Emergency Reunion in addition to documents listed above (as applicable), confirmation of the need \\nof family member from attending medical practitioner \\nx. For claim under Reinstatement of Sum Insured due to Road Traffic Accident in addition to documents listed above (as \\napplicable), police investigation report, confirming the road traffic accident. \\nxi. Any other document required by Company/TPA \\n \\nNote \\nIn the event of a claim lodged as per condition 5.8 and the original documents having been submitted to the other insurer, the \\nCompany may accept the documents listed under condition 5.5.4 and claim settlement advice duly certified by the other insurer \\nsubject to satisfaction of the Company.'),\n", " Document(metadata={'producer': 'Microsoft® Word LTSC', 'creator': 'Microsoft® Word LTSC', 'creationdate': '2025-02-11T11:39:19+05:30', 'source': 'app\\\\uploads\\\\policy.pdf', 'file_path': 'app\\\\uploads\\\\policy.pdf', 'total_pages': 25, 'format': 'PDF 1.7', 'title': 'National Parivar Mediclaim Plus Policy (NPMPP)', 'author': 'Avishek Banerjee', 'subject': '', 'keywords': '', 'moddate': '2025-02-11T11:39:19+05:30', 'trapped': '', 'modDate': \"D:20250211113919+05'30'\", 'creationDate': \"D:20250211113919+05'30'\", 'page': 13}, page_content='National Insurance Co. Ltd. \\nPremises No. 18-0374, Plot no. CBD-81, \\nNew Town, Kolkata - 700156 \\nPage 14 of 25 \\nNational Parivar Mediclaim Plus Policy \\nUIN: NICHLIP25039V032425 \\n \\nType of claim \\nTime limit for submission of documents to Company/TPA \\nReimbursement of hospitalization, pre hospitalisation \\nexpenses and ambulance charges, air ambulance charges and \\nmedical emergency reunion charges \\nWithin fifteen days from date of discharge from hospital \\nReimbursement of post hospitalisation expenses and \\ndoctor’s home visit and nursing care during post \\nhospitalization \\nWithin fifteen days from completion of post hospitalisation \\ntreatment \\nReimbursement of domiciliary hospitalisation expenses \\n \\nWithin fifteen days from issuance of fitness certificate \\nReimbursement of anti rabies vaccination, new born baby \\nvaccination and vaccination of children \\nWithin fifteen days from date of vaccination \\nReimbursement of expenses for infertility treatment \\nWithin fifteen days of completion of treatment or fifteen days \\nof expiry of Policy period, whichever is earlier, once during the \\npolicy year \\nReimbursement of health check up expenses (to be \\nsubmitted to the office only) \\nAt least forty five (45) days before the expiry of the third Policy \\nYear. \\n \\n5.5.5 Claim Settlement \\ni. \\nThe Company shall settle or reject a claim, as the case may be, within 15 days from the date of receipt of last necessary \\ndocument. \\nii. In the case of delay in the payment of a claim, the Company shall be liable to pay interest to the policyholder from the date of \\nreceipt of last necessary document to the date of payment of claim at a rate 2% above the bank rate. \\niii. However, where the circumstances of a claim warrant an investigation in the opinion of the Company, it shall initiate and \\ncomplete such investigation at the earliest, in any case not later than 30 days from the date of receipt of last necessary document. \\nIn such cases, the Company shall settle or reject the claim within 45 days from the date of receipt of last necessary document. \\niv. In case of delay beyond stipulated 45 days, the Company shall be liable to pay interest to the policyholder at a rate 2% above \\nthe bank rate from the date of receipt of last necessary document to the date of payment of claim. \\n(Explanation: “Bank rate” shall mean the rate fixed by the Reserve Bank of India (RBI) at the beginning of the financial year in \\nwhich claim has fallen due) \\n \\n5.5.6 Services Offered by TPA \\nThe TPA shall render health care services covered by the Policy including issuance of ID cards & guide book, hospitalization & \\npre-authorization services, call centre, acceptance of claim related documents, claim processing and other related services \\nThe services offered by a TPA shall not include \\ni. \\nClaim settlement and claim rejection; however, TPA may handle claims admission and recommend to the Company for \\nsettlement of the claim \\nii. Any services directly to any insured person or to any other person unless such service is in accordance with the terms and \\nconditions of the Agreement entered into with the Company. \\n \\nWaiver \\nTime limit for notification of claim and submission of documents may be waived in cases where it is proved to the satisfaction of \\nthe Company, that the physical circumstances under which insured person was placed, it was not possible to intimate the \\nclaim/submit the documents within the prescribed time limit. \\n \\n5.5.7 Classification of * Zone and Co-payment \\nThe amount of claim admissible will depend upon the zone for which premium has been paid and the zone where treatment has \\nbeen taken. \\n* The country has been divided into four zones. \\nZone I - Greater Mumbai Metropolitan area, entire state of Gujarat \\nZone II – National Capital Territory (NCT) Delhi and National Capital Region (# NCR), Chandigarh, Pune \\nZone III - Chennai, Hyderabad, Bangalore, Kolkata \\nZone IV - Rest of India \\n# NCR includes Gurgaon-Manesar, Alwar-Bhiwadi, Faridabad-Ballabgarh, Ghaziabad-Loni, Noida, Greater Noida, Bahadurgarh, Sonepat-\\nKundli, Charkhi Dadri, Bhiwani, Narnaul \\n \\n \\nWhere treatment has been taken in a zone, other than the one for which ** premium has been paid, the claim shall be subject to co-\\npayment. \\na. \\nInsured paying premium as per Zone I can avail treatment in Zone I, Zone II, Zone III and Zone IV without co-payment \\nb. Insured paying premium as per Zone II \\na. \\nCan avail treatment in Zone II, Zone III and Zone IV without any co-payment \\nb. Availing treatment in Zone I will be subject to a co-payment of 5% \\nc. \\nInsured paying premium as per Zone III \\na. \\nCan avail treatment in Zone III and Zone IV without any co-payment \\nb. Availing treatment in Zone I will be subject to a co-payment of 12.5% \\nc. \\nAvailing treatment in Zone II will be subject to a co-payment of 7.5% \\nd. Insured paying premium as per Zone IV'),\n", " Document(metadata={'producer': 'Microsoft® Word LTSC', 'creator': 'Microsoft® Word LTSC', 'creationdate': '2025-02-11T11:39:19+05:30', 'source': 'app\\\\uploads\\\\policy.pdf', 'file_path': 'app\\\\uploads\\\\policy.pdf', 'total_pages': 25, 'format': 'PDF 1.7', 'title': 'National Parivar Mediclaim Plus Policy (NPMPP)', 'author': 'Avishek Banerjee', 'subject': '', 'keywords': '', 'moddate': '2025-02-11T11:39:19+05:30', 'trapped': '', 'modDate': \"D:20250211113919+05'30'\", 'creationDate': \"D:20250211113919+05'30'\", 'page': 14}, page_content='National Insurance Co. Ltd. \\nPremises No. 18-0374, Plot no. CBD-81, \\nNew Town, Kolkata - 700156 \\nPage 15 of 25 \\nNational Parivar Mediclaim Plus Policy \\nUIN: NICHLIP25039V032425 \\n \\na. \\nCan avail treatment in Zone IV without any co-payment \\nb. Availing treatment in Zone I will be subject to a co-payment of 22.5% \\nc. \\nAvailing treatment in Zone II will be subject to a co-payment of 17.5% \\nd. Availing treatment in Zone III will be subject to a co-payment of 10% \\n** For premium rates please refer to the Prospectus/ Brochure \\n \\n5.5.8 Optional Co-payment \\nThe Insured may opt for Optional Co-payment, with discount in premium. In such cases, each admissible claim under the Policy \\nshall be subject to the same Co-payment percentage. Any change in Optional Co-payment may be done only during Renewal. \\nInsured may choose either of the two Co-payment options: \\n• \\n20% Co-payment on each admissible claim under the Policy, with a 25% discount in total premium. \\n• \\n10% Co-payment on each admissible claim under the Policy, with a 12.5% discount in total premium. \\n \\nAbove co-payments shall not be applicable on Critical illness & Outpatient treatment optional covers, but shall apply on Pre-existing \\ndiabetes and/ or hypertension optional cover. \\n \\n5.6 Moratorium Period \\nAfter completion of sixty continuous months of coverage (including Portability and Migration), no claim shall be contestable by the \\nCompany on grounds of non-disclosure, misrepresentation, except on grounds of established fraud. This period of sixty continuous \\nmonths is called as Moratorium Period. The moratorium would be applicable for the Basic Sums Insured of the first policy. \\nWherever, the Basic Sum Insured is enhanced, completion of sixty continuous months would be applicable from the date of \\nenhancement of Basic Sums Insured only on the enhanced limits. \\n \\n5.7 Payment of Claim \\nAll claims by the Policy shall be payable in Indian currency and through NEFT/ RTGS only. \\n \\n \\n5.8 Territorial Limit \\nAll medical treatment for the purpose of this insurance will have to be taken in India only. \\n \\n5.9 Multiple Policies \\ni. \\nIn case of multiple policies taken by an insured person during a period from one or more insurers to indemnify treatment costs, \\nthe insured person shall have the right to require a settlement of his/her claim in terms of any of his/her policies. In all such \\ncases the insurer chosen by the insured person shall be obliged to settle the claim as long as the claim is within the limits of and \\naccording to the terms of the chosen policy. \\nii. Insured person having multiple policies shall also have the right to prefer claims under this policy for the amounts disallowed \\nunder any other policy / policies. Then the insurer shall independently settle the claim subject to the terms and conditions of \\nthis policy. \\niii. If the amount to be claimed exceeds the sum insured under a single policy, the insured person shall have the right to choose \\ninsurer from whom he/she wants to claim the balance amount. \\niv. Where an insured person has policies from more than one insurer to cover the same risk on indemnity basis, the insured person \\nshall only be indemnified the treatment costs in accordance with the terms and conditions of the chosen policy. \\nv. On occurrence of an insured event under specified critical illnesses, the policyholders can claim from all Insurers under all \\npolicies. \\n \\n5.10 Fraud \\nIf any claim made by the insured person, is in any respect fraudulent, or if any false statement, or declaration is made or used in \\nsupport thereof, or if any fraudulent means or devices are used by the insured person or anyone acting on his/her behalf to obtain \\nany benefit under this policy, all benefits under this policy and the premium paid shall be forfeited. \\nAny amount already paid against claims made under this policy but which are found fraudulent later shall be repaid by all \\nrecipient(s)/policyholder(s), who has made that particular claim, who shall be jointly and severally liable for such repayment to the \\ninsurer. \\nFor the purpose of this clause, the expression \"fraud\" means any of the following acts committed by the insured person or by his \\nagent or the hospital/doctor/any other party acting on behalf of the insured person, with intent to deceive the insurer or to induce the \\ninsurer to issue an insurance policy: \\na) the suggestion, as a fact of that which is not true and which the insured person does not believe to be true; \\nb) the active concealment of a fact by the insured person having knowledge or belief of the fact; \\nc) any other act fitted to deceive; and \\nd) any such act or omission as the law specially declares to be fraudulent \\nThe Company shall not repudiate the claim and / or forfeit the policy benefits on the ground of Fraud, if the insured person / \\nbeneficiary can prove that the misstatement was true to the best of his knowledge and there was no deliberate intention to suppress \\nthe fact or that such misstatement of or suppression of material fact are within the knowledge of the insurer. \\n \\n5.11 Cancellation \\ni. The Company may cancel the policy at any time, on grounds of misrepresentation, non-disclosure of material facts or \\nestablished fraud by the insured person by giving 15 days’ written notice. There would be no refund of premium on \\ncancellation on grounds of misrepresentation, non-disclosure of material facts or fraud.'),\n", " Document(metadata={'producer': 'Microsoft® Word LTSC', 'creator': 'Microsoft® Word LTSC', 'creationdate': '2025-02-11T11:39:19+05:30', 'source': 'app\\\\uploads\\\\policy.pdf', 'file_path': 'app\\\\uploads\\\\policy.pdf', 'total_pages': 25, 'format': 'PDF 1.7', 'title': 'National Parivar Mediclaim Plus Policy (NPMPP)', 'author': 'Avishek Banerjee', 'subject': '', 'keywords': '', 'moddate': '2025-02-11T11:39:19+05:30', 'trapped': '', 'modDate': \"D:20250211113919+05'30'\", 'creationDate': \"D:20250211113919+05'30'\", 'page': 15}, page_content='National Insurance Co. Ltd. \\nPremises No. 18-0374, Plot no. CBD-81, \\nNew Town, Kolkata - 700156 \\nPage 16 of 25 \\nNational Parivar Mediclaim Plus Policy \\nUIN: NICHLIP25039V032425 \\n \\nii. The policyholder may cancel his/her policy at any time during the term, by giving 7 days’ notice in writing. The Insurer shall: \\na) refund proportionate premium for unexpired policy period, if the term of policy upto one year and there is no claim (s) \\nmade during the policy period. \\nb) refund premium for the unexpired policy period, in respect of policies with term more than 1 year and risk coverage for \\nsuch policy years has not commenced and refund proportionate premium for unexpired policy period for the current \\npolicy year. \\nThere shall be no refund for the completed policy year elapsed. \\nNotwithstanding anything contained herein or otherwise, no refunds of premium shall be made in respect of Cancellation where, \\nany claim has been admitted or has been lodged or any benefit has been availed under the Policy. \\n \\n5.12 Territorial Jurisdiction \\nAll disputes or differences under or in relation to the Policy shall be determined by an Indian court in accordance to Indian law. \\n \\n5.13 Arbitration \\ni. \\nIf any dispute or difference shall arise as to the quantum to be paid by the Policy, (liability being otherwise admitted) such \\ndifference shall independently of all other questions, be referred for arbitration as per Arbitration and Conciliation Act 1996, \\nas amended from time to time. \\nii. It is clearly agreed and understood that no difference or dispute shall be referable to arbitration as herein before provided, if the \\nCompany has disputed or not accepted liability under or in respect of the Policy. \\niii. It is hereby expressly stipulated and declared that it shall be a condition precedent to any right of action or suit upon the Policy \\nthat award by such arbitrator/arbitrators of the amount of expenses shall be first obtained. \\n \\n5.14 Disclaimer \\nIf the Company shall disclaim liability for a claim hereunder and if the insured person shall not within twelve calendar months from \\nthe date of receipt of the notice of such disclaimer notify the Company in writing that he/ she does not accept such disclaimer and \\nintends to recover his/ her claim from the Company, then the claim shall for all purposes be deemed to have been abandoned and \\nshall not thereafter be recoverable hereunder. \\n \\n5.15 Renewal of Policy \\ni. \\nThe policy shall be renewable provided the product is not withdrawn, except in case of established fraud or non-disclosure or \\nmisrepresentation by the Insured. If the product is withdrawn, the policyholder shall be provided with suitable options to migrate \\nto other similar health insurance products/plans offered by the Company. \\nii. The Company shall endeavor to give notice for renewal. However, the Company is not under obligation to give any notice for \\nrenewal. \\niii. Renewal shall not be denied on the ground that the insured person had made a claim or claims in the preceding policy years. \\niv. Request for renewal along with requisite premium shall be received by the Company before the end of the policy period. \\nv. At the end of the policy period, the policy shall terminate and can be renewed within the Grace Period of 30 days to maintain \\ncontinuity of benefits without break in policy. Coverage is not available during the grace period. \\nvi. No loading shall apply on renewals based on individual claims experience. \\nvii. In case of non-continuance of the Policy by the insured (due to death or any other valid and acceptable reason) \\na. \\nThe Policy may be renewed by any insured person above eighteen years of age, as the insured \\nb. If only children (less than eighteen years of age) are covered, the Policy shall be allowed till the expiry of the policy \\nperiod. The grandparents may be allowed to renew the Policy as Proposer, covering the grandchildren. \\nviii. In case of death of the eldest insured person: \\n• \\nThe base premium may be calculated based on the age of the next eldest insured person. \\n \\n5.16 Enhancement of Sum Insured \\nSum insured can be enhanced only at the time of renewal. Sum insured may be enhanced subject to the availability of the higher \\nslabs in the Policy and at the discretion of the Company. For the incremental portion of the sum insured, the waiting periods and \\nconditions as mentioned in exclusion 4.1, 4.2, 4.3 shall apply. Coverage on enhanced sum insured shall be available after the \\ncompletion of waiting periods. \\n \\n5.17 Adjustment of Premium for Overseas Travel Insurance Policy \\nIf during the policy period any of the insured person is also covered by an Overseas Travel Insurance Policy of any non life insurance \\ncompany, the Policy shall be inoperative in respect of the insured persons for the number of days the Overseas Travel Insurance \\nPolicy is in force and proportionate premium for such number of days shall be adjusted against the renewal premium. The insured \\nperson must inform the Company in writing before leaving India and may submit an application, stating the details of visit(s) abroad, \\nalong with copies of the Overseas Travel Insurance Policy, within seven days of return or expiry of the Policy, whichever is earlier. \\n \\n5.18 Migration \\nThe Insured Person will have the option to migrate the Policy to an alternative health insurance product offered by the Company by \\napplying for Migration of the policy at least 30 days before the policy renewal date as per extant Guidelines related to Migration. If \\nsuch person is presently covered and has been continuously covered without any lapses under this Policy offered by the Company, \\ni. The Insured Person will get all the accrued continuity benefits for credits gained to the extent of the specific waiting periods, \\nwaiting period for pre-existing diseases and Moratorium period of the Insured Person.'),\n", " Document(metadata={'producer': 'Microsoft® Word LTSC', 'creator': 'Microsoft® Word LTSC', 'creationdate': '2025-02-11T11:39:19+05:30', 'source': 'app\\\\uploads\\\\policy.pdf', 'file_path': 'app\\\\uploads\\\\policy.pdf', 'total_pages': 25, 'format': 'PDF 1.7', 'title': 'National Parivar Mediclaim Plus Policy (NPMPP)', 'author': 'Avishek Banerjee', 'subject': '', 'keywords': '', 'moddate': '2025-02-11T11:39:19+05:30', 'trapped': '', 'modDate': \"D:20250211113919+05'30'\", 'creationDate': \"D:20250211113919+05'30'\", 'page': 16}, page_content='National Insurance Co. Ltd. \\nPremises No. 18-0374, Plot no. CBD-81, \\nNew Town, Kolkata - 700156 \\nPage 17 of 25 \\nNational Parivar Mediclaim Plus Policy \\nUIN: NICHLIP25039V032425 \\n \\nii. Migration benefit will be offered to the extent of Sum Insured of the previous policy. Migration benefit shall not apply to \\nany other additional increased Sum Insured. \\nThe Proposal may be subject to fresh Underwriting as per terms of conditions of the migrated product, if the insured is not \\ncontinuously covered for at least 36 months under the previous product. \\n \\n5.19 Portability \\nThe Insured Person will have the option to port the Policy to other insurers by applying to such Insurer to port the entire policy along \\nwith all the members of the family, if any, at least 15 days before, but not earlier than 60 days from the policy renewal date, as per \\nIRDAI guidelines related to Portability. If such person is presently covered and has been continuously covered without any lapses \\nunder this Policy offered by the Company, \\ni. The proposed Insured Person will get all the accrued continuity benefits for specific waiting periods, waiting period for pre-\\nexisting diseases and Moratorium period of the Insured Person under the previous health insurance Policy. \\nii. Portability benefit will be offered to the extent of Sum Insured of the previous policy. Portability benefit shall not apply to \\nany other additional increased Sum Insured. \\n \\n5.20 Withdrawal of Product \\ni. \\nIn the likelihood of this product being withdrawn in future, the Company will intimate the insured person about the same 90 \\ndays prior to expiry of the policy. \\nii. Insured Person will have the option to migrate to similar health insurance product available with the Company at the time of \\nrenewal with all the accrued continuity benefits such as cumulative bonus, waiver of waiting period as per IRDAI guidelines, \\nprovided the policy has been maintained without a break. \\n \\n5.21 Revision of Terms of the Policy Including the Premium Rates \\nThe Company, with prior approval of IRDAI, may revise or modify the terms of the policy including the premium rates. The insured \\nperson shall be notified before the changes are effected. \\n \\n5.22 Free Look Period \\nThe Free Look Period shall be applicable on new individual health insurance policies and not on renewals or at the time of \\nporting/migrating the policy. \\nThe insured person shall be allowed free look period of thirty days from date of receipt of the policy document to review the terms \\nand conditions of the policy. If he/she is not satisfied with any of the terms and conditions, he/she has the option to cancel his/her \\npolicy. This option is available in case of policies with a term of one year or more. \\nIf the insured has not made any claim during the Free Look Period, the insured shall be entitled to: \\ni. \\na refund of the premium paid less any expenses incurred by the Company on medical examination of the insured person and \\nthe stamp duty charges or \\nii. where the risk has already commenced and the option of return of the policy is exercised by the insured person, a deduction \\ntowards the proportionate risk premium for period of cover or \\niii. Where only a part of the insurance coverage has commenced, such proportionate premium commensurate with the insurance \\ncoverage during such period. \\n \\n5.23 Nomination \\nThe policyholder is required at the inception of the policy to make a nomination for the purpose of payment of claims under the \\npolicy in the event of death of the policyholder. Any change of nomination shall be communicated to the company in writing and \\nsuch change shall be effective only when an endorsement on the policy is made. In the event of death of the policyholder, the \\nCompany will pay the nominee {as named in the Policy Schedule/Policy Certificate/Endorsement (if any)} and in case there is no \\nsubsisting nominee, to the legal heirs or legal representatives of the policyholder whose discharge shall be treated as full and final \\ndischarge of its liability under the policy. \\n \\n6. REDRESSAL OF GRIEVANCE \\nIn case of any grievance related to the Policy, the insured person may submit in writing to the Policy Issuing Office or Grievance \\ncell at Regional Office of the Company for redressal. If the grievance remains unaddressed, the insured person may contact: \\nCustomer Relationship Management Dept., National Insurance Company Limited, Premises No. 18-0374, Plot no. CBD-81, New \\nTown, Kolkata - 700156, email: customer.relations@nic.co.in, griho@nic.co.in \\nFor \\nmore \\ninformation \\non \\ngrievance \\nmechanism, \\nand \\nto \\ndownload \\ngrievance \\nform, \\nvisit \\nour \\nwebsite https://nationalinsurance.nic.co.in \\nBima Bharosa (an Integrated Grievance Management System earlier known as IGMS) - https://bimabharosa.irdai.gov.in/ \\nInsurance Ombudsman – The Insured person can also approach the office of Insurance Ombudsman of the respective area/region \\nfor redressal of grievance as listed in Annexure -III. The updated list of Office of Insurance Ombudsman are available on IRDAI \\nwebsite: https://irdai.gov.in/ and on the website of Council for Insurance Ombudsman: https://www.cioins.co.in/ \\nHelpline Number: 1800 345 0330 \\nDedicated Email ID for Senior Citizens: health.srcitizens@nic.co.in'),\n", " Document(metadata={'producer': 'Microsoft® Word LTSC', 'creator': 'Microsoft® Word LTSC', 'creationdate': '2025-02-11T11:39:19+05:30', 'source': 'app\\\\uploads\\\\policy.pdf', 'file_path': 'app\\\\uploads\\\\policy.pdf', 'total_pages': 25, 'format': 'PDF 1.7', 'title': 'National Parivar Mediclaim Plus Policy (NPMPP)', 'author': 'Avishek Banerjee', 'subject': '', 'keywords': '', 'moddate': '2025-02-11T11:39:19+05:30', 'trapped': '', 'modDate': \"D:20250211113919+05'30'\", 'creationDate': \"D:20250211113919+05'30'\", 'page': 17}, page_content='National Insurance Co. Ltd. \\nPremises No. 18-0374, Plot no. CBD-81, \\nNew Town, Kolkata - 700156 \\nPage 18 of 25 \\nNational Parivar Mediclaim Plus Policy \\nUIN: NICHLIP25039V032425 \\n \\n7. OPTIONAL COVERS \\n7.1 Pre-existing Diabetes / Hypertension \\nSubject otherwise to the terms, definitions, exclusions, and conditions of the Policy and on payment of additional premium, the \\nCompany shall pay expenses for treatment of diabetes and/ or hypertension, if pre-existing, from the inception of the Policy. On \\ncompletion of continuous thirty six months of insurance, the additional premium and sub limits shall not apply. \\n \\nEligibility \\nAs per the Policy. \\n \\nLimit of Cover \\nSum Insured opted under the policy shall apply. \\n \\nPolicy period \\nThe policy period for the Policy, and the cover should be identical, as mentioned in the schedule. \\n \\nTax rebate \\nThe insured can avail tax benefits for the premium paid, under Section 80D of Income Tax Act 1961. \\n \\nRenewal \\nThe cover can be renewed annually till Exclusion 4.1 applies on diabetes and/or hypertension, with respect to the insured persons. \\n \\n7.1.1 Condition \\nClaim Amount \\nAny amount payable shall be subject to \\ni. \\nThe sum insured applicable to Section 3.1, \\nii. \\nCo-payment mentioned under Classification of Zone and Co-payment, Optional Copayment, and \\niii. \\nSub limits mentioned below. \\nFirst year \\nUp to a maximum of 25% of SI \\nSecond year \\nUp to a maximum of 50% of SI \\nThird year \\nUp to a maximum of 75% of SI \\n \\n7.2 Out-patient Treatment \\nSubject otherwise to the terms, definitions, conditions and Exclusions 4.7, 4.8, 4.17, 4.16, 4.23, 4.12, 4.9, 4.10, 4.34 and 4.35, the \\nCompany shall pay up to the limit, as stated in the schedule with respect of \\ni. \\nOut-patient consultations by a medical practitioner \\nii. Diagnostic tests prescribed by a medical practitioner \\niii. Medicines/drugs prescribed by a medical practitioner \\niv. Out patient dental treatment \\n \\nEligibility \\nThe cover can be availed by all insured persons as a floater. \\n \\nLimit of Cover \\nLimit of cover, available under Out-patient Treatment are INR 2,000/ 3,000/ 4,000/ 5,000/ 10,000/ 15,000/ 20,000/ 25,000, in \\naddition to the sum insured opted. \\nPolicy Period \\nThe policy period for the Policy, and the cover should be identical, as mentioned in the schedule. \\n \\nTax Rebate \\nThe insured person can avail tax benefits for the premium paid, under Section 80D of Income Tax Act 1961. \\n \\nRenewal \\nThe Outpatient Treatment cover can be renewed annually throughout the lifetime of the insured person. \\n \\n7.2.1 Exclusions \\nThe Company shall not make any payment under the cover in respect of \\ni. \\nTreatment other than Allopathy/ Modern medicine, AYUSH \\nii. * Cosmetic dental treatment to straighten lightens, reshape and repair teeth. \\n* Cosmetic treatments include veneers, crowns, bridges, tooth-coloured fillings, implants and tooth whitening). \\n \\n7.2.2 Condition \\nClaim Amount \\ni. \\nAny amount payable shall not affect the sum insured applicable to Section 3.1 and entitlement to No Claim Discount. \\nii. \\nAny amount payable shall not be subject to co-payment.'),\n", " Document(metadata={'producer': 'Microsoft® Word LTSC', 'creator': 'Microsoft® Word LTSC', 'creationdate': '2025-02-11T11:39:19+05:30', 'source': 'app\\\\uploads\\\\policy.pdf', 'file_path': 'app\\\\uploads\\\\policy.pdf', 'total_pages': 25, 'format': 'PDF 1.7', 'title': 'National Parivar Mediclaim Plus Policy (NPMPP)', 'author': 'Avishek Banerjee', 'subject': '', 'keywords': '', 'moddate': '2025-02-11T11:39:19+05:30', 'trapped': '', 'modDate': \"D:20250211113919+05'30'\", 'creationDate': \"D:20250211113919+05'30'\", 'page': 18}, page_content='National Insurance Co. Ltd. \\nPremises No. 18-0374, Plot no. CBD-81, \\nNew Town, Kolkata - 700156 \\nPage 19 of 25 \\nNational Parivar Mediclaim Plus Policy \\nUIN: NICHLIP25039V032425 \\n \\nClaims Procedure \\nDocuments supporting all out-patient treatments shall be submitted to the TPA/ Company twice during the policy period, within \\nthirty days of completion of six month period. \\n \\nDocuments \\nThe claim has to be supported by the following original documents \\ni. \\nAll bills, prescriptions from medical practitioner \\nii. Diagnostic test bills, copy of reports \\niii. Any other documents required by the Company \\n \\nEnhancement of Limit of Cover \\nLimit of cover can be enhanced only at the time of renewal. \\n \\n7.3 Critical Illness \\nSubject otherwise to the terms, definitions, exclusions, and conditions of the Policy the Company shall pay the benefit amount, as \\nstated in the schedule, provided that \\ni. \\nthe insured person is first diagnosed as suffering from a critical illness during the policy period as a first incidence, and \\nii. the insured person survives at least thirty days following such diagnosis \\niii. diagnosis of critical illness is supported by clinical, radiological, histological and laboratory evidence acceptable to the \\nCompany. \\n \\nEligibility (entry age) \\nThe cover can be availed by persons between the age of eighteen years and sixty five years. \\n \\nBenefit Amount \\nBenefit amount available under Critical Illness cover shall be limited to the 50% of the sum insured by the Policy. \\nBenefit amount available per individual are INR 2,00,000/ 3,00,000/ 5,00,000/ 10,00,000/ 15,00,000/ 20,00,000/ 25,00,000, in \\naddition to the sum insured opted. \\n \\nPolicy Period \\nThe policy period for the Policy, and the cover should be identical, as mentioned in the schedule. \\n \\nPre Policy checkup \\nPre Policy checkup reports (as per Section 2.8.iii) are required for individual opting for Critical illness cover between the age of \\neighteen years and sixty five years. \\n \\nTax Rebate \\nNo tax benefit is allowed on the premium paid under Critical Illness cover (if opted) \\n \\nRenewal \\nThe Critical Illness cover can be renewed annually throughout the lifetime of the insured person. \\n \\n7.3.1 Definition \\nCritical illness means stroke resulting in permanent symptoms, cancer of specified severity, kidney failure requiring regular \\ndialysis, major organ/ bone marrow transplant, multiple sclerosis with persisting symptoms an open chest CABG (Coronary Artery \\nBypass Graft), permanent paralysis of limbs and blindness. \\n \\nI. Stroke Resulting in Permanent Symptoms \\nAny cerebrovascular incident producing permanent neurological sequelae. This includes infarction of brain tissue, thrombosis in an \\nintracranial vessel, haemorrhage and embolisation from an extracranial source. Diagnosis has to be confirmed by a specialist medical \\npractitioner and evidenced by typical clinical symptoms as well as typical findings in CT Scan or MRI of the brain. Evidence of \\npermanent neurological deficit lasting for at least three months has to be produced. \\n \\nThe following are not covered: \\ni. \\ntransient ischemic attacks (TIA) \\nii. traumatic injury of the brain \\niii. vascular disease affecting only the eye or optic nerve or vestibular functions. \\n \\nII. Cancer of Specified Severity \\nA malignant tumor characterised by the uncontrolled growth & spread of malignant cells with invasion & destruction of normal \\ntissues. This Diagnosis must be supported by histological evidence of malignancy. The term cancer includes leukemia, lymphoma \\nand sarcoma. \\nThe following are excluded: \\ni. \\nAll tumors which are histologically described as carcinoma in situ, benign, pre-malignant, borderline malignant, low \\nmalignant potential, neoplasm of unknown behavior, or non- invasive, including but not limited to: \\nCarcinoma in situ of breasts, Cervical dysplasia CIN-1, CIN -2 & CIN-3. \\nii. Any non- melanoma skin carcinoma unless there is evidence of metastases to lymph nodes or beyond;'),\n", " Document(metadata={'producer': 'Microsoft® Word LTSC', 'creator': 'Microsoft® Word LTSC', 'creationdate': '2025-02-11T11:39:19+05:30', 'source': 'app\\\\uploads\\\\policy.pdf', 'file_path': 'app\\\\uploads\\\\policy.pdf', 'total_pages': 25, 'format': 'PDF 1.7', 'title': 'National Parivar Mediclaim Plus Policy (NPMPP)', 'author': 'Avishek Banerjee', 'subject': '', 'keywords': '', 'moddate': '2025-02-11T11:39:19+05:30', 'trapped': '', 'modDate': \"D:20250211113919+05'30'\", 'creationDate': \"D:20250211113919+05'30'\", 'page': 19}, page_content='National Insurance Co. Ltd. \\nPremises No. 18-0374, Plot no. CBD-81, \\nNew Town, Kolkata - 700156 \\nPage 20 of 25 \\nNational Parivar Mediclaim Plus Policy \\nUIN: NICHLIP25039V032425 \\n \\niii. Malignant melanoma that has not caused invasion beyond the epidermis; \\niv. All tumors of the prostate unless histologically classified as having a Gleason score greater than 6 or having progressed to at \\nleast clinical TNM classification T2N0M0; \\nv. All Thyroid cancers histologically classified as T1N0M0 (TNM classification) or below; \\nvi. Chronic lymphocytic leukaemia less than RAI stage 3 \\nvii. Non- invasive Papillary cancer of bladder histologically described as TaN0M0 (TNM Classification)or of a lesser \\nclassification; \\nviii. All Gastro-intestinal Stromal Tumors histologically classified as T1N0M0 (TNM Classification) or below and with mitotic \\ncount of less than or equal to 5/50 HPFs; \\n \\nIII Kidney Failure Requiring Regular Dialysis \\nEnd stage renal disease presenting as chronic irreversible failure of both kidneys to function, as a result of which either regular renal \\ndialysis (hemodialysis or peritoneal dialysis) is instituted or renal transplantation is carried out. Diagnosis has to be confirmed by a \\nspecialist medical practitioner. \\n \\nIV Major Organ/ Bone Marrow Transplant \\nThe actual undergoing of a transplant of: \\ni. \\none of the following human organs: heart, lung, liver, kidney, pancreas, that resulted from irreversible end-stage failure of the \\nrelevant organ, or \\nii. human bone marrow using haematopoietic stem cells. The undergoing of a transplant has to be confirmed by a specialist medical \\npractitioner. \\n \\nThe following are not covered \\ni. \\nother stem-cell transplants \\nii. where only islets of langerhans are transplanted \\n \\nV Multiple Sclerosis with Persisting Symptoms \\nThe unequivocal Diagnosis of Definite Multiple Sclerosis confirmed and evidenced by all of the following \\ni. \\nInvestigations including typical MRI findings, which unequivocally confirm the Diagnosis to be multiple sclerosis and \\nii. There must be current clinical impairment of motor or sensory function, which must have persisted for a continuous period of \\nat least 6 months \\niii. Neurological damage due to SLE is excluded. \\n \\nVI Open Chest CABG \\nThe actual undergoing of open chest surgery for the correction of one or more coronary arteries, which is/are narrowed or blocked, \\nby coronary artery bypass graft (CABG). The diagnosis must be supported by a coronary angiography and the realization of surgery \\nhas to be confirmed by a specialist medical practitioner. \\n \\nThe following are not covered \\ni. \\nangioplasty and/or any other intra-arterial procedures \\nii. any key-hole or laser surgery. \\n \\nVII Permanent Paralysis of Limbs \\nTotal and irreversible loss of use of two or more limbs as a result of injury or disease of the brain or spinal cord. A specialist medical \\npractitioner must be of the opinion that the paralysis will be permanent with no hope of recovery and must be present for more than \\nthree months. \\n \\nVIII Blindness \\nThe total and permanent loss of all sight in both eyes. \\n \\n7.3.2 Exclusions \\nThe Company shall not be liable to make any payment by the Policy if: any critical illness and/or its symptoms (and/or the treatment) \\nwhich were present at any time before inception of the first Policy, or which manifest within a period of ninety days from inception \\nof the first Policy, whether or not the insured person had knowledge that the symptoms or treatment were related to such critical \\nillness. In the event of break in the Policy, the terms of this exclusion shall apply as new from recommencement of cover \\n \\n7.3.3 Condition \\nClaim Amount \\ni. \\nAny amount payable under the optional covers will not affect the sum insured applicable to Section 3.1 and entitlement to \\nNo Claim Discount (Section 3.1). \\nii. \\nAny amount payable shall not be subject to co-payment. \\nNotification of Claim \\nIn the event of a claim, the insured person/insured person’s representative shall intimate the Company in writing, providing all \\nrelevant information within fifteen days of diagnosis of the illness.'),\n", " Document(metadata={'producer': 'Microsoft® Word LTSC', 'creator': 'Microsoft® Word LTSC', 'creationdate': '2025-02-11T11:39:19+05:30', 'source': 'app\\\\uploads\\\\policy.pdf', 'file_path': 'app\\\\uploads\\\\policy.pdf', 'total_pages': 25, 'format': 'PDF 1.7', 'title': 'National Parivar Mediclaim Plus Policy (NPMPP)', 'author': 'Avishek Banerjee', 'subject': '', 'keywords': '', 'moddate': '2025-02-11T11:39:19+05:30', 'trapped': '', 'modDate': \"D:20250211113919+05'30'\", 'creationDate': \"D:20250211113919+05'30'\", 'page': 20}, page_content='National Insurance Co. Ltd. \\nPremises No. 18-0374, Plot no. CBD-81, \\nNew Town, Kolkata - 700156 \\nPage 21 of 25 \\nNational Parivar Mediclaim Plus Policy \\nUIN: NICHLIP25039V032425 \\n \\nClaims Procedure \\nDocuments as mentioned above, supporting the diagnosis shall be submitted to the Company within sixty days from the date of \\ndiagnosis of the critical illness. \\n \\nDocuments \\nThe claim has to be supported by the following original documents \\ni. \\nDoctor’s certificate confirming diagnosis of the critical illness along with date of diagnosis. \\nii. Pathological/other diagnostic test reports confirming the diagnosis of the critical illness. \\niii. Any other documents required by the Company \\n \\nCessation of Cover \\n1 upon payment of the benefit amount on the occurrence of a critical illness the cover shall cease and no further claim shall be paid \\nfor any other critical illness during the policy year. \\n2 On renewal, no claim shall be paid for a critical illness for which a claim has already been made \\n \\nEnhancement of Benefit Amount \\ni. \\nBenefit amount can be enhanced only at the time of renewal. \\nii. Benefit amount can be enhanced to the next slab subject to discretion of the Company. \\n \\n \\nInsurance is the subject matter of solicitation \\nPlease preserve the Policy for all future reference.'),\n", " Document(metadata={'producer': 'Microsoft® Word LTSC', 'creator': 'Microsoft® Word LTSC', 'creationdate': '2025-02-11T11:39:19+05:30', 'source': 'app\\\\uploads\\\\policy.pdf', 'file_path': 'app\\\\uploads\\\\policy.pdf', 'total_pages': 25, 'format': 'PDF 1.7', 'title': 'National Parivar Mediclaim Plus Policy (NPMPP)', 'author': 'Avishek Banerjee', 'subject': '', 'keywords': '', 'moddate': '2025-02-11T11:39:19+05:30', 'trapped': '', 'modDate': \"D:20250211113919+05'30'\", 'creationDate': \"D:20250211113919+05'30'\", 'page': 21}, page_content='National Insurance Co. Ltd. \\nPremises No. 18-0374, Plot no. CBD-81, \\nNew Town, Kolkata - 700156 \\nPage 22 of 25 \\nNational Parivar Mediclaim Plus Policy \\nUIN: NICHLIP25039V032425 \\n \\nTable of Benefits: \\nFeatures \\nPlans \\n \\nPLAN A \\nPLAN B \\nPLAN C \\nSum insured (SI) (as Floater) \\nINR 6/ 7/ 8/ 9 /10 Lac \\nINR 15/ 20 /25 Lac \\nINR 30/ 40/ 50 Lac \\nTreatment \\nAllopathy, AYUSH \\nIn built Covers (subject to the SI) \\n \\n \\n \\nIn patient Treatment (as Floater) \\nUp to SI \\nUp to SI \\nUp to SI \\nPre Hospitalisation \\n30 days \\n30 days \\n30 days \\nPost Hospitalisation \\n60 days \\n60 days \\n60 days \\nPre-existing Disease (Only PEDs declared in the Proposal \\nForm and accepted for coverage by the Company shall be \\ncovered) \\nCovered after 36 months of \\ncontinuous coverage \\nCovered after 36 months \\nof continuous coverage \\nCovered after 36 months \\nof continuous coverage \\n* Room/ ICU Charges (per day per insured person) \\nRoom - Up to 1% of SI or actual, \\nwhichever is lower \\nUp to SI \\nUp to SI \\nICU – Up to 2% of SI or actual, \\nwhichever is lower \\n** Limit for Cataract Surgery (For each eye per insured \\nperson) \\nUp to 15% of SI or INR 60,000 \\nwhichever is lower \\nUp to SI \\nUp to SI \\nDomiciliary Hospitalisation (as Floater) \\nUp to INR 1,00,000 \\nUp to INR 2,00,000 \\nUp to INR 2,00,000 \\nDay Care Procedures (as Floater) \\nUp to SI \\nUp to SI \\nUp to SI \\nAYUSH Treatment (as Floater) \\nUp to SI \\nUp to SI \\nUp to SI \\nOrgan Donor’s Medical Expenses (as Floater) \\nUp to SI \\nUp to SI \\nUp to SI \\nHospital Cash (per insured person, per day) \\nINR 500, max. of 5 days \\nINR 1,000, max. of 5 \\ndays \\nINR 2,000, max. of 5 \\ndays \\nAmbulance (per insured person, in a policy year) \\nUp to INR 2,500 \\nUp to INR 4,000 \\nUp to INR 5,000 \\nAir Ambulance (per insured person, in a policy year) \\nNot covered \\nUp to 5% of SI \\nUp to 5% of SI \\nMedical Emergency Reunion (per insured person, in a policy \\nyear) \\nNot covered \\nNo sublimit \\nNo sublimit \\nDoctor’s Home Visit and Nursing Care during Post \\nHospitalisation (per insured person, in a policy year) \\nNot covered \\nINR 1,000 per day, max. \\nof 10 days \\nINR 2,000 per day, max. \\nof 10 days \\nAnti Rabies Vaccination (per insured person, in a policy year) \\nUp to INR 5,000 \\nUp to INR 5,000 \\nUp to INR 5,000 \\nMaternity (including Baby from Birth Cover) (per insured \\nperson, in a policy year, waiting period of 2 years applies) \\nUp to INR 30,000 for normal \\ndelivery and INR 50,000 for \\ncaesarean section \\nUp to SI \\nUp to SI \\nVaccination for New Born Baby \\nAs part of Maternity \\nAs part of Maternity \\nAs part of Maternity \\nInfertility (per insured person, in a policy year, waiting \\nperiod of 2 years applies) \\nUp to INR 50,000 \\nUp to INR 1,00,000 \\nUp to INR 1,00,000 \\nVaccination for Children, for male child up to 12 years and \\nfemale child up to 14 years (per insured person, in a policy \\nyear) \\nUp to INR 1,000 \\nUp to SI \\nUp to SI \\nModern Treatment (12 nos) \\nUp to 25% of SI for each treatment \\nUp to 25% of SI for each \\ntreatment \\nUp to 25% of SI for each \\ntreatment \\nTreatment due to participation in hazardous or adventure \\nsports (non-professionals) \\nUp to 25% of SI \\nUp to 25% of SI \\nUp to 25% of SI \\nMorbid Obesity \\nCovered after waiting period of 3 \\nyears \\nCovered after waiting \\nperiod of 3 years \\nCovered after waiting \\nperiod of 3 years \\nRefractive Error (min 7.5D) \\nCovered after waiting period of 2 \\nyears \\nCovered after waiting \\nperiod of 2 years \\nCovered after waiting \\nperiod of 2 years \\nOther benefits \\n \\n \\n \\nReinstatement of sum insured due to road traffic accident \\nYes \\nYes \\nYes \\nGood Health Incentives \\n \\n \\n \\nNo Claim Discount \\n5% discount on base premium, \\nHealth Check Up (as Floater) \\nEvery 2 yrs., up to INR 5,000 \\nEvery 2 yrs., up to INR \\n7,500 \\nEvery 2 yrs., up to INR \\n10,000 \\nOptional covers \\n \\n \\n \\nPre-existing Diabetes/Hypertension (as Floater) \\nFirst year \\nUp to a maximum of 25% of SI \\nSecond year \\nUp to a maximum of 50% of SI \\nThird year \\nUp to a maximum of 75% of SI \\nOut-patient Treatment (as Floater in a policy year) \\nLimit of cover per family - INR 2,000/ 3,000/ 4,000/ 5,000/ 10,000/ 15,000/ 20,000/ 25,000 \\nin addition to the SI \\n***Critical Illness (per insured person in a policy year) \\nBenefit amount - INR 2,00,000/ 3,00,000/ 5,00,000/ 10,00,000/ 15,00,000/ 20,00,000/ \\n25,00,000 in addition to the SI \\nDiscounts \\nOnline Discount \\n10% discount in premium (for new and Renewal, ONLY where no intermediary is involved) \\nCo-payment discount (optional) \\n•20% Co-payment, with a 25% discount in total premium. \\n•10% Co-payment, with a 12.5% discount in total premium. \\nLong Term Discount \\nDiscount of 4% for 2 year policy and Discount of 7.5% for 3 year policy \\nNo Maternity/ Infertility Discount \\nDiscount of 3%, above 45 years of age \\nAdd-ons (cover available on payment of additional premium) \\nNational Home Care Treatment Add-On \\nINR 10,000/ 15,000/ 20,000/ 25,000/ 30,000/ 35,000/ 40,000/ 45,000/ 50,000, subject to 10% \\nof Basic SI under base Policy. \\nNational Non-Medical Expenses Add-on (available to SI 5 \\nlacs & above) \\nUp to 10% of Basic Sum Insured (excluding Cumulative Bonus, if any) of base Policy and \\nshall be part of the base Policy Basic Sum Insured (excluding Cumulative Bonus, if any). \\n* The limit shall not apply if the treatment is undergone for a listed procedure in a Preferred Provider Network (PPN) as a package. \\n** The limit shall not apply if the treatment is undergone for a listed procedure in a Preferred Provider Network (PPN) as a package \\n*** Critical Illness benefit amount should not be more than the sum insured opted under the Policy'),\n", " Document(metadata={'producer': 'Microsoft® Word LTSC', 'creator': 'Microsoft® Word LTSC', 'creationdate': '2025-02-11T11:39:19+05:30', 'source': 'app\\\\uploads\\\\policy.pdf', 'file_path': 'app\\\\uploads\\\\policy.pdf', 'total_pages': 25, 'format': 'PDF 1.7', 'title': 'National Parivar Mediclaim Plus Policy (NPMPP)', 'author': 'Avishek Banerjee', 'subject': '', 'keywords': '', 'moddate': '2025-02-11T11:39:19+05:30', 'trapped': '', 'modDate': \"D:20250211113919+05'30'\", 'creationDate': \"D:20250211113919+05'30'\", 'page': 22}, page_content='National Insurance Co. Ltd. \\nPremises No. 18-0374, Plot no. CBD-81, \\nNew Town, Kolkata - 700156 \\nPage 23 of 25 \\nNational Parivar Mediclaim Plus Policy \\nUIN: NICHLIP25039V032425 \\n \\nAnnexure I \\nVaccinations for Children \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\nTime interval \\nType of vaccination \\nFrequency \\n \\nVaccination for new born \\n0-3 months \\nBCG (From birth to 2 weeks) \\n1 \\nOPV (0‚6‚10 weeks) OR OPV + IPV1 (6,10 \\nweeks) \\n3 OR 4 \\nDPT (6 & 10 week) \\n2 \\nHepatitis-B (0 & 6 week) \\n2 \\nHib (6 & 10 week) \\n2 \\nVaccination for first year \\n3-6 months \\nOPV (14 week) OR OPV + IPV2 \\n1 OR 2 \\nDPT (14 week) \\n1 \\nHepatitis-B (14 week) \\n1 \\nHib (14 week) \\n1 \\n9 months \\nMeasles (+9 months) \\n1 \\n12 months \\nChicken Pox (12 months) \\n1 \\nVaccinations for age 1 to 12 years \\n1-2 years \\nOPV (15 &18 months) OR OPV + IPV3 \\n1 OR 2 \\nDPT (15-18 months) \\n1 \\nHib (15-18 months) \\n1 \\nMMR (15- 18 months) \\n1 \\nMeningococcal vaccine (24 months) \\n1 \\n2-3 years \\nTyphoid (+2 years) \\n1 \\n10-12 years \\nTT \\n1 \\n14 years (girl child only) \\nHPV \\n1'),\n", " Document(metadata={'producer': 'Microsoft® Word LTSC', 'creator': 'Microsoft® Word LTSC', 'creationdate': '2025-02-11T11:39:19+05:30', 'source': 'app\\\\uploads\\\\policy.pdf', 'file_path': 'app\\\\uploads\\\\policy.pdf', 'total_pages': 25, 'format': 'PDF 1.7', 'title': 'National Parivar Mediclaim Plus Policy (NPMPP)', 'author': 'Avishek Banerjee', 'subject': '', 'keywords': '', 'moddate': '2025-02-11T11:39:19+05:30', 'trapped': '', 'modDate': \"D:20250211113919+05'30'\", 'creationDate': \"D:20250211113919+05'30'\", 'page': 23}, page_content=\"National Insurance Co. Ltd. \\nPremises No. 18-0374, Plot no. CBD-81, \\nNew Town, Kolkata - 700156 \\nPage 24 of 25 \\nNational Parivar Mediclaim Plus Policy \\nUIN: NICHLIP25039V032425 \\n \\nAnnexure II \\nList I – List of which coverage is not available in the policy \\nSl \\nItem \\n1 \\nBABY FOOD \\n2 \\nBABY UTILITIES CHARGES \\n3 \\nBEAUTY SERVICES \\n4 \\nBELTS/ BRACES \\n5 \\nBUDS \\n6 \\nCOLD PACK/HOT PACK \\n7 \\nCARRY BAGS \\n8 \\nEMAIL / INTERNET CHARGES \\n9 \\nFOOD CHARGES (OTHER THAN PATIENT's DIET PROVIDED BY \\nHOSPITAL) \\n10 \\nLEGGINGS \\n11 \\nLAUNDRY CHARGES \\n12 \\nMINERAL WATER \\n13 \\nSANITARY PAD \\n14 \\nTELEPHONE CHARGES \\n15 \\nGUEST SERVICES \\n16 \\nCREPE BANDAGE \\n17 \\nDIAPER OF ANY TYPE \\n18 \\nEYELET COLLAR \\n19 \\nSLINGS \\n20 \\nBLOOD GROUPING AND CROSS MATCHING OF DONORS SAMPLES \\n21 \\nSERVICE CHARGES WHERE NURSING CHARGE ALSO CHARGED \\n22 \\nTelevision Charges \\n23 \\nSURCHARGES \\n24 \\nATTENDANT CHARGES \\n25 \\nEXTRA DIET OF PATIENT (OTHER THAN THAT WHICH FORMS \\nPART OF BED CHARGE) \\n26 \\nBIRTH CERTIFICATE \\n27 \\nCERTIFICATE CHARGES \\n28 \\nCOURIER CHARGES \\n29 \\nCONVEYANCE CHARGES \\n30 \\nMEDICAL CERTIFICATE \\n31 \\nMEDICAL RECORDS \\n32 \\nPHOTOCOPIES CHARGES \\n33 \\nMORTUARY CHARGES \\n34 \\nWALKING AIDS CHARGES \\n35 \\nOXYGEN CYLINDER (FOR USAGE OUTSIDE THE HOSPITAL) \\n36 \\nSPACER \\n37 \\nSPIROMETRE \\n38 \\nNEBULIZER KIT \\n39 \\nSTEAM INHALER \\n40 \\nARMSLING \\n41 \\nTHERMOMETER \\n42 \\nCERVICAL COLLAR \\n43 \\nSPLINT \\n44 \\nDIABETIC FOOT WEAR \\n45 \\nKNEE BRACES (LONG/ SHORT/ HINGED) \\n46 \\nKNEE IMMOBILIZER/SHOULDER IMMOBILIZER \\n47 \\nLUMBO SACRAL BELT \\n48 \\nNIMBUS BED OR WATER OR AIR BED CHARGES \\n49 \\nAMBULANCE COLLAR \\n50 \\nAMBULANCE EQUIPMENT \\n51 \\nABDOMINAL BINDER \\n52 \\nPRIVATE NURSES CHARGES- SPECIAL NURSING CHARGES \\n53 \\n SUGAR FREE Tablets \\n54 \\nCREAMS POWDERS LOTIONS (Toiletries are not payable, only prescribed \\nmedical pharmaceuticals payable) \\n55 \\nECG ELECTRODES \\n56 \\nGLOVES \\n57 \\nNEBULISATION KIT \\n58 \\nANY KIT WITH NO DETAILS MENTIONED [DELIVERY KIT, \\nORTHOKIT, RECOVERY KIT, ETC] \\n59 \\nKIDNEY TRAY \\n60 \\nMASK \\n61 \\nOUNCE GLASS \\n62 \\nOXYGEN MASK \\n63 \\nPELVIC TRACTION BELT \\n64 \\nPAN CAN \\n65 \\nTROLLY COVER \\n66 \\nUROMETER, URINE JUG \\n67 \\nVASOFIX SAFETY \\nList II – Items that are to be subsumed into Room Charges \\nSl \\nItem \\n1 \\nBABY CHARGES (UNLESS SPECIFIED/INDICATED) \\n2 \\nHAND WASH \\n3 \\nSHOE COVER \\n4 \\nCAPS \\n5 \\nCRADLE CHARGES \\n6 \\nCOMB \\n7 \\nEAU-DE-COLOGNE / ROOM FRESHNERS \\n8 \\nFOOT COVER \\n9 \\nGOWN \\n10 \\nSLIPPERS \\n11 \\nTISSUE PAPER \\n12 \\nTOOTH PASTE \\n13 \\nTOOTH BRUSH \\n14 \\nBED PAN \\n15 \\nFACE MASK \\n16 \\nFLEXI MASK \\n17 \\nHAND HOLDER \\n18 \\nSPUTUM CUP \\n19 \\nDISINFECTANT LOTIONS \\n20 \\nLUXURY TAX \\n21 \\nHVAC \\n22 \\nHOUSE KEEPING CHARGES \\n23 \\nAIR CONDITIONER CHARGES \\n24 \\nIM IV INJECTION CHARGES \\n25 \\nCLEAN SHEET \\n26 \\nBLANKET/WARMER BLANKET \\n27 \\nADMISSION KIT \\n28 \\nDIABETIC CHART CHARGES \\n29 \\nDOCUMENTATION CHARGES / ADMINISTRATIVE EXPENSES \\n30 \\nDISCHARGE PROCEDURE CHARGES \\n31 \\nDAILY CHART CHARGES \\n32 \\nENTRANCE PASS / VISITORS PASS CHARGES \\n33 \\nEXPENSES RELATED TO PRESCRIPTION ON DISCHARGE \\n34 \\nFILE OPENING CHARGES \\n35 \\nINCIDENTAL EXPENSES / MISC. CHARGES (NOT EXPLAINED) \\n36 \\nPATIENT IDENTIFICATION BAND / NAME TAG \\n37 \\nPULSEOXYMETER CHARGES \\nList III – Items that are to be subsumed into Procedure Charges \\nSl \\nItem \\n1 \\nHAIR REMOVAL CREAM \\n2 \\nDISPOSABLES RAZORS CHARGES (for site preparations) \\n3 \\nEYE PAD \\n4 \\nEYE SHEILD \\n5 \\nCAMERA COVER \\n6 \\nDVD, CD CHARGES \\n7 \\nGAUSE SOFT \\n8 \\nGAUZE \\n9 \\nWARD AND THEATRE BOOKING CHARGES \\n10 \\nARTHROSCOPY AND ENDOSCOPY INSTRUMENTS \\n11 \\nMICROSCOPE COVER \\n12 \\nSURGICAL BLADES, HARMONICSCALPEL,SHAVER \\n13 \\nSURGICAL DRILL \\n14 \\nEYE KIT \\n15 \\nEYE DRAPE \\n16 \\nX-RAY FILM \\n17 \\nBOYLES APPARATUS CHARGES \\n18 \\nCOTTON \\n19 \\nCOTTON BANDAGE \\n20 \\nSURGICAL TAPE \\n21 \\nAPRON \\n22 \\nTORNIQUET \\n23 \\nORTHOBUNDLE, GYNAEC BUNDLE \\nList IV – Items that are to be subsumed into costs of treatment \\nSl \\nItem \\n1 \\nADMISSION/REGISTRATION CHARGES \\n2 \\nHOSPITALISATION FOR EVALUATION/ DIAGNOSTIC PURPOSE \\n3 \\nURINE CONTAINER \\n4 \\nBLOOD RESERVATION CHARGES AND ANTE NATAL BOOKING \\nCHARGES \\n5 \\nBIPAP MACHINE \\n6 \\nCPAP/ CAPD EQUIPMENTS \\n7 \\nINFUSION PUMP– COST \\n8 \\nHYDROGEN PEROXIDE\\\\SPIRIT\\\\ DISINFECTANTS ETC \\n9 \\nNUTRITION PLANNING CHARGES - DIETICIAN CHARGES- DIET \\nCHARGES \\n10 \\nHIV KIT \\n11 \\nANTISEPTIC MOUTHWASH \\n12 \\nLOZENGES \\n13 \\nMOUTH PAINT \\n14 \\nVACCINATION CHARGES \\n15 \\nALCOHOL SWABES \\n16 \\nSCRUB SOLUTION/STERILLIUM \\n17 \\nGlucometer & Strips \\n18 \\nURINE BAG\"),\n", " Document(metadata={'producer': 'Microsoft® Word LTSC', 'creator': 'Microsoft® Word LTSC', 'creationdate': '2025-02-11T11:39:19+05:30', 'source': 'app\\\\uploads\\\\policy.pdf', 'file_path': 'app\\\\uploads\\\\policy.pdf', 'total_pages': 25, 'format': 'PDF 1.7', 'title': 'National Parivar Mediclaim Plus Policy (NPMPP)', 'author': 'Avishek Banerjee', 'subject': '', 'keywords': '', 'moddate': '2025-02-11T11:39:19+05:30', 'trapped': '', 'modDate': \"D:20250211113919+05'30'\", 'creationDate': \"D:20250211113919+05'30'\", 'page': 24}, page_content='National Insurance Co. Ltd. \\nPremises No. 18-0374, Plot no. CBD-81, \\nNew Town, Kolkata - 700156 \\nPage | 25 \\nNational Parivar Mediclaim Plus Policy \\nUIN: NICHLIP25039V032425 \\n \\nAnnexure III \\nThe contact details of the Insurance Ombudsman offices are as below: \\nAreas of Jurisdiction \\nOffice of the Insurance Ombudsman \\nGujarat , UT of Dadra and \\nNagar Haveli, Daman and \\nDiu \\nOffice of the Insurance Ombudsman, \\nAhmedabad \\nJeevan Prakash Building, 6th floor, \\nTilak Marg, Relief Road, \\nAhmedabad – 380 001. \\nTel.: 079 - 25501201/02 \\nEmail: \\nbimalokpal.ahmedabad@cioins.co.in \\nKarnataka \\nOffice of the Insurance Ombudsman, \\nBengaluru \\nJeevan Soudha Building,PID No. 57-27-\\nN-19 \\nGround Floor, 19/19, 24th Main Road, \\nJP Nagar, Ist Phase, Bengaluru – 560 078. \\nTel.: 080 - 26652048 / 26652049 \\nEmail: bimalokpal.bengaluru@cioins.co.in \\nMadhya Pradesh and \\nChhattisgarh \\nOffice of the Insurance Ombudsman, \\nBhopal \\n1st floor,\"Jeevan Shikha\", 60-B, \\nHoshangabad Road, Opp. Gayatri \\nMandir,Arera Hills \\nBhopal – 462 011. \\nTel.: 0755 - 2769201 / 2769202/ 2769203 \\nEmail: bimalokpal.bhopal@cioins.co.in \\nOrissa \\nOffice of the Insurance Ombudsman, \\nBhubaneswar \\n62, Forest park, \\nBhubneshwar – 751 009. \\nTel.: 0674 - 2596461 /2596455 \\nEmail: \\nbimalokpal.bhubaneswar@cioins.co.in \\nPunjab, Haryana (excluding \\nGurugram, Faridabad, \\nSonepat and Bahadurgarh), \\nHimachal Pradesh, Union \\nTerritories of Jammu & \\nKashmir,Ladakh & \\nChandigarh. \\nOffice of the Insurance Ombudsman, \\nChandigarh \\nJeevan Deep Building SCO 20-27, \\nGround Floor Sector- 17 A, \\nChandigarh – 160 017. \\nTel.: 0172-2706468 \\nEmail: \\nbimalokpal.chandigarh@cioins.co.in \\nTamil Nadu, UT–\\nPondicherry Town and \\nKaraikal (which are part of \\nUT of Pondicherry) \\nOffice of the Insurance Ombudsman, \\nChennai \\nFatima Akhtar Court, 4th Floor, 453, \\nAnna Salai, Teynampet, \\nCHENNAI – 600 018. \\nTel.: 044 - 24333668 / 24333678 \\nEmail: bimalokpal.chennai@cioins.co.in \\nDelhi & following Districts \\nof Haryana - Gurugram, \\nFaridabad, Sonepat & \\nBahadurgarh. \\nOffice of the Insurance Ombudsman, \\nDelhi \\n2/2 A, Universal Insurance Building, \\nAsaf Ali Road, \\nNew Delhi – 110 002. \\nTel.: 011 - 46013992/23213504/23232481 \\nEmail: bimalokpal.delhi@cioins.co.in \\nAssam , Meghalaya, \\nManipur, Mizoram, \\nArunachal Pradesh, Nagaland \\nand Tripura \\nOffice of the Insurance Ombudsman, \\nGuwahati \\nJeevan Nivesh, 5th Floor, \\nNear Pan Bazar , S.S. Road, \\nGuwahati – 781001(ASSAM). \\nTel.: 0361 - 2632204 / 2602205 / 2631307 \\nEmail: bimalokpal.guwahati@cioins.co.in \\nAndhra Pradesh, Telangana \\nand UT of Yanam – a part of \\nthe UT of Pondicherry \\nOffice of the Insurance Ombudsman, \\nHyderabad \\n6-2-46, 1st floor, \"Moin Court\", Lane \\nOpp.Hyundai Showroom , A. C. Guards, \\nLakdi-Ka-Pool, Hyderabad - 500 004. \\nTel.: 040 - 23312122 / 23376991 / \\n23376599 / 23328709 / 23325325 \\nEmail: \\nbimalokpal.hyderabad@cioins.co.in \\nRajasthan \\nOffice of the Insurance Ombudsman, \\nJaipur \\nJeevan Nidhi – II Bldg., Gr. Floor, \\nBhawani Singh Marg, Jaipur - 302 005. \\nTel.: 0141- 2740363 \\nEmail: bimalokpal.jaipur@cioins.co.in \\nKerala , UT of (a) \\nLakshadweep, (b) Mahe – a \\npart of UT of Pondicherry \\nOffice of the Insurance Ombudsman, \\nKochi \\n10th Floor, Jeevan Prakash,LIC Building, \\nOpp to Maharaja\\'s College \\nGround,M.G.Road, \\nKochi - 682 011. \\nTel.: 0484 - 2358759 \\nEmail: \\nbimalokpal.ernakulam@cioins.co.in \\nWest Bengal, UT of \\nAndaman and Nicobar \\nIslands, Sikkim \\nOffice of the Insurance Ombudsman, \\nKolkata \\nHindustan Bldg. Annexe, 7th Floor, \\n4, C.R. Avenue, \\nKOLKATA - 700 072. \\nTel.: 033 - 22124339 / 22124341 \\nEmail: bimalokpal.kolkata@cioins.co.in \\nDistricts of Uttar Pradesh : \\nLaitpur, Jhansi, Mahoba, \\nHamirpur, Banda, \\nChitrakoot, Allahabad, \\nMirzapur, Sonbhabdra, \\nFatehpur, Pratapgarh, \\nJaunpur,Varanasi, Gazipur, \\nJalaun, Kanpur, Lucknow, \\nUnnao, Sitapur, Lakhimpur, \\nBahraich, Barabanki, \\nRaebareli, Sravasti, Gonda, \\nFaizabad, Amethi, \\nKaushambi, Balrampur, \\nBasti, Ambedkarnagar, \\nSultanpur, Maharajgang, \\nSantkabirnagar, Azamgarh, \\nKushinagar, Gorkhpur, \\nDeoria, Mau, Ghazipur, \\nChandauli, Ballia, \\nSidharathnagar. \\nOffice of the Insurance Ombudsman, \\nLucknow \\n6th Floor, Jeevan Bhawan, Phase-II, \\nNawal Kishore Road, Hazratganj, \\nLucknow - 226 001. \\nTel.: 0522 - 4002082 / 3500613 \\nEmail: bimalokpal.lucknow@cioins.co.in \\nMumbai Metropolitan \\nRegion excluding wards in \\nMumbai – i.e M/E, M/W, N , \\nS and T covered under Office \\nof Insurance Ombudsman \\nThane and areas of Navi \\nMumbai. \\nOffice of the Insurance Ombudsman, \\nMumbai \\n3rd Floor, Jeevan Seva Annexe, \\nS. V. Road, Santacruz (W), \\nMumbai - 400 054. \\nTel.: 022 - 69038800/27/29/31/32/33 \\nEmail: bimalokpal.mumbai@cioins.co.in \\nState of Uttaranchal and the \\nfollowing Districts of Uttar \\nPradesh: \\nAgra, Aligarh, Bagpat, \\nBareilly, Bijnor, Budaun, \\nBulandshehar, Etah, Kanooj, \\nMainpuri, Mathura, Meerut, \\nMoradabad, Muzaffarnagar, \\nOraiyya, Pilibhit, Etawah, \\nFarrukhabad, Firozbad, \\nGautambodhanagar, \\nGhaziabad, Hardoi, \\nShahjahanpur, Hapur, \\nShamli, Rampur, Kashganj, \\nSambhal, Amroha, Hathras, \\nKanshiramnagar, Saharanpur \\nOffice of the Insurance Ombudsman, \\nNoida \\nBhagwan Sahai Palace \\n4th Floor, Main Road, Naya Bans, Sector \\n15, \\nDistt: Gautam Buddh Nagar, U.P-201301. \\nTel.: 0120-2514252 / 2514253 \\nEmail: bimalokpal.noida@cioins.co.in \\nBihar, \\nJharkhand. \\nOffice of the Insurance Ombudsman, \\nPatna \\n2nd Floor, Lalit Bhawan, Bailey Road, \\nPatna 800 001. \\nTel.: 0612-2547068 \\nEmail: bimalokpal.patna@cioins.co.in \\nState of Goa and State of \\nMaharashtra excluding areas \\nof Navi Mumbai, Thane \\ndistrict,Palghar District, \\nRaigad district & Mumbai \\nMetropolitan Region \\nOffice of the Insurance Ombudsman, Pune \\nJeevan Darshan Bldg., 3rd Floor, \\nC.T.S. No.s. 195 to 198, N.C. Kelkar \\nRoad, \\nNarayan Peth, Pune – 411 030. \\nTel.: 020-24471175 \\nEmail: bimalokpal.pune@cioins.co.in')]" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# to be added in main.py\n", "from app.ingestion.file_loader import FileLoader\n", "file_loader_obj = FileLoader()\n", "if file_type == \"pdf\":\n", " doc = file_loader_obj.load_pdf(uploaded_file_path)\n", "elif file_type == \"word\":\n", " doc = file_loader_obj.load_word_document(uploaded_file_path)\n", "doc" ] }, { "cell_type": "code", "execution_count": 4, "id": "50579ebc", "metadata": {}, "outputs": [], "source": [ "doc_2_page = [document.page_content for document in doc[0:2]]" ] }, { "cell_type": "code", "execution_count": 35, "id": "2a30061e", "metadata": {}, "outputs": [], "source": [ "doc_content = \" \".join(doc_2_page)" ] }, { "cell_type": "markdown", "id": "4c420dd1", "metadata": {}, "source": [ "2. detect the type of document" ] }, { "cell_type": "code", "execution_count": 5, "id": "83d05c02", "metadata": {}, "outputs": [], "source": [ "from pydantic import BaseModel, Field\n", "from typing import List, Dict, Literal, Optional\n", "\n", "class DocumentTypeSchema(BaseModel):\n", " document_types: Literal[\n", " \"HR/Employment\",\n", " \"Insurance\",\n", " \"Legal/Compliance\",\n", " \"Financial/Regulatory\",\n", " \"Government/Public Policy\",\n", " \"Technical/IT Policies\"\n", " ] = Field(..., description=\"The category/type of the document\")\n", "\n", "class CommonMetaData(BaseModel):\n", " # --- Common metadata (across all domains) ---\n", " doc_id: Optional[str] = Field(None, description=\"Unique document identifier\")\n", " doc_category: Optional[List[str]] = Field(None, description=\"General pool/category e.g. Insurance, HR, Legal\")\n", " doc_type: Optional[List[str]] = Field(None, description=\"Specific type e.g. Policy doc, Contract, Handbook\")\n", " jurisdiction: Optional[List[str]] = Field(\n", " default=None, description=\"Applicable jurisdictions/regions/countries\"\n", " )\n", " effective_date: Optional[List[str]] = Field(None, description=\"Date from which the document is effective\")\n", " expiry_date: Optional[List[str]] = Field(None, description=\"Date until which the document is valid\")\n", " parties: Optional[List[str]] = Field(None, description=\"Involved parties (e.g., employer/employee, insurer/insured)\")\n", " obligations: Optional[List[str]] = Field(\n", " default=None,\n", " description=\"List of short, normalized obligation keywords (2–5 words each, no full sentences)\"\n", " )\n", " penalties: Optional[List[str]] = Field(None, description=\"Penalties/non-compliance consequences\")\n", " notes: Optional[List[str]] = Field(None, description=\"Freeform additional metadata\")\n", "\n", "class InsuranceMetadata(CommonMetaData):\n", "\n", " # --- Insurance ---\n", " policy_number: Optional[List[str]] = None\n", " coverage_type: Optional[List[str]] = Field(\n", " default=None,\n", " description=\"Type(s) of coverage. Short keywords (1–3 words each).\"\n", " )\n", " premium_amount: Optional[List[str]] = None\n", " exclusions: Optional[List[str]] = Field(\n", " description=\"List of normalized keywords representing exclusions (short, 2-5 words each, not full paragraphs).\", default=None\n", " )\n", " added_new_keyword: bool = False\n", " # # --- HR / Employment ---\n", " # policy_type: Optional[str] = None\n", " # applicable_roles: Optional[List[str]] = None\n", " # notice_period: Optional[str] = None\n", "\n", " # # --- Legal / Compliance ---\n", " # clause_type: Optional[str] = None\n", " # governing_law: Optional[str] = None\n", " # duration: Optional[str] = None\n", "\n", " # # --- Financial / Regulatory ---\n", " # section: Optional[str] = None\n", " # compliance_requirement: Optional[str] = None\n", " # reporting_frequency: Optional[str] = None\n", "\n", " # # --- Healthcare / Pharma ---\n", " # disease: Optional[str] = None\n", " # treatment_limit: Optional[str] = None\n", " # validity_period: Optional[str] = None\n", "\n", " # # --- Procurement / Vendor Management ---\n", " # vendor_name: Optional[str] = None\n", " # contract_value: Optional[str] = None\n", " # payment_terms: Optional[str] = None\n", " # sla_metrics: Optional[List[str]] = None\n", "\n", " # # --- Government / Public Policy ---\n", " # act_name: Optional[str] = None\n", "\n", " # # --- Technical / IT Policies ---\n", " # security_level: Optional[str] = None\n", " # compliance_standard: Optional[str] = None # ISO, NIST, SOC2 etc." ] }, { "cell_type": "code", "execution_count": 38, "id": "3fa6ac48", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'properties': {'doc_id': {'anyOf': [{'type': 'string'}, {'type': 'null'}],\n", " 'default': None,\n", " 'description': 'Unique document identifier',\n", " 'title': 'Doc Id'},\n", " 'doc_category': {'anyOf': [{'type': 'string'}, {'type': 'null'}],\n", " 'default': None,\n", " 'description': 'General pool/category e.g. Insurance, HR, Legal',\n", " 'title': 'Doc Category'},\n", " 'doc_type': {'anyOf': [{'type': 'string'}, {'type': 'null'}],\n", " 'default': None,\n", " 'description': 'Specific type e.g. Policy doc, Contract, Handbook',\n", " 'title': 'Doc Type'},\n", " 'jurisdiction': {'anyOf': [{'type': 'string'}, {'type': 'null'}],\n", " 'default': None,\n", " 'description': 'Applicable jurisdiction/region/country',\n", " 'title': 'Jurisdiction'},\n", " 'effective_date': {'anyOf': [{'type': 'string'}, {'type': 'null'}],\n", " 'default': None,\n", " 'description': 'Date from which the document is effective',\n", " 'title': 'Effective Date'},\n", " 'expiry_date': {'anyOf': [{'type': 'string'}, {'type': 'null'}],\n", " 'default': None,\n", " 'description': 'Date until which the document is valid',\n", " 'title': 'Expiry Date'},\n", " 'parties': {'anyOf': [{'items': {'type': 'string'}, 'type': 'array'},\n", " {'type': 'null'}],\n", " 'default': None,\n", " 'description': 'Involved parties (e.g., employer/employee, insurer/insured)',\n", " 'title': 'Parties'},\n", " 'obligations': {'anyOf': [{'type': 'string'}, {'type': 'null'}],\n", " 'default': None,\n", " 'description': 'Obligations/responsibilities stated',\n", " 'title': 'Obligations'},\n", " 'penalties': {'anyOf': [{'type': 'string'}, {'type': 'null'}],\n", " 'default': None,\n", " 'description': 'Penalties/non-compliance consequences',\n", " 'title': 'Penalties'},\n", " 'notes': {'anyOf': [{'type': 'string'}, {'type': 'null'}],\n", " 'default': None,\n", " 'description': 'Freeform additional metadata',\n", " 'title': 'Notes'},\n", " 'policy_number': {'anyOf': [{'type': 'string'}, {'type': 'null'}],\n", " 'default': None,\n", " 'title': 'Policy Number'},\n", " 'coverage_type': {'anyOf': [{'type': 'string'}, {'type': 'null'}],\n", " 'default': None,\n", " 'title': 'Coverage Type'},\n", " 'premium_amount': {'anyOf': [{'type': 'string'}, {'type': 'null'}],\n", " 'default': None,\n", " 'title': 'Premium Amount'},\n", " 'exclusions': {'anyOf': [{'items': {'type': 'string'}, 'type': 'array'},\n", " {'type': 'null'}],\n", " 'default': None,\n", " 'title': 'Exclusions'}},\n", " 'title': 'InsuranceMetadata',\n", " 'type': 'object'}" ] }, "execution_count": 38, "metadata": {}, "output_type": "execute_result" } ], "source": [ "InsuranceMetadata.model_json_schema()" ] }, { "cell_type": "code", "execution_count": 82, "id": "c931d01d", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'{\\n \"properties\": {\\n \"policy_number\": {\\n \"anyOf\": [\\n {\\n \"type\": \"string\"\\n },\\n {\\n \"type\": \"null\"\\n }\\n ],\\n \"default\": null,\\n \"title\": \"Policy Number\"\\n },\\n \"coverage_start\": {\\n \"anyOf\": [\\n {\\n \"type\": \"string\"\\n },\\n {\\n \"type\": \"null\"\\n }\\n ],\\n \"default\": null,\\n \"title\": \"Coverage Start\"\\n },\\n \"coverage_end\": {\\n \"anyOf\": [\\n {\\n \"type\": \"string\"\\n },\\n {\\n \"type\": \"null\"\\n }\\n ],\\n \"default\": null,\\n \"title\": \"Coverage End\"\\n },\\n \"premium_amount\": {\\n \"anyOf\": [\\n {\\n \"type\": \"string\"\\n },\\n {\\n \"type\": \"null\"\\n }\\n ],\\n \"default\": null,\\n \"title\": \"Premium Amount\"\\n },\\n \"jurisdiction\": {\\n \"anyOf\": [\\n {\\n \"type\": \"string\"\\n },\\n {\\n \"type\": \"null\"\\n }\\n ],\\n \"default\": null,\\n \"title\": \"Jurisdiction\"\\n },\\n \"exclusions\": {\\n \"anyOf\": [\\n {\\n \"type\": \"string\"\\n },\\n {\\n \"type\": \"null\"\\n }\\n ],\\n \"default\": null,\\n \"title\": \"Exclusions\"\\n }\\n },\\n \"title\": \"InsuranceMetadata\",\\n \"type\": \"object\"\\n}'" ] }, "execution_count": 82, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import json\n", "schema_str = InsuranceMetadata.model_json_schema()\n", "json.dumps(schema_str, indent = 1)" ] }, { "cell_type": "code", "execution_count": null, "id": "19bd33d3", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Loading config....\n", "LLM loading...\n", "Loading model from provider: \n", "Loading model from gemini:\n" ] } ], "source": [ "from app.utils.model_loader import ModelLoader\n", "from langchain_core.documents import Document\n", "from typing import List, Dict, Literal\n", "from langchain_core.prompts import ChatPromptTemplate\n", "from langchain_core.output_parsers import PydanticOutputParser\n", "\n", "llm_loader = ModelLoader(model_provider=\"gemini\")\n", "llm = llm_loader.load_llm()\n", "\n", "def detect_document_type(documents: List[Document]) -> DocumentTypeSchema:\n", " \"\"\"Detect the genre of document by reading first 2 page content by llm \"\"\"\n", "\n", " document_list = [doc.page_content for doc in documents]\n", " document_content = \" \".join(document_list)\n", " parser = PydanticOutputParser(pydantic_object=DocumentTypeSchema)\n", "\n", " # Prompt template\n", " prompt = ChatPromptTemplate.from_messages([\n", " (\"system\", \"You are a legal/HR/financial document classifier.\"),\n", " (\"human\", \"\"\"\n", " You will be given the first 2 pages of a document. \n", " Classify it into one of the following categories:\n", " - HR/Employment\n", " - Insurance\n", " - Legal/Compliance\n", " - Financial/Regulatory\n", " - Healthcare \n", " \n", "\n", " Respond strictly in JSON that matches the schema.\n", "\n", " {format_instructions}\n", "\n", " Document content:\n", " {document_content}\n", " \"\"\"),\n", " ])\n", " chain = prompt | llm | parser \n", "\n", " result: DocumentTypeSchema = chain.invoke({\n", " \"document_content\": document_content,\n", " \"format_instructions\": parser.get_format_instructions()\n", " })\n", " return result\n", " " ] }, { "cell_type": "code", "execution_count": 7, "id": "07d15a5b", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "document_types='Insurance'\n" ] } ], "source": [ "result = detect_document_type(doc[0:2])\n", "print(result)" ] }, { "cell_type": "code", "execution_count": null, "id": "6f81613b", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 10, "id": "70d124e5", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "str" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type(result.document_types)" ] }, { "cell_type": "code", "execution_count": 8, "id": "fe8dd781", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n" ] } ], "source": [ "print(type(result))" ] }, { "cell_type": "markdown", "id": "ffbeba05", "metadata": {}, "source": [ "3. extract metadata per page using langextract" ] }, { "cell_type": "code", "execution_count": 155, "id": "0d7035db", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Loading config....\n", "LLM loading...\n", "Loading model from provider: \n", "Loading model from gemini:\n" ] } ], "source": [ "from app.utils.model_loader import ModelLoader\n", "model_loader = ModelLoader(model_provider=\"gemini\")\n", "llm = model_loader.load_llm()" ] }, { "cell_type": "code", "execution_count": 9, "id": "34d845a1", "metadata": {}, "outputs": [], "source": [ "result = extractInsuranceMetadata(doc[11])" ] }, { "cell_type": "code", "execution_count": 10, "id": "7fc00ad8", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "InsuranceMetadata(doc_id=None, doc_category='Insurance', doc_type='Policy doc', jurisdiction='India', effective_date=None, expiry_date=None, parties=['National Insurance Co. Ltd.', 'Insured person', 'Policyholder'], obligations='Disclosure of information, fulfill terms', penalties='Policy void, premium forfeited', notes=None, policy_number='NICHLIP25039V032425', coverage_type='Mediclaim Plus', premium_amount=None, exclusions=['Unrelated treatment', 'Medical equipment', 'Personal comfort items', 'Service charges', 'Home visits', 'War', 'Radioactivity', 'Overseas treatment'])" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "result" ] }, { "cell_type": "code", "execution_count": 11, "id": "f842f878", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "------ Metadata Summary ------\n", "doc_category: Insurance\n", "doc_type: Policy doc\n", "jurisdiction: India\n", "parties: National Insurance Co. Ltd., Insured person, Policyholder\n", "obligations: Disclosure of information, fulfill terms\n", "penalties: Policy void, premium forfeited\n", "policy_number: NICHLIP25039V032425\n", "coverage_type: Mediclaim Plus\n", "exclusions: Unrelated treatment, Medical equipment, Personal comfort items, Service charges, Home visits, War, Radioactivity, Overse...\n" ] } ], "source": [ "def print_metadata(result, max_len: int = 120):\n", " \"\"\"\n", " Pretty prints metadata, only showing non-empty fields.\n", " Long values are truncated for readability.\n", " \"\"\"\n", " print(\"------ Metadata Summary ------\")\n", " for field, value in result.model_dump().items():\n", " if value is None:\n", " continue # skip empty fields\n", "\n", " # Format list fields nicely\n", " if isinstance(value, list):\n", " value = \", \".join(map(str, value))\n", "\n", " # Truncate long values\n", " if isinstance(value, str) and len(value) > max_len:\n", " value = value[:max_len] + \"...\"\n", "\n", " print(f\"{field}: {value}\")\n", "\n", "print_metadata(result)" ] }, { "cell_type": "code", "execution_count": 44, "id": "ba707132", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Document(metadata={'producer': 'Microsoft® Word LTSC', 'creator': 'Microsoft® Word LTSC', 'creationdate': '2025-02-11T11:39:19+05:30', 'source': 'app\\\\uploads\\\\policy.pdf', 'file_path': 'app\\\\uploads\\\\policy.pdf', 'total_pages': 25, 'format': 'PDF 1.7', 'title': 'National Parivar Mediclaim Plus Policy (NPMPP)', 'author': 'Avishek Banerjee', 'subject': '', 'keywords': '', 'moddate': '2025-02-11T11:39:19+05:30', 'trapped': '', 'modDate': \"D:20250211113919+05'30'\", 'creationDate': \"D:20250211113919+05'30'\", 'page': 11}, page_content='National Insurance Co. Ltd. \\nPremises No. 18-0374, Plot no. CBD-81, \\nNew Town, Kolkata - 700156 \\nPage 12 of 25 \\nNational Parivar Mediclaim Plus Policy \\nUIN: NICHLIP25039V032425 \\n \\n4.29. \\nTreatment not Related to Disease for which Claim is Made \\nTreatment which the insured person was on before Hospitalisation for the Illness/Injury, different from the one for which claim for \\nHospitalisation has been made. \\n \\n4.30. \\nEquipments \\nExternal/durable medical/non-medical equipments/instruments of any kind used for diagnosis/ treatment including CPAP, CAPD, \\ninfusion pump, ambulatory devices such as walker, crutches, belts, collars, caps, splints, slings, braces, stockings, diabetic foot-\\nwear, glucometer, thermometer and similar related items and any medical equipment which could be used at home subsequently. \\n \\n4.31. \\nItems of personal comfort \\nItems of personal comfort and convenience including telephone, television, aya, barber, beauty services, baby food, cosmetics, \\nnapkins, toiletries, guest services. \\n \\n4.32. \\nService charge/ registration fee \\nAny kind of service charges including surcharges, admission fees, registration charges and similar charges levied by the hospital. \\n \\n4.33. \\nHome visit charges \\nHome visit charges during Pre and Post Hospitalisation of doctor, attendant and nurse, except as and to the extent provided for under \\nSection 3.1.12 (Doctor’s Home Visit and Nursing Care during Post Hospitalisation). \\n \\n4.34. \\nWar \\nWar (whether declared or not) and war like occurrence or invasion, acts of foreign enemies, hostilities, civil war, rebellion, \\nrevolutions, insurrections, mutiny, military or usurped power, seizure, capture, arrest, restraints and detainment of all kinds. \\n \\n4.35. \\nRadioactivity \\nNuclear, chemical or biological attack or weapons, contributed to, caused by, resulting from or from any other cause or event \\ncontributing concurrently or in any other sequence to the loss, claim or expense. For the purpose of this exclusion: \\n \\na) Nuclear attack or weapons means the use of any nuclear weapon or device or waste or combustion of nuclear fuel or the \\nemission, discharge, dispersal, release or escape of fissile/ fusion material emitting a level of radioactivity capable of causing \\nany Illness, incapacitating disablement or death. \\nb) Chemical attack or weapons means the emission, discharge, dispersal, release or escape of any solid, liquid or gaseous \\nchemical compound which, when suitably distributed, is capable of causing any Illness, incapacitating disablement or death. \\nc) Biological attack or weapons means the emission, discharge, dispersal, release or escape of any pathogenic (disease \\nproducing) micro-organisms and/or biologically produced toxins (including genetically modified organisms and chemically \\nsynthesized toxins) which are capable of causing any Illness, incapacitating disablement or death. \\n \\n4.36. \\nTreatment taken outside the geographical limits of India \\n \\n5 CONDITIONS \\n \\n5.1 Disclosure of Information \\nThe policy shall be void and all premium paid thereon shall be forfeited to the Company in the event of misrepresentation, mis \\ndescription or non-disclosure of any material fact by the policyholder. \\n(Explanation: \"Material facts\" for the purpose of this policy shall mean all relevant information sought by the company in the \\nproposal form and other connected documents to enable it to take informed decision in the context of underwriting the risk) \\n \\n5.2 Condition Precedent to Admission of Liability \\nThe terms and conditions of the policy must be fulfilled by the insured person for the Company to make any payment for claim(s) \\narising under the policy. \\n \\n5.3 Communication \\ni. \\nAll communication should be made in writing. \\nii. For policies serviced by TPA, ID card, PPN/network provider related issues to be communicated to the TPA at the address \\nmentioned in the schedule. For claim serviced by the Company, the Policy related issues to be communicated to the Policy \\nissuing office of the Company at the address mentioned in the schedule. \\niii. Any change of address, state of health or any other change affecting any of the insured person, shall be communicated to the \\nPolicy issuing office of the Company at the address mentioned in the schedule \\niv. The Company or TPA shall communicate to the insured at the address mentioned in the schedule. \\n \\n5.4 Physical Examination \\nAny medical practitioner authorised by the Company shall be allowed to examine the insured person in the event of any alleged \\ninjury or disease requiring hospitalisation when and as often as the same may reasonably be required on behalf of the Company. \\n \\n5.5 Claim Procedure \\n5.5.1 Notification of Claim')" ] }, "execution_count": 44, "metadata": {}, "output_type": "execute_result" } ], "source": [ "doc[11]" ] }, { "cell_type": "code", "execution_count": 46, "id": "b5cb988f", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "dict" ] }, "execution_count": 46, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type(doc[11].metadata)" ] }, { "cell_type": "code", "execution_count": 51, "id": "8f624505", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'doc_id': 'NICHLIP25039V032425',\n", " 'doc_category': 'Insurance',\n", " 'doc_type': 'Policy doc',\n", " 'jurisdiction': 'India',\n", " 'parties': ['Insured person', 'Company'],\n", " 'obligations': 'Policyholder must disclose material facts, insured must fulfill policy terms',\n", " 'penalties': 'Policy void, premium forfeited for misrepresentation',\n", " 'policy_number': 'NICHLIP25039V032425',\n", " 'coverage_type': 'Mediclaim Plus',\n", " 'exclusions': ['Unrelated treatment',\n", " 'Equipments',\n", " 'Personal comfort',\n", " 'Service charges',\n", " 'Home visits',\n", " 'War',\n", " 'Radioactivity',\n", " 'Outside India']}" ] }, "execution_count": 51, "metadata": {}, "output_type": "execute_result" } ], "source": [ "result = result.model_dump(exclude_none=True)\n", "result" ] }, { "cell_type": "markdown", "id": "5a531a28", "metadata": {}, "source": [ "4. Splitting chunks with metadata extraction" ] }, { "cell_type": "code", "execution_count": 140, "id": "8979ee88", "metadata": {}, "outputs": [], "source": [ "doc_content = doc[0:5]" ] }, { "cell_type": "code", "execution_count": null, "id": "c1efc7e7", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "loop started\n", "\n" ] } ], "source": [ "for i, page in enumerate(doc_content): \n", " # reset per page\n", " try:\n", " text = page.get_text()\n", " except:\n", " text = page.page_content\n", " print(type(page))" ] }, { "cell_type": "code", "execution_count": 132, "id": "3f43c88c", "metadata": {}, "outputs": [], "source": [ "def normalize_dict_to_lists(metadata: dict) -> dict:\n", " \"\"\"\n", " Convert every value in a dict to a list (unless it's None).\n", " - None → []\n", " - list → as-is\n", " - scalar → wrap in list\n", " \"\"\"\n", " normalized = {}\n", " for key, value in metadata.items():\n", " if value is None:\n", " normalized[key] = []\n", " elif isinstance(value, list):\n", " normalized[key] = value\n", " else:\n", " normalized[key] = [value]\n", " return normalized\n" ] }, { "cell_type": "code", "execution_count": 161, "id": "6603fdb2", "metadata": {}, "outputs": [], "source": [ "## neww\n", "\n", "import json\n", "from langchain_core.exceptions import OutputParserException\n", "# wrap parser with fixer once\n", "# pydantic_parser = PydanticOutputParser(pydantic_object=InsuranceMetadata)\n", "# fixing_parser = OutputFixingParser.from_llm(llm=llm, parser=pydantic_parser) \n", "def extractInsuranceMetadata(document: Document, known_keywords: dict) -> InsuranceMetadata:\n", " parser = PydanticOutputParser(pydantic_object=InsuranceMetadata)\n", "\n", " schema_str = json.dumps(InsuranceMetadata.model_json_schema(), indent=2)\n", " keywords_str = json.dumps(known_keywords, indent=2)\n", "\n", " prompt = ChatPromptTemplate.from_messages([\n", " (\"system\", \"\"\"You are an information extraction system. \n", " Extract only the required metadata from the text according to schema given below. \n", "\n", " ⚠️ Rules for consistency:\n", " - For exclusions and obligations, DO NOT copy full sentences. \n", " - Instead, extract only concise normalized keywords (2–5 words max each).\n", " - Use existing keywords if they already exist in the provided list.\n", " - Prefer to reuse existing keywords if they are semantically the same. \n", " - If you find a new keyword that is a **sub-type** or **more specific variant** of an existing one, keep both: \n", " *reuse the closest match from existing keywords*, and also add the new one. \n", " - In that case, set `added_new_keyword=true`.\n", " - Do not include raw paragraphs in the output.\n", " \n", " Schema you must follow:\n", " {schema}\n", "\n", " Existing Keywords:\n", " {keywords}\n", " \"\"\"),\n", " (\"human\", \"Text:\\n{document_content}\")\n", " ])\n", " # - Use existing keywords if they already exist in the provided list.\n", " # - Only create a new keyword if absolutely necessary, and set `added_new_keyword=true`.\n", " # - New keywords must be short (1–3 words).\n", " # - Do NOT invent different variations (e.g., if \"Medical\" already exists, do not output \"Mediclaim Plus\").\n", " # - For list fields (like exclusions), reuse existing keywords where possible.\n", " chain = prompt | llm | parser\n", "\n", " try:\n", " result: InsuranceMetadata = chain.invoke({\n", " \"schema\": schema_str,\n", " \"keywords\": keywords_str,\n", " \"document_content\": document.page_content\n", " })\n", " return result\n", " except OutputParserException as e:\n", " print(f\"⚠️ Parser failed on doc {document.metadata.get('source')} | error: {e}\")\n", " return InsuranceMetadata(added_new_keyword=False) " ] }, { "cell_type": "code", "execution_count": 162, "id": "defba5e3", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "doc number: 0\n", "\n", "doc number: 1\n", "\n", "doc number: 2\n", "\n", "doc number: 3\n", "\n", "⚠️ Parser failed on doc app\\uploads\\policy.pdf | error: Failed to parse InsuranceMetadata from completion {\"doc_id\": \"NICHLIP25039V032425\", \"doc_category\": \"Insurance\", \"doc_type\": \"Policy\", \"jurisdiction\": null, \"effective_date\": null, \"expiry_date\": null, \"parties\": [\"National Insurance Company Ltd.\", \"Insured\"], \"obligations\": [\"treatment prescribed by medical practitioner\", \"pay premium for renewal\", \"indemnify medical treatment charges\", \"make records accessible to company\", \"maintain patient records\", \"intimate claim to company/TPA\", \"bear co-payment\", \"indemnify in-patient treatment expenses\", \"indemnify pre-hospitalisation expenses\", \"indemnify post-hospitalisation expenses\", \"indemnify domiciliary hospitalisation expenses\"], \"penalties\": [\"no coverage without premium\"], \"notes\": \"CIN - U10200WB1906GOI001713, IRDAI Regn. No. \\u2013 58, National Parivar Mediclaim Plus Policy\", \"policy_number\": \"NICHLIP25039V032425\", \"coverage_type\": [\"Migration facility\", \"Surgical procedure\", \"Portability facility\", \"In-Patient Care\", \"Domiciliary Hospitalisation\", \"Hospitalisation\", \"Mediclaim\", \"AYUSH Treatment\", \"Intensive Care Unit\", \"mental health establishment\", \"Dental Treatment\", \"Cashless Facility\", \"Day Care Treatment\", \"Anaesthesia\", \"blood\", \"oxygen\", \"operation theatre charges\", \"surgical appliances\", \"Medicines and drugs\", \"Diagnostic procedures\", \"implants during surgical procedure\", \"dental treatment due to injury\", \"plastic surgery for disease/injury\", \"Hormone replacement therapy\", \"vitamins and tonics for treatment\", \"circumcision for disease/injury\", \"Cataract Surgery\", \"hazardous/adventure sports treatment\", \"Pre Hospitalisation\", \"Post Hospitalisation\"], \"premium_amount\": null, \"exclusions\": [\"out-patient treatment\", \"cosmetic surgery\", \"specified diseases during waiting period\", \"implants\", \"unproven/experimental treatment\", \"domiciliary treatment less than 3 days\", \"alternative treatment\", \"maternity or infertility\", \"Asthma\", \"Bronchitis\", \"chronic nephritis/nephritic syndrome\", \"diarrhoea/dysenteries/gastroenteritis\", \"Epilepsy\", \"influenza/cough/cold\", \"psychiatric/psychosomatic disorders\", \"pyrexia of unknown origin <10 days\", \"tonsillitis/upper respiratory infection\", \"arthritis/gout/rheumatism\"], \"added_new_keyword\": true}. Got: 1 validation error for InsuranceMetadata\n", "penalties\n", " Input should be a valid string [type=string_type, input_value=['no coverage without premium'], input_type=list]\n", " For further information visit https://errors.pydantic.dev/2.11/v/string_type\n", "For troubleshooting, visit: https://python.langchain.com/docs/troubleshooting/errors/OUTPUT_PARSING_FAILURE \n", "doc number: 4\n", "\n", "doc number: 5\n", "\n", "doc number: 6\n", "\n", "doc number: 7\n", "\n", "⚠️ Parser failed on doc app\\uploads\\policy.pdf | error: Failed to parse InsuranceMetadata from completion {\"doc_id\": \"NICHLIP25039V032425\", \"doc_category\": \"Insurance\", \"doc_type\": \"Policy\", \"jurisdiction\": \"India\", \"effective_date\": null, \"expiry_date\": null, \"parties\": [\"Hospital\", \"Insured\", \"National Insurance Company Ltd.\", \"Insured Persons\"], \"obligations\": [\"medically indicated Modern Treatments\", \"include new born baby mid-term\", \"make records accessible to company\", \"Insured medically advised transplant\", \"confirm need from medical practitioner\", \"submit legal affidavit (surrogacy)\", \"Insured Person 18 years or older (obesity)\", \"surgery/Procedure supported by clinical protocols (obesity)\", \"BMI greater than or equal to 35 with co-morbidities\", \"limit 25% Sum Insured for Modern Treatment\", \"treatment prescribed by medical practitioner\", \"pay premium for renewal\", \"maintain patient records\", \"intimate claim to company/TPA\", \"failure of less invasive weight loss methods\", \"organ used for Insured Person\", \"treatment at Hospital with specific department for Mental Illness\", \"medical expenses in-patient\", \"ectopic pregnancy established by reports\", \"claim admitted inpatient section\", \"continuously covered 24 months\", \"maximum two claims (no living child)\", \"BMI greater than or equal to 40\", \"treatment upon Medical Practitioner advice (obesity)\", \"policy continuous 24 months (infertility)\", \"unable to attain pregnancy (prior treatment)\", \"bear co-payment\", \"maximum one claim (one living child)\", \"Waiting Period of three years (obesity treatment)\", \"treatment under qualified Medical Practitioner/Psychiatrist\", \"prior intimation to Company/TPA\", \"hospitalisation exceeds three days\", \"indemnify medical treatment charges\", \"infertility inclusion date\", \"confirm organ donation to Act\", \"children covered by Policy\", \"pay requisite premium\", \"indemnify medical expenses (refractive error)\", \"waiting period of two years (refractive error)\", \"reinstatement allowed once per year\", \"single claim maximum sum insured\", \"no claims reported (NCD)\", \"policy continuously renewed\", \"expenses subject to benefit limits\", \"PED declared at application\", \"waiting period reduced (portability)\", \"exclusion not applicable (accident)\", \"longer waiting period applies\"], \"penalties\": [\"no coverage without premium\"], \"notes\": [\"National Parivar Mediclaim Plus Policy\", \"CIN - U10200WB1906GOI001713, IRDAI Regn. No. \\u2013 58\"], \"policy_number\": \"NICHLIP25039V032425\", \"coverage_type\": [\"Pre-Natal expenses\", \"Maternity Expenses\", \"HIV/ AIDS Cover\", \"Stereotactic Radio surgeries\", \"Doctor's Home Visit\", \"Ambulance\", \"Domiciliary Hospitalisation\", \"Anti Rabies Vaccination\", \"Vaporization of the prostrate\", \"Intensive Care Unit\", \"mental health establishment\", \"Medical Emergency Reunion\", \"day care infertility treatment\", \"Organ Donor's Medical Expenses\", \"Vaccination for Children\", \"Air Ambulance\", \"in-patient infertility treatment\", \"Modern Treatments\", \"Pre Hospitalisation Expenses\", \"Post Hospitalisation Expenses\", \"Portability facility\", \"Post-Natal Hospitalisation expenses\", \"childbirth medical expenses\", \"In-Patient Care\", \"infertility treatment\", \"IVF\", \"Hospitalisation\", \"Obesity-related cardiomyopathy\", \"Coronary heart disease\", \"Nursing Care post hospitalisation\", \"Mediclaim\", \"Ectopic pregnancy\", \"Robotic Surgery\", \"Severe Sleep Apnea\", \"Surgical procedure\", \"ICSI\", \"Mental Illness Cover\", \"Immunotherapy\", \"Day Care Procedure\", \"medical termination of pregnancy\", \"ZIFT\", \"Mental Illnesses\", \"caesarean sections\", \"IONM\", \"surgical treatment of obesity\", \"Stem cell therapy\", \"Uncontrolled Type 2 Diabetes\", \"Morbid Obesity Treatment\", \"AYUSH Treatment\", \"UAE & HIFU\", \"GIFT\", \"Maternity\", \"Hospital Cash\", \"Migration facility\", \"New Born Baby coverage\", \"Balloon Sinuplasty\", \"New Born Baby vaccination\", \"Deep Brain Stimulation\", \"Bronchial Thermoplasty\", \"complicated deliveries\", \"Dental Treatment\", \"Oral Chemotherapy\", \"Cashless Facility\", \"Day Care Treatment\", \"Intravitreal injections\", \"Correction of Refractive Error\", \"Reinstatement of Sum Insured\", \"No Claim Discount (NCD)\", \"Health Check Up\"], \"premium_amount\": null, \"exclusions\": [\"reversing vasectomy\", \"insured below 18 years\", \"psychotherapy without hospitalisation\", \"post-hospitalization organ donor expenses\", \"investigations (Oral Chemotherapy)\", \"ectopic pregnancy\", \"family therapy\", \"hospitalisation less than 24 hours (cash)\", \"delivery/termination waiting period\", \"cosmetic surgery\", \"consultation charges (Oral Chemotherapy)\", \"egg/sperm donor expenses\", \"unproven/experimental treatment\", \"experimental treatments\", \"surrogate mother maternity expenses\", \"incidental charges (Oral Chemotherapy)\", \"pre-hospitalization organ donor expenses\", \"donor treatment post-harvesting\", \"cognitive therapy\", \"behavior therapy\", \"Psychological counselling\", \"donor's organ acquisition costs\", \"organ transportation/preservation expenses\", \"infertility diagnostic tests\", \"implants\", \"more than one delivery/termination per period\", \"pre/post hospitalization (non-natal)\", \"reversing tubal ligation\", \"more than two deliveries/terminations\", \"group therapy\", \"out-patient treatment\", \"specified diseases during waiting period\", \"palliative therapy\", \"experimental/investigational organ transplant\", \"surrogate mother disease/injury (non-maternity)\", \"insured above 45 years\", \"insured above 45 years (infertility)\", \"sperm/egg/embryo preservation\", \"Pre-Existing Diseases\", \"specified disease waiting period\", \"Hypertension and related complications\", \"Diabetes and related complications\", \"Cardiac conditions\", \"Benign ENT disorders\", \"Tonsillectomy\", \"Adenoidectomy\", \"Mastoidectomy\", \"Tympanoplasty\"], \"added_new_keyword\": true}. Got: 2 validation errors for InsuranceMetadata\n", "penalties\n", " Input should be a valid string [type=string_type, input_value=['no coverage without premium'], input_type=list]\n", " For further information visit https://errors.pydantic.dev/2.11/v/string_type\n", "notes\n", " Input should be a valid string [type=string_type, input_value=['National Parivar Medicl...IRDAI Regn. No. – 58'], input_type=list]\n", " For further information visit https://errors.pydantic.dev/2.11/v/string_type\n", "For troubleshooting, visit: https://python.langchain.com/docs/troubleshooting/errors/OUTPUT_PARSING_FAILURE \n", "doc number: 8\n", "\n", "doc number: 9\n", "\n", "doc number: 10\n", "\n", "⚠️ Parser failed on doc app\\uploads\\policy.pdf | error: Failed to parse InsuranceMetadata from completion {\"doc_id\": \"NICHLIP25039V032425\", \"doc_category\": \"Insurance\", \"doc_type\": \"Policy\", \"jurisdiction\": \"India\", \"effective_date\": null, \"expiry_date\": null, \"parties\": [\"National Insurance Company Ltd.\", \"policyholders\", \"Insured Person\", \"TPA\", \"Company\", \"insured\", \"medical practitioner\"], \"obligations\": [\"medically indicated Modern Treatments\", \"include new born baby mid-term\", \"make records accessible to company\", \"Insured medically advised transplant\", \"confirm need from medical practitioner\", \"submit legal affidavit (surrogacy)\", \"Insured Person 18 years or older (obesity)\", \"surgery/Procedure supported by clinical protocols (obesity)\", \"BMI greater than or equal to 35 with co-morbidities\", \"limit 25% Sum Insured for Modern Treatment\", \"treatment prescribed by medical practitioner\", \"pay premium for renewal\", \"maintain patient records\", \"intimate claim to company/TPA\", \"failure of less invasive weight loss methods\", \"organ used for Insured Person\", \"treatment at Hospital with specific department for Mental Illness\", \"medical expenses in-patient\", \"ectopic pregnancy established by reports\", \"claim admitted inpatient section\", \"continuously covered 24 months\", \"maximum two claims (no living child)\", \"BMI greater than or equal to 40\", \"treatment upon Medical Practitioner advice (obesity)\", \"policy continuous 24 months (infertility)\", \"unable to attain pregnancy (prior treatment)\", \"bear co-payment\", \"maximum one claim (one living child)\", \"Waiting Period of three years (obesity treatment)\", \"treatment under qualified Medical Practitioner/Psychiatrist\", \"prior intimation to Company/TPA\", \"hospitalisation exceeds three days\", \"indemnify medical treatment charges\", \"infertility inclusion date\", \"confirm organ donation to Act\", \"children covered by Policy\", \"pay requisite premium\", \"disclose material facts\", \"fulfill policy terms/conditions\", \"communication in writing\", \"communicate TPA (ID card/network)\", \"communicate company (policy issues)\", \"communicate change of address\", \"communicate change of health state\", \"communicate changes affecting insured\", \"allow medical examination\"], \"penalties\": [\"no coverage without premium\", \"policy void\", \"premium forfeited\"], \"notes\": [\"National Parivar Mediclaim Plus Policy\", \"CIN - U10200WB1906GOI001713, IRDAI Regn. No. \\u2013 58\", \"CIN - U10200WB1906GOI001713, IRDAI Regn. No. \\u2013 58, National Parivar Mediclaim Plus Policy\"], \"policy_number\": \"NICHLIP25039V032425\", \"coverage_type\": [\"Maternity Expenses\", \"Anti Rabies Vaccination\", \"Vaporization of the prostrate\", \"Intensive Care Unit\", \"Medical Emergency Reunion\", \"Pilonidal sinus\", \"infertility treatment\", \"Hospitalisation\", \"Severe Sleep Apnea\", \"Ectopic pregnancy\", \"Immunotherapy\", \"caesarean sections\", \"Hernia\", \"Morbid Obesity Treatment\", \"Hospital Cash\", \"Hydrocele\", \"Balloon Sinuplasty\", \"New Born Baby vaccination\", \"Cashless Facility\", \"Intravitreal injections\", \"Surgery of genito-urinary system\", \"Osteoarthritis and osteoporosis\", \"Stereotactic Radio surgeries\", \"Domiciliary Hospitalisation\", \"day care infertility treatment\", \"Vaccination for Children\", \"Congenital Internal Anomaly\", \"Air Ambulance\", \"Fissure/Fistula in anus\", \"In-Patient Care\", \"IVF\", \"Obesity-related cardiomyopathy\", \"surgical treatment of obesity\", \"Non-infective arthritis\", \"AYUSH Treatment\", \"Cataract\", \"Refractive error eye\", \"Polycystic ovarian disease\", \"Piles\", \"Bronchial Thermoplasty\", \"Dental Treatment\", \"Oral Chemotherapy\", \"Pre-Natal expenses\", \"Ambulance\", \"Joint replacement treatment\", \"Organ Donor's Medical Expenses\", \"in-patient infertility treatment\", \"Post Hospitalisation Expenses\", \"Portability facility\", \"Post-Natal Hospitalisation expenses\", \"Mediclaim\", \"ICSI\", \"Mental Illnesses\", \"IONM\", \"Gout and Rheumatism\", \"Stem cell therapy\", \"UAE & HIFU\", \"Maternity\", \"Migration facility\", \"New Born Baby coverage\", \"Hematopoietic stem cell transplant\", \"Deep Brain Stimulation\", \"Surgery of varicose vein\", \"Day Care Treatment\", \"Surgery of gall bladder and bile duct\", \"HIV/ AIDS Cover\", \"Hysterectomy\", \"Doctor's Home Visit\", \"mental health establishment\", \"Benign prostatic hypertrophy\", \"Modern Treatments\", \"Pre Hospitalisation Expenses\", \"childbirth medical expenses\", \"Coronary heart disease\", \"Nursing Care post hospitalisation\", \"Robotic Surgery\", \"Surgical procedure\", \"Mental Illness Cover\", \"Sinusitis\", \"Surgery for prolapsed intervertebral disc\", \"Day Care Procedure\", \"medical termination of pregnancy\", \"ZIFT\", \"Uncontrolled Type 2 Diabetes\", \"GIFT\", \"Morbid Obesity complications\", \"Calculus diseases\", \"complicated deliveries\"], \"premium_amount\": null, \"exclusions\": [\"Hysterectomy (two-year waiting)\", \"psychotherapy without hospitalisation\", \"Treatment to change appearance\", \"hospitalisation less than 24 hours (cash)\", \"obesity surgical treatment\", \"Illness treatment within 30 days\", \"contact lens\", \"egg/sperm donor expenses\", \"Change-of-gender treatments\", \"unproven/experimental treatment\", \"Benign prostatic hypertrophy (two-year waiting)\", \"experimental treatments\", \"Piles (two-year waiting)\", \"Gout and Rheumatism (two-year waiting)\", \"Cataract (two-year waiting)\", \"acupressure\", \"more than one delivery/termination per period\", \"non-prescription vitamins/minerals\", \"Refractive error eye (two-year waiting)\", \"private nursing charges\", \"stem cell surgery\", \"Pilonidal sinus (two-year waiting)\", \"spas\", \"palliative therapy\", \"cochlear implants\", \"surrogate mother disease/injury (non-maternity)\", \"Admission for enforced bed rest\", \"Custodial care nursing facility\", \"insured above 45 years (infertility)\", \"non-prescription drugs\", \"insured below 18 years\", \"post-hospitalization organ donor expenses\", \"Joint replacement treatment (three-year waiting)\", \"steam bath\", \"investigations (Oral Chemotherapy)\", \"ectopic pregnancy\", \"family therapy\", \"Hernia (two-year waiting)\", \"Calculus diseases (two-year waiting)\", \"Custodial care at home\", \"treatment by excluded providers\", \"delivery/termination waiting period\", \"breach of law\", \"refractive error less than 7.5 dioptres\", \"spectacles\", \"behavior therapy\", \"Varicose vein surgery (two-year waiting)\", \"nature cure clinics\", \"pre/post hospitalization (non-natal)\", \"attempted suicide\", \"congenital external anomaly\", \"reversing tubal ligation\", \"Osteoarthritis/osteoporosis (three-year waiting)\", \"general debility\", \"Diagnostic expenses unrelated to treatment\", \"outstation doctor/surgeon/consultant fees\", \"experimental/investigational organ transplant\", \"Genito-urinary system surgery (two-year waiting)\", \"Congenital Internal Anomaly (two-year waiting)\", \"insured above 45 years\", \"Hazardous/adventure sports injury\", \"non-medical admissions\", \"Hydrocele (two-year waiting)\", \"drug abuse\", \"Gall bladder surgery (two-year waiting)\", \"cosmetic surgery\", \"Obesity surgical treatment non-compliant\", \"surrogate mother maternity expenses\", \"incidental charges (Oral Chemotherapy)\", \"Morbid Obesity complications (three-year waiting)\", \"hormone replacement therapy\", \"donor treatment post-harvesting\", \"organ transportation/preservation expenses\", \"infertility diagnostic tests\", \"implants\", \"alcoholism\", \"self-inflicted injury\", \"more than two deliveries/terminations\", \"group therapy\", \"addictive condition\", \"health hydros\", \"out-patient treatment\", \"specified diseases during waiting period\", \"vaccination or inoculation\", \"Non-infective arthritis (two-year waiting)\", \"sperm/egg/embryo preservation\", \"reversing vasectomy\", \"Cosmetic/plastic surgery (non-reconstructive)\", \"Services for terminally ill\", \"Stem Cell Therapy (three-year waiting)\", \"alternative treatments (non-AYUSH)\", \"Sinusitis (two-year waiting)\", \"magneto-therapy\", \"substance abuse\", \"consultation charges (Oral Chemotherapy)\", \"acupuncture\", \"Pre-existing diseases\", \"Admission for diagnostics only\", \"circumcision\", \"pre-hospitalization organ donor expenses\", \"cognitive therapy\", \"Psychological counselling\", \"donor's organ acquisition costs\", \"non-medically necessary hospital stay\", \"hearing aid\", \"massages\", \"Polycystic ovarian disease (two-year waiting)\", \"referral fee (family physician)\", \"Bile duct surgery (two-year waiting)\", \"Non-accident claims (first 30 days)\", \"Fissure/Fistula in anus (two-year waiting)\", \"Prolapsed intervertebral disc surgery (two-year waiting)\", \"dietary supplements\", \"Enhanced sum insured waiting period\", \"dental treatment\", \"treatment not related to claim disease\", \"external medical equipment\", \"durable medical equipment\", \"non-medical equipment\", \"home use medical equipment\", \"CPAP machine\", \"CAPD machine\", \"infusion pump\", \"ambulatory devices\", \"support devices\", \"diabetic footwear\", \"glucometer\", \"thermometer\", \"personal comfort items\", \"communication devices\", \"personal care services\", \"baby food\", \"cosmetics\", \"napkins\", \"toiletries\", \"guest services\", \"service charges\", \"surcharges\", \"admission fees\", \"registration charges\", \"hospital levied charges\", \"pre-hospitalisation home visit charges\", \"post-hospitalisation home visit charges\", \"attendant home visit charges\", \"nurse home visit charges\", \"war\", \"war-like events\", \"acts of foreign enemies\", \"civil war\", \"rebellion\", \"insurrection\", \"mutiny\", \"military power\", \"nuclear attack/weapons\", \"chemical attack/weapons\", \"biological attack/weapons\", \"nuclear fuel waste\", \"radioactive material emission\", \"treatment outside India\"], \"added_new_keyword\": true}. Got: 2 validation errors for InsuranceMetadata\n", "penalties\n", " Input should be a valid string [type=string_type, input_value=['no coverage without pre...d', 'premium forfeited'], input_type=list]\n", " For further information visit https://errors.pydantic.dev/2.11/v/string_type\n", "notes\n", " Input should be a valid string [type=string_type, input_value=['National Parivar Medicl... Mediclaim Plus Policy'], input_type=list]\n", " For further information visit https://errors.pydantic.dev/2.11/v/string_type\n", "For troubleshooting, visit: https://python.langchain.com/docs/troubleshooting/errors/OUTPUT_PARSING_FAILURE \n", "doc number: 11\n", "\n", "⚠️ Parser failed on doc app\\uploads\\policy.pdf | error: Failed to parse InsuranceMetadata from completion {\"doc_id\": \"NICHLIP25039V032425\", \"doc_category\": \"Insurance\", \"doc_type\": \"Policy\", \"jurisdiction\": \"India\", \"effective_date\": null, \"expiry_date\": null, \"parties\": [\"Hospital\", \"Insured\", \"Network Provider\", \"National Insurance Company Ltd.\", \"TPA\", \"Medical Practitioner\", \"Insured Person\", \"family member\", \"surgeon\", \"insured person's representative\", \"PPN\", \"chemist\", \"other insurer\"], \"obligations\": [\"intimate claim to company/TPA\", \"notify TPA 72 hours prior (planned hospitalization)\", \"notify TPA 24 hours of admission (emergency)\", \"notify Company/TPA 72 hours prior (planned)\", \"notify Company/TPA 24 hours of admission (emergency)\", \"notify Company/TPA 24 hours prior (vaccination)\", \"complete and send cashless request form\", \"TPA issue pre-authorization letter\", \"Insured verify and sign discharge papers\", \"Insured pay non-medical expenses\", \"TPA grant final authorization\", \"submit claim documents to TPA\", \"submit necessary documents within time limit\", \"submit original claim documents\", \"submit completed claim form\", \"submit bills, receipts, medical history\", \"submit cash memo with prescription\", \"submit test reports with prescription\", \"submit medical practitioner's certificate\", \"submit surgeon's certificate\", \"submit domiciliary medical certificate\", \"submit legal affidavit (surrogacy)\", \"confirm need from medical practitioner\", \"submit family member need confirmation (Medical Emergency Reunion)\", \"submit police investigation report (RTA)\", \"submit other requested documents\"], \"penalties\": [\"no coverage without premium\", \"deny pre-authorization\"], \"notes\": \"National Parivar Mediclaim Plus Policy, CIN - U10200WB1906GOI001713, IRDAI Regn. No. \\u2013 58, Company address: Premises No. 18-0374, Plot no. CBD-81, New Town, Kolkata - 700156\", \"policy_number\": \"NICHLIP25039V032425\", \"coverage_type\": [\"Maternity Expenses\", \"Anti Rabies Vaccination\", \"Medical Emergency Reunion\", \"infertility treatment\", \"Hospitalisation\", \"Cashless Facility\", \"Domiciliary Hospitalisation\", \"Vaccination for Children\", \"Maternity\", \"Reimbursement\", \"Surrogacy under Infertility\"], \"premium_amount\": null, \"exclusions\": [\"non-medical expenses\", \"inadmissible expenses\"], \"added_new_keyword\": true}. Got: 1 validation error for InsuranceMetadata\n", "penalties\n", " Input should be a valid string [type=string_type, input_value=['no coverage without pre...deny pre-authorization'], input_type=list]\n", " For further information visit https://errors.pydantic.dev/2.11/v/string_type\n", "For troubleshooting, visit: https://python.langchain.com/docs/troubleshooting/errors/OUTPUT_PARSING_FAILURE \n", "doc number: 12\n", "\n", "⚠️ Parser failed on doc app\\uploads\\policy.pdf | error: Failed to parse InsuranceMetadata from completion {\"doc_id\": \"NICHLIP25039V032425\", \"doc_category\": \"Insurance\", \"doc_type\": \"Policy\", \"jurisdiction\": \"India\", \"effective_date\": null, \"expiry_date\": null, \"parties\": [\"National Insurance Company Ltd.\", \"Policyholders\", \"TPA\", \"Insured Person\", \"Insured\"], \"obligations\": [\"bear co-payment\", \"intimate claim to company/TPA\", \"submit documents within 15 days (hospital discharge)\", \"submit documents within 15 days (post hospitalisation)\", \"submit documents within 15 days (domiciliary hospitalisation)\", \"submit documents within 15 days (vaccination)\", \"submit documents within 15 days (infertility treatment)\", \"submit health check up expenses (45 days prior)\", \"Company settle/reject claim within 15 days\", \"Company complete claim investigation within 30 days\", \"Company settle/reject claim within 45 days (investigation)\", \"TPA render health care services\", \"TPA issue ID cards & guide book\", \"TPA provide pre-authorization services\", \"TPA accept claim documents\", \"TPA process claims\", \"TPA recommend claim settlement\", \"intimate claim/submit documents on time\"], \"penalties\": [\"no coverage without premium\", \"Company pay interest for claim delay\", \"Company pay interest for claim delay (beyond 45 days)\"], \"notes\": \"National Parivar Mediclaim Plus Policy\", \"policy_number\": \"NICHLIP25039V032425\", \"coverage_type\": [\"Hospitalisation\", \"Pre Hospitalisation Expenses\", \"Ambulance\", \"Air Ambulance\", \"Medical Emergency Reunion\", \"Post Hospitalisation Expenses\", \"Doctor's Home Visit\", \"Nursing Care post hospitalisation\", \"Domiciliary Hospitalisation\", \"Anti Rabies Vaccination\", \"New Born Baby vaccination\", \"Vaccination for Children\", \"infertility treatment\", \"Health check up expenses\"], \"premium_amount\": null, \"exclusions\": [\"TPA claim settlement\", \"TPA claim rejection\", \"TPA direct services to insured (no agreement)\"], \"added_new_keyword\": true}. Got: 1 validation error for InsuranceMetadata\n", "penalties\n", " Input should be a valid string [type=string_type, input_value=['no coverage without pre...delay (beyond 45 days)'], input_type=list]\n", " For further information visit https://errors.pydantic.dev/2.11/v/string_type\n", "For troubleshooting, visit: https://python.langchain.com/docs/troubleshooting/errors/OUTPUT_PARSING_FAILURE \n", "doc number: 13\n", "\n", "doc number: 14\n", "\n", "⚠️ Parser failed on doc app\\uploads\\policy.pdf | error: Failed to parse InsuranceMetadata from completion {\"doc_id\": \"NICHLIP25039V032425\", \"doc_category\": \"Insurance\", \"doc_type\": \"Policy\", \"jurisdiction\": \"India\", \"effective_date\": null, \"expiry_date\": null, \"parties\": [\"National Insurance Company Ltd.\", \"Insurer\", \"Policyholders\", \"Insured Person\", \"Insured\", \"Company\", \"grandparents\", \"Proposer\", \"children\"], \"obligations\": [\"pay requisite premium\", \"policyholder give notice for cancellation\", \"insurer refund proportionate premium\", \"insurer refund premium for unexpired period (term > 1 year)\", \"disputes determined by Indian court\", \"refer quantum disputes to arbitration\", \"obtain arbitration award before legal action\", \"notify company if disclaimer not accepted\", \"provide migration options if product withdrawn\", \"insured person above 18 renew policy\", \"grandparents renew policy for grandchildren\", \"enhance sum insured at renewal\", \"waiting periods apply to enhanced sum insured\", \"inform company of overseas travel insurance\", \"apply for migration 30 days before renewal\"], \"penalties\": [\"all benefits and premium forfeited for fraud; no refund of premium on cancellation for misrepresentation, non-disclosure, or fraud\", \"no coverage without premium\", \"no premium refund if claim lodged/admitted\", \"claim abandoned if disclaimer not challenged\", \"renewal denied for fraud/non-disclosure/misrepresentation\"], \"notes\": [\"National Parivar Mediclaim Plus Policy\", \"National Parivar Mediclaim Plus Policy, UIN: NICHLIP25039V032425\"], \"policy_number\": \"NICHLIP25039V032425\", \"coverage_type\": [], \"premium_amount\": null, \"exclusions\": [\"Enhanced sum insured waiting period\", \"no premium refund if claim availed\", \"arbitration not applicable if liability disputed\", \"no coverage during grace period\", \"policy inoperative with overseas travel insurance\"], \"added_new_keyword\": true}. Got: 2 validation errors for InsuranceMetadata\n", "penalties\n", " Input should be a valid string [type=string_type, input_value=['all benefits and premiu...sure/misrepresentation'], input_type=list]\n", " For further information visit https://errors.pydantic.dev/2.11/v/string_type\n", "notes\n", " Input should be a valid string [type=string_type, input_value=['National Parivar Medicl...N: NICHLIP25039V032425'], input_type=list]\n", " For further information visit https://errors.pydantic.dev/2.11/v/string_type\n", "For troubleshooting, visit: https://python.langchain.com/docs/troubleshooting/errors/OUTPUT_PARSING_FAILURE \n", "doc number: 15\n", "\n", "doc number: 16\n", "\n", "doc number: 17\n", "\n", "doc number: 18\n", "\n", "doc number: 19\n", "\n", "doc number: 20\n", "\n", "doc number: 21\n", "\n", "doc number: 22\n", "\n", "⚠️ Parser failed on doc app\\uploads\\policy.pdf | error: Failed to parse InsuranceMetadata from completion {\"doc_id\": \"NICHLIP25039V032425\", \"doc_category\": \"Insurance\", \"doc_type\": \"Policy\", \"jurisdiction\": \"India\", \"effective_date\": null, \"expiry_date\": null, \"parties\": [\"Hospital\", \"Insured\", \"Bima Bharosa\", \"nominee\", \"Network Provider\", \"insured person's representative\", \"recipient\", \"sperm donor\", \"National Insurance Company Ltd.\", \"oocyte donor\", \"policyholders\", \"Proposer\", \"other insurers\", \"spouse\", \"Doctor\", \"qualified nurse\", \"Company\", \"Medical Practitioner\", \"Insurance Ombudsman\", \"agent\", \"Insured Persons\", \"TPA\", \"intermediary\", \"Non Network Provider\", \"legal heirs\", \"Policyholders\", \"children\", \"beneficiary\", \"family member\", \"Organ donor\", \"Insured Person\", \"egg donor\", \"Insurer\", \"Psychiatrist\", \"specialist medical practitioner\", \"IRDAI\", \"legal representatives\", \"medical practitioner\"], \"obligations\": [\"renew critical illness cover annually\", \"submit legal affidavit (surrogacy)\", \"apply 15-60 days before renewal\", \"Insured Person 18 years or older (obesity)\", \"surgery/Procedure supported by clinical protocols (obesity)\", \"benefit amount enhanced to next slab\", \"BMI greater than or equal to 35 with co-morbidities\", \"Company give 15 days notice for cancellation\", \"treatment prescribed by medical practitioner\", \"Company intimate withdrawal 90 days prior\", \"pay premium for renewal\", \"insured right to choose policy for claim\", \"renew outpatient treatment cover annually\", \"maintain patient records\", \"submit out-patient treatment documents\", \"claim payable Indian currency NEFT/RTGS\", \"organ used for Insured Person\", \"medicines prescribed by medical practitioner\", \"insured allowed 30 day free look\", \"submit documents within 60 days of diagnosis\", \"diagnosis evidenced by CT/MRI\", \"insured 18-65 years (critical illness)\", \"paralysis persists 3 months\", \"Waiting Period of three years (obesity treatment)\", \"change optional co-payment during renewal\", \"claim supported by original documents\", \"insured diagnosed with critical illness\", \"declare pre-existing diseases\", \"Company notify insured before changes\", \"policy period and cover identical\", \"pay requisite premium\", \"bear 22.5% co-payment Zone I\", \"intimate claim within 15 days\", \"claim subject to sub limits\", \"include new born baby mid-term\", \"no maternity/infertility discount\", \"diagnosis confirmed by specialist\", \"Insured medically advised transplant\", \"insured submit grievance in writing\", \"claim subject to sum insured\", \"waiting period two years\", \"enhance benefit amount at renewal\", \"submit bills/prescriptions\", \"claim not subject to co-payment\", \"submit other required documents\", \"communicate change of nomination\", \"insured approach Insurance Ombudsman\", \"medical expenses in-patient\", \"continuously covered 24 months\", \"maximum two claims (no living child)\", \"no intermediary involved (discount)\", \"claim from all insurers (critical illness)\", \"policy continuous 24 months (infertility)\", \"unable to attain pregnancy (prior treatment)\", \"Company pay nominee/legal heirs\", \"Insured apply to other insurer for portability\", \"treatment under qualified Medical Practitioner/Psychiatrist\", \"enhance cover limit at renewal\", \"hospitalisation exceeds three days\", \"indemnify medical treatment charges\", \"infertility inclusion date\", \"children covered by Policy\", \"repay fraudulent claim amounts\", \"no claim discount\", \"diagnostic tests prescribed by medical practitioner\", \"submit diagnostic test bills/reports\", \"reinstatement of sum insured\", \"maintain continuous insurance 36 months\", \"admissible claim subject to co-payment\", \"diagnosis supported by angiography\", \"critical illness diagnosis supported by evidence\", \"limit 25% Sum Insured for Modern Treatment\", \"submit doctor's certificate\", \"insured survives 30 days post-diagnosis\", \"insured prefer claims for disallowed amounts\", \"intimate claim to company/TPA\", \"avail treatment Zone IV no co-payment\", \"insurer settle chosen policy claim\", \"endorsement for change of nomination\", \"renew cover annually\", \"ectopic pregnancy established by reports\", \"claim admitted inpatient section\", \"BMI greater than or equal to 40\", \"policy maintained without break\", \"insured not made claim during free look\", \"10% online discount\", \"pre-policy checkup for critical illness\", \"out-patient consultations prescribed by medical practitioner\", \"maximum one claim (one living child)\", \"jointly/severally liable for repayment\", \"claim subject to co-payment\", \"pay additional premium for add-ons\", \"insured option to cancel policy\", \"treatment taken in India only\", \"indemnified treatment costs per chosen policy\", \"submit diagnostic test reports\", \"medically indicated Modern Treatments\", \"make records accessible to company\", \"insured choose insurer for balance claim\", \"confirm need from medical practitioner\", \"pay additional premium\", \"bear 17.5% co-payment Zone II\", \"policyholder make nomination at inception\", \"health check up every two years\", \"discount above 45 years\", \"insurer independently settle disallowed claim\", \"failure of less invasive weight loss methods\", \"treatment at Hospital with specific department for Mental Illness\", \"opt for optional co-payment\", \"treatment upon Medical Practitioner advice (obesity)\", \"evidence permanent neurological deficit (3 months)\", \"critical illness benefit limit\", \"bear co-payment\", \"prior intimation to Company/TPA\", \"continuously covered without lapses\", \"cancer diagnosis supported by histology\", \"confirm organ donation to Act\", \"long term discount\", \"bear 10% co-payment Zone III\"], \"penalties\": [\"all benefits and premium forfeited for fraud; no refund of premium on cancellation for misrepresentation, non-disclosure, or fraud\", \"no coverage without premium\"], \"notes\": [\"National Parivar Mediclaim Plus Policy\", \"National Parivar Mediclaim Plus Policy, UIN: NICHLIP25039V032425\", \"CIN - U10200WB1906GOI001713, IRDAI Regn. No. \\u2013 58\", \"CIN - U10200WB1906GOI001713, IRDAI Regn. No. \\u2013 58, National Parivar Mediclaim Plus Policy\"], \"policy_number\": \"NICHLIP25039V032425\", \"coverage_type\": [\"Maternity Expenses\", \"Anti Rabies Vaccination\", \"hazardous sports injury coverage\", \"Vaporization of the prostrate\", \"Intensive Care Unit\", \"Medical Emergency Reunion\", \"Pilonidal sinus\", \"Stroke\", \"infertility treatment\", \"Hospitalisation\", \"Severe Sleep Apnea\", \"Out-patient Treatment\", \"Ectopic pregnancy\", \"OPV vaccination\", \"Immunotherapy\", \"caesarean sections\", \"Hernia\", \"Morbid Obesity Treatment\", \"Hospital Cash\", \"Hydrocele\", \"Balloon Sinuplasty\", \"New Born Baby vaccination\", \"permanent paralysis of limbs\", \"Cashless Facility\", \"Intravitreal injections\", \"Surgery of genito-urinary system\", \"Osteoarthritis and osteoporosis\", \"Stereotactic Radio surgeries\", \"Medicines/drugs\", \"Domiciliary Hospitalisation\", \"Measles vaccination\", \"day care infertility treatment\", \"BCG vaccination\", \"Vaccination for Children\", \"Congenital Internal Anomaly\", \"Air Ambulance\", \"Day Care Procedures\", \"Fissure/Fistula in anus\", \"In-Patient Care\", \"IVF\", \"Obesity-related cardiomyopathy\", \"surgical treatment of obesity\", \"major organ/bone marrow transplant\", \"Non-infective arthritis\", \"Chicken Pox vaccination\", \"AYUSH Treatment\", \"Cataract\", \"Non-Medical Expenses\", \"Refractive error eye\", \"Polycystic ovarian disease\", \"Allopathy\", \"Piles\", \"Bronchial Thermoplasty\", \"Dental Treatment\", \"Oral Chemotherapy\", \"Hepatitis-B vaccination\", \"Pre-Natal expenses\", \"TT vaccination\", \"Ambulance\", \"Joint replacement treatment\", \"Organ Donor's Medical Expenses\", \"in-patient infertility treatment\", \"blindness\", \"Hib vaccination\", \"Post Hospitalisation Expenses\", \"Portability facility\", \"Post-Natal Hospitalisation expenses\", \"Health Check-up\", \"kidney failure (dialysis)\", \"Mediclaim\", \"ICSI\", \"multiple sclerosis\", \"Mental Illnesses\", \"IONM\", \"Gout and Rheumatism\", \"Home Care Treatment\", \"Pre-existing diabetes\", \"Stem cell therapy\", \"UAE & HIFU\", \"Out patient dental treatment\", \"Maternity\", \"Cancer\", \"Out-patient consultations\", \"Migration facility\", \"New Born Baby coverage\", \"Outpatient treatment optional cover\", \"Hematopoietic stem cell transplant\", \"Deep Brain Stimulation\", \"Surgery of varicose vein\", \"Day Care Treatment\", \"Surgery of gall bladder and bile duct\", \"HIV/ AIDS Cover\", \"Hysterectomy\", \"Doctor's Home Visit\", \"Critical illness\", \"mental health establishment\", \"Benign prostatic hypertrophy\", \"Modern Treatments\", \"Pre Hospitalisation Expenses\", \"childbirth medical expenses\", \"Coronary heart disease\", \"Nursing Care post hospitalisation\", \"Robotic Surgery\", \"Surgical procedure\", \"Mental Illness Cover\", \"Sinusitis\", \"Surgery for prolapsed intervertebral disc\", \"hypertension optional cover\", \"MMR vaccination\", \"Day Care Procedure\", \"medical termination of pregnancy\", \"Typhoid vaccination\", \"ZIFT\", \"HPV vaccination\", \"Uncontrolled Type 2 Diabetes\", \"Diagnostic tests\", \"Pre-existing Disease coverage\", \"DPT vaccination\", \"Meningococcal vaccination\", \"Room Charges\", \"GIFT\", \"Morbid Obesity complications\", \"Calculus diseases\", \"open chest CABG\", \"complicated deliveries\"], \"premium_amount\": null, \"exclusions\": [\"Hysterectomy (two-year waiting)\", \"psychotherapy without hospitalisation\", \"Treatment to change appearance\", \"neurological damage (SLE)\", \"hospitalisation less than 24 hours (cash)\", \"obesity surgical treatment\", \"Cervical dysplasia CIN-1\", \"key-hole/laser surgery\", \"Illness treatment within 30 days\", \"contact lens\", \"break of policy\", \"islets of langerhans transplant\", \"egg/sperm donor expenses\", \"Doctor's Home Visit (Plan A)\", \"Change-of-gender treatments\", \"unproven/experimental treatment\", \"Benign prostatic hypertrophy (two-year waiting)\", \"experimental treatments\", \"Piles (two-year waiting)\", \"Gout and Rheumatism (two-year waiting)\", \"Cataract (two-year waiting)\", \"acupressure\", \"chronic lymphocytic leukaemia (RAI < 3)\", \"non-invasive tumors\", \"more than one delivery/termination per period\", \"non-prescription vitamins/minerals\", \"Refractive error eye (two-year waiting)\", \"private nursing charges\", \"co-payments critical illness\", \"stem cell surgery\", \"malignant melanoma (non-invasive)\", \"Pilonidal sinus (two-year waiting)\", \"spas\", \"other stem-cell transplants\", \"no claim for critical illness already paid\", \"palliative therapy\", \"cochlear implants\", \"false statement/declaration\", \"tooth whitening\", \"transient ischemic attacks\", \"benign tumors\", \"surrogate mother disease/injury (non-maternity)\", \"Admission for enforced bed rest\", \"Custodial care nursing facility\", \"insured above 45 years (infertility)\", \"non-prescription drugs\", \"Nursing Care post hospitalisation (Plan A)\", \"insured below 18 years\", \"treatment other than Allopathy/Modern medicine/AYUSH\", \"cosmetic dental treatment\", \"post-hospitalization organ donor expenses\", \"Joint replacement treatment (three-year waiting)\", \"low malignant potential tumors\", \"steam bath\", \"co-payments outpatient treatment\", \"investigations (Oral Chemotherapy)\", \"ectopic pregnancy\", \"family therapy\", \"Hernia (two-year waiting)\", \"prostate tumors (low Gleason/TNM)\", \"Calculus diseases (two-year waiting)\", \"Custodial care at home\", \"treatment by excluded providers\", \"delivery/termination waiting period\", \"breach of law\", \"refractive error less than 7.5 dioptres\", \"spectacles\", \"bridges\", \"behavior therapy\", \"fraudulent means/devices\", \"Varicose vein surgery (two-year waiting)\", \"nature cure clinics\", \"pre/post hospitalization (non-natal)\", \"attempted suicide\", \"congenital external anomaly\", \"reversing tubal ligation\", \"Osteoarthritis/osteoporosis (three-year waiting)\", \"non-disclosure of material facts\", \"Cervical dysplasia CIN-2\", \"general debility\", \"Diagnostic expenses unrelated to treatment\", \"outstation doctor/surgeon/consultant fees\", \"experimental/investigational organ transplant\", \"Genito-urinary system surgery (two-year waiting)\", \"pre-malignant tumors\", \"papillary bladder cancer (non-invasive)\", \"Congenital Internal Anomaly (two-year waiting)\", \"dental implants\", \"insured above 45 years\", \"Hazardous/adventure sports injury\", \"neoplasm of unknown behavior\", \"non-melanoma skin carcinoma (no metastasis)\", \"non-medical admissions\", \"thyroid cancers (TNM T1N0M0 or below)\", \"Hydrocele (two-year waiting)\", \"drug abuse\", \"Gall bladder surgery (two-year waiting)\", \"cosmetic surgery\", \"Obesity surgical treatment non-compliant\", \"surrogate mother maternity expenses\", \"traumatic brain injury\", \"incidental charges (Oral Chemotherapy)\", \"vascular disease (eye/optic nerve/vestibular)\", \"Morbid Obesity complications (three-year waiting)\", \"hormone replacement therapy\", \"crowns\", \"donor treatment post-harvesting\", \"organ transportation/preservation expenses\", \"infertility diagnostic tests\", \"implants\", \"alcoholism\", \"cover ceases upon critical illness payment\", \"self-inflicted injury\", \"more than two deliveries/terminations\", \"group therapy\", \"addictive condition\", \"health hydros\", \"gastro-intestinal stromal tumors (low grade)\", \"out-patient treatment\", \"specified diseases during waiting period\", \"veneers\", \"critical illness (90-day waiting)\", \"vaccination or inoculation\", \"carcinoma in situ\", \"Non-infective arthritis (two-year waiting)\", \"sperm/egg/embryo preservation\", \"no further claim for critical illness\", \"reversing vasectomy\", \"Cosmetic/plastic surgery (non-reconstructive)\", \"Carcinoma in situ of breasts\", \"borderline malignant tumors\", \"Services for terminally ill\", \"Stem Cell Therapy (three-year waiting)\", \"alternative treatments (non-AYUSH)\", \"Sinusitis (two-year waiting)\", \"magneto-therapy\", \"substance abuse\", \"consultation charges (Oral Chemotherapy)\", \"acupuncture\", \"Pre-existing diseases\", \"Admission for diagnostics only\", \"circumcision\", \"Cervical dysplasia CIN-3\", \"pre-hospitalization organ donor expenses\", \"tooth-coloured fillings\", \"cognitive therapy\", \"Psychological counselling\", \"fraudulent claims\", \"donor's organ acquisition costs\", \"non-medically necessary hospital stay\", \"hearing aid\", \"massages\", \"misrepresentation\", \"Polycystic ovarian disease (two-year waiting)\", \"Medical Emergency Reunion (Plan A)\", \"referral fee (family physician)\", \"Air Ambulance (Plan A)\", \"Bile duct surgery (two-year waiting)\", \"Non-accident claims (first 30 days)\", \"Fissure/Fistula in anus (two-year waiting)\", \"Prolapsed intervertebral disc surgery (two-year waiting)\", \"dietary supplements\", \"Enhanced sum insured waiting period\", \"angioplasty/intra-arterial procedures\", \"dental treatment\", \"baby food\", \"baby utilities charges\", \"beauty services\", \"belts and braces\", \"buds\", \"cold/hot pack\", \"carry bags\", \"email/internet charges\", \"food charges (non-hospital diet)\", \"leggings\", \"laundry charges\", \"mineral water\", \"sanitary pad\", \"telephone charges\", \"guest services\", \"crepe bandage\", \"diaper of any type\", \"eyelet collar\", \"slings\", \"blood grouping/cross matching (donors)\", \"service charges (with nursing charge)\", \"television charges\", \"surcharges\", \"attendant charges\", \"extra patient diet\", \"birth certificate charges\", \"certificate charges\", \"courier charges\", \"conveyance charges\", \"medical certificate charges\", \"medical records charges\", \"photocopies charges\", \"mortuary charges\", \"walking aids charges\", \"oxygen cylinder (outside hospital)\", \"spacer\", \"spirometre\", \"nebulizer kit\", \"steam inhaler\", \"armsling\", \"thermometer\", \"cervical collar\", \"splint\", \"diabetic foot wear\", \"knee braces\", \"knee/shoulder immobilizer\", \"lumbo sacral belt\", \"nimbus/water/air bed charges\", \"ambulance collar\", \"ambulance equipment\", \"abdominal binder\", \"special nursing charges\", \"sugar free tablets\", \"creams, powders, lotions (non-prescribed)\", \"ECG electrodes\", \"gloves\", \"unspecified kits\", \"kidney tray\", \"mask\", \"ounce glass\", \"oxygen mask\", \"pelvic traction belt\", \"pan can\", \"trolly cover\", \"urometer, urine jug\", \"vasofix safety\"], \"added_new_keyword\": true}. Got: 2 validation errors for InsuranceMetadata\n", "penalties\n", " Input should be a valid string [type=string_type, input_value=['all benefits and premiu...verage without premium'], input_type=list]\n", " For further information visit https://errors.pydantic.dev/2.11/v/string_type\n", "notes\n", " Input should be a valid string [type=string_type, input_value=['National Parivar Medicl... Mediclaim Plus Policy'], input_type=list]\n", " For further information visit https://errors.pydantic.dev/2.11/v/string_type\n", "For troubleshooting, visit: https://python.langchain.com/docs/troubleshooting/errors/OUTPUT_PARSING_FAILURE \n", "doc number: 23\n", "\n", "⚠️ Parser failed on doc app\\uploads\\policy.pdf | error: Failed to parse InsuranceMetadata from completion {\"doc_id\": \"NICHLIP25039V032425\", \"doc_category\": \"Insurance\", \"doc_type\": \"Policy\", \"jurisdiction\": [\"India\", \"Gujarat\", \"Dadra and Nagar Haveli\", \"Daman and Diu\", \"Karnataka\", \"Madhya Pradesh\", \"Chhattisgarh\", \"Orissa\", \"Punjab\", \"Haryana\", \"Himachal Pradesh\", \"Jammu & Kashmir\", \"Ladakh\", \"Chandigarh\", \"Tamil Nadu\", \"Puducherry\", \"Karaikal\", \"Delhi\", \"Assam\", \"Meghalaya\", \"Manipur\", \"Mizoram\", \"Arunachal Pradesh\", \"Nagaland\", \"Tripura\", \"Andhra Pradesh\", \"Telangana\", \"Yanam\", \"Rajasthan\", \"Kerala\", \"Lakshadweep\", \"Mahe\", \"West Bengal\", \"Andaman and Nicobar Islands\", \"Sikkim\", \"Uttar Pradesh\", \"Mumbai Metropolitan Region\", \"Navi Mumbai\", \"Thane\", \"Uttarakhand\", \"Bihar\", \"Jharkhand\", \"Goa\", \"Maharashtra\", \"Palghar\", \"Raigad\"], \"effective_date\": null, \"expiry_date\": null, \"parties\": [\"National Insurance Company Ltd.\", \"Insurance Ombudsman\"], \"obligations\": null, \"penalties\": null, \"notes\": \"National Parivar Mediclaim Plus Policy\", \"policy_number\": \"NICHLIP25039V032425\", \"coverage_type\": null, \"premium_amount\": null, \"exclusions\": null, \"added_new_keyword\": true}. Got: 1 validation error for InsuranceMetadata\n", "jurisdiction\n", " Input should be a valid string [type=string_type, input_value=['India', 'Gujarat', 'Dad...a', 'Palghar', 'Raigad'], input_type=list]\n", " For further information visit https://errors.pydantic.dev/2.11/v/string_type\n", "For troubleshooting, visit: https://python.langchain.com/docs/troubleshooting/errors/OUTPUT_PARSING_FAILURE \n", "doc number: 24\n" ] } ], "source": [ "from langchain.text_splitter import RecursiveCharacterTextSplitter\n", "import json\n", "\n", "all_chunks = []\n", "splitter = RecursiveCharacterTextSplitter(chunk_size=800, chunk_overlap=100)\n", "for i, page in enumerate(doc): \n", " # reset per page\n", " try:\n", " text = page.get_text()\n", " except:\n", " text = page.page_content\n", " print(type(page))\n", " \n", " # text = self._clean_text(text)\n", "\n", " output_folder = \"app/data/\"\n", " filename = page.metadata['source'].replace(\".\",\"\").replace(\"\\\\\",\"\")+ \".json\"\n", " output_path = os.path.join(output_folder, filename)\n", "\n", " if i == 0:\n", " # First page → extract + create JSON\n", " Document_metadata = extractInsuranceMetadata(page, known_keywords={})\n", " extracted = Document_metadata.model_dump()\n", " normalized = normalize_dict_to_lists(extracted)\n", "\n", " with open(output_path, \"w\") as f:\n", " json.dump(normalized, f, indent=4)\n", " known_keywords = normalized\n", "\n", " else:\n", " # Next pages → load JSON and enforce consistency\n", " with open(output_path, \"r\") as f:\n", " known_keywords = json.load(f)\n", "\n", " Document_metadata = extractInsuranceMetadata(page, known_keywords)\n", "\n", " # check if there is new keyword is added or not during metadata extraction if yes then normalise(convert to dict) and then add new values into the keys exist\n", " if Document_metadata.added_new_keyword:\n", " new_data = normalize_dict_to_lists(\n", " Document_metadata.model_dump(exclude_none= True)\n", " )\n", " for key,vals in new_data.items():\n", " if isinstance(vals,list):\n", " known_keywords[key] = list(set(known_keywords.get(key,[]) + vals)) #get the existing key and add vals and convert into set then list and update the file.\n", " with open(output_path, \"w\") as f:\n", " json.dump(known_keywords, f, indent=4)\n", "\n", " # print(f\"Document_metadata type: {type(Document_metadata)}\")\n", " extracted_metadata = Document_metadata.model_dump(exclude_none=True)\n", " # print(f\"extracted_metadata type: {type(extracted_metadata)}\")\n", " print(f\"doc number: {i}\")\n", "\n", "\n", " if text.strip():\n", " uuid = str(uuid4())\n", " temp_doc = Document(\n", " page_content=text,\n", " metadata={\n", " **page.metadata,\n", " **extracted_metadata,\n", " \"page_no\": i,\n", " \"doc_id\": uuid,\n", " \"chunk_id\": f\"{uuid}_p{i}\",\n", " \"type\": \"text\"\n", " }\n", " )\n", " chunks = splitter.split_documents([temp_doc])\n", " all_chunks.extend(chunks)" ] }, { "cell_type": "code", "execution_count": null, "id": "1a38934a", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'appuploadspolicypdf.json'" ] }, "execution_count": 106, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\n", "all_chunks[0].metadata['source'].replace(\".\",\"\").replace(\"\\\\\",\"\") + \".json\"" ] }, { "cell_type": "code", "execution_count": null, "id": "2fb4e1c9", "metadata": {}, "outputs": [], "source": [ "## creating a helper function which updates the json keyword file \n", "\n", "import os, json \n", "\n", "def update_keyword" ] }, { "cell_type": "code", "execution_count": null, "id": "0c7c39ea", "metadata": {}, "outputs": [], "source": [ "## neww\n", "\n", "import json\n", "from langchain_core.exceptions import OutputParserException\n", "# wrap parser with fixer once\n", "# pydantic_parser = PydanticOutputParser(pydantic_object=InsuranceMetadata)\n", "# fixing_parser = OutputFixingParser.from_llm(llm=llm, parser=pydantic_parser) \n", "def extractInsuranceMetadata_query(document: Document, known_keywords: dict) -> InsuranceMetadata:\n", " parser = PydanticOutputParser(pydantic_object=InsuranceMetadata)\n", "\n", " schema_str = json.dumps(InsuranceMetadata.model_json_schema(), indent=2)\n", " keywords_str = json.dumps(known_keywords, indent=2)\n", "\n", " prompt = ChatPromptTemplate.from_messages([\n", " (\"system\", \"\"\"You are an information extraction system. \n", " Extract only the required metadata from the user query using the existing known keywords. \n", "\n", " ⚠️ Rules for consistency:\n", " - For exclusions and obligations, DO NOT copy full sentences. \n", " - Instead, extract only concise normalized keywords (2–5 words max each).\n", " - Use existing keywords if they already exist in the provided list.\n", " - Prefer to reuse existing keywords if they are semantically the same. \n", " - If you find a new keyword that is a **sub-type** or **more specific variant** of an existing one, keep both: \n", " *reuse the closest match from existing keywords*, and also add the new one. \n", " - In that case, set `added_new_keyword=true`.\n", " - Do not include raw paragraphs in the output.\n", " \n", " Schema you must follow:\n", " {schema}\n", "\n", " Existing Keywords:\n", " {keywords}\n", " \"\"\"),\n", " (\"human\", \"Text:\\n{document_content}\")\n", " ])\n", " chain = prompt | llm | parser\n", "\n", " try:\n", " result: InsuranceMetadata = chain.invoke({\n", " \"schema\": schema_str,\n", " \"keywords\": keywords_str,\n", " \"document_content\": document.page_content\n", " })\n", " return result\n", " except OutputParserException as e:\n", " print(f\"⚠️ Parser failed on doc {document.metadata.get('source')} | error: {e}\")\n", " return InsuranceMetadata(added_new_keyword=False) " ] }, { "cell_type": "code", "execution_count": null, "id": "f7d958a9", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Document_metadata type: \n", "extracted_metadata type: \n", "extracted_metadata type: {'doc_id': 'NICHLIP25039V032425', 'doc_category': 'Insurance', 'doc_type': 'Mediclaim Policy', 'jurisdiction': 'India', 'parties': ['National Insurance Company Ltd.', 'Proposer', 'Insured Persons'], 'obligations': 'Indemnify reasonable and customary charges for medically necessary treatment and hospitalization.', 'notes': 'Includes definitions for Accident, Age, AIDS, Any One Illness, AYUSH Day Care Centre, AYUSH Treatment, AYUSH Hospital, Break in policy.', 'policy_number': 'NICHLIP25039V032425', 'coverage_type': 'Health Insurance', 'exclusions': []}\n", "Number of chunks added for the page0 is 7\n", "Document_metadata type: \n", "extracted_metadata type: \n", "extracted_metadata type: {'doc_category': 'Insurance', 'doc_type': 'Policy', 'parties': ['Company', 'Insured'], 'obligations': 'Insured to bear co-payment percentage; Day Care Centres/Hospitals to maintain daily records.', 'policy_number': 'NICHLIP25039V032425', 'coverage_type': 'Mediclaim', 'exclusions': ['Out-patient treatment', 'Cosmetic surgery', 'Implants']}\n", "Number of chunks added for the page1 is 7\n", "Document_metadata type: \n", "extracted_metadata type: \n", "extracted_metadata type: {'doc_category': 'Insurance', 'doc_type': 'Mediclaim Policy', 'jurisdiction': 'India', 'parties': ['Insured', 'Insurer', 'TPA'], 'notes': 'Page 3 of 25', 'policy_number': 'NICHLIP25039V032425', 'coverage_type': 'Mediclaim', 'exclusions': ['Disease']}\n", "Number of chunks added for the page2 is 7\n", "Document_metadata type: \n", "extracted_metadata type: \n", "extracted_metadata type: {'doc_id': 'NICHLIP25039V032425', 'doc_category': 'Insurance', 'doc_type': 'Mediclaim Policy', 'jurisdiction': 'India', 'parties': ['Company', 'insured person', 'policyholders', 'insurer'], 'obligations': 'Intimating claim', 'notes': 'Definitions of insurance terms', 'coverage_type': 'Health', 'exclusions': ['Waiting Period', 'Pre-existing disease', 'Unproven treatment']}\n", "Number of chunks added for the page3 is 7\n", "Document_metadata type: \n", "extracted_metadata type: \n", "extracted_metadata type: {'doc_category': 'Insurance', 'doc_type': 'Policy doc', 'jurisdiction': 'India', 'parties': ['National Insurance Co. Ltd.', 'Insured person'], 'obligations': 'Indemnify medical expenses for in-patient, pre/post hospitalization, domiciliary hospitalization', 'notes': 'UIN: NICHLIP25039V032425', 'policy_number': 'NICHLIP25039V032425', 'coverage_type': 'Health Insurance', 'exclusions': ['Treatment < 3 days', 'Alternative treatment', 'Maternity', 'Infertility', 'Specific diseases']}\n", "Number of chunks added for the page4 is 6\n", "Document_metadata type: \n", "extracted_metadata type: \n", "extracted_metadata type: {'doc_id': 'NICHLIP25039V032425', 'doc_category': 'Insurance', 'doc_type': 'Policy', 'jurisdiction': 'India', 'parties': ['Insured Person', 'Company'], 'obligations': \"Indemnify medical expenses for various treatments: Day Care, AYUSH, Organ Donor, Hospital Cash, Ambulance, Air Ambulance, Medical Emergency Reunion, Doctor's Home Visit, Anti Rabies Vaccination, Maternity.\", 'notes': 'Policy name: National Parivar Mediclaim Plus Policy', 'policy_number': 'NICHLIP25039V032425', 'coverage_type': 'Health, Mediclaim', 'exclusions': ['Pre-hospitalization expenses', 'Post-hospitalization expenses', 'Organ acquisition costs', 'Experimental transplant', 'Donor treatment complications', 'Organ transportation']}\n", "Number of chunks added for the page5 is 7\n", "Document_metadata type: \n", "extracted_metadata type: \n", "extracted_metadata type: {'doc_id': 'NICHLIP25039V032425', 'doc_category': 'Insurance', 'doc_type': 'Mediclaim Policy', 'parties': ['National Insurance Co. Ltd.', 'Insured Person', 'New Born Baby', 'Surrogate Mother'], 'obligations': '24 months continuous cover, mid-term inclusion premium paid, legal affidavit for surrogacy, 24 months policy in force for infertility', 'notes': 'Ectopic pregnancy covered under in-patient treatment.', 'policy_number': 'NICHLIP25039V032425', 'coverage_type': 'Maternity, Infertility', 'exclusions': ['Age limits', 'Waiting period', 'More than two deliveries', 'Single policy period', 'Surrogate mother expenses', 'Ectopic pregnancy', 'Pre/post hospitalization (except natal)', 'Diagnostic tests (infertility)', 'Reversing sterilization', 'Sperm/egg/embryo storage', 'Donor expenses', 'Experimental treatments', 'Surrogate mother illness']}\n", "Number of chunks added for the page6 is 8\n", "Document_metadata type: \n", "extracted_metadata type: \n", "extracted_metadata type: {'doc_category': 'Insurance', 'doc_type': 'Policy', 'jurisdiction': 'India', 'parties': ['National Insurance Co. Ltd.', 'Insured'], 'obligations': 'Reimburse vaccinations, indemnify medical expenses for HIV/AIDS, mental illness, modern treatments, morbid obesity', 'notes': 'Definitions: Surrogate, Zygote Intra-Fallopian Transfer (ZIFT)', 'policy_number': 'NICHLIP25039V032425', 'coverage_type': 'Mediclaim, Health, Vaccinations, HIV/AIDS, Mental Illness, Modern Treatment, Morbid Obesity', 'exclusions': ['Psychological counselling', 'Cognitive therapy', 'Family therapy', 'Group therapy', 'Behavior therapy', 'Palliative therapy', 'Psychotherapy']}\n", "Number of chunks added for the page7 is 6\n", "Document_metadata type: \n", "extracted_metadata type: \n", "extracted_metadata type: {'doc_id': 'NICHLIP25039V032425', 'doc_category': 'Insurance', 'doc_type': 'Policy', 'parties': ['Company', 'Insured', 'Insured Person(s)'], 'obligations': 'Company indemnifies medical expenses, reinstates sum insured. Insured renews policy for benefits.', 'notes': 'Expenses not covered are in List-I of Annexure-II. Expenses subsumed into charges are in List-II, List-III, List-IV of Annexure-II.', 'policy_number': 'NICHLIP25039V032425', 'coverage_type': 'Mediclaim Plus', 'exclusions': ['Pre-Existing Diseases', 'Specified disease/procedure waiting period', 'Hypertension', 'Diabetes', 'Cardiac conditions', 'Benign ENT disorders', 'Tonsillectomy', 'Adenoidectomy']}\n", "Number of chunks added for the page8 is 7\n", "Document_metadata type: \n", "extracted_metadata type: \n", "extracted_metadata type: {'doc_category': 'Insurance', 'doc_type': 'Mediclaim Policy', 'jurisdiction': 'India', 'parties': ['National Insurance', 'Insured'], 'policy_number': 'NICHLIP25039V032425', 'coverage_type': 'Health Insurance', 'exclusions': ['2-year waiting period', '3-year waiting period', '30-day waiting period', 'Diagnostic evaluation', 'Rest/rehab/respite', 'Obesity surgery', 'Gender change', 'Cosmetic surgery', 'Hazardous sports']}\n", "Number of chunks added for the page9 is 6\n", "Document_metadata type: \n", "extracted_metadata type: \n", "extracted_metadata type: {'doc_id': 'NICHLIP25039V032425', 'doc_category': 'Insurance', 'doc_type': 'Mediclaim Policy', 'jurisdiction': 'India', 'parties': ['National Insurance Co. Ltd.', 'Insured Person', 'Policyholders'], 'policy_number': 'NICHLIP25039V032425', 'coverage_type': 'Health Insurance', 'exclusions': ['Breach of Law', 'Excluded Providers', 'Drug/Alcohol Abuse', 'Non Medical Admissions', 'Vitamins, Tonics', 'Refractive Error', 'Unproven Treatments', 'Hormone Replacement Therapy', 'General Debility', 'Self Inflicted Injury', 'Stem Cell Surgery', 'Circumcision', 'Vaccination', 'Massages, Steam Bath', 'Alternative Treatment', 'Dental treatment', 'Out Patient Department', 'Non Medically Necessary Stay', 'Spectacles, Contact Lens', 'Non Prescription Drug']}\n", "Number of chunks added for the page10 is 6\n", "Document_metadata type: \n", "extracted_metadata type: \n", "extracted_metadata type: {'doc_category': 'Insurance', 'doc_type': 'Mediclaim Policy', 'jurisdiction': 'India', 'parties': ['Insured person', 'Company', 'Policyholder'], 'obligations': 'Policyholder disclosure, Insured fulfill terms, Written communication, Report address changes', 'penalties': 'Policy void, Premium forfeited for misrepresentation', 'notes': 'UIN: NICHLIP25039V032425', 'policy_number': 'NICHLIP25039V032425', 'coverage_type': 'Health', 'exclusions': ['Unrelated treatment', 'Medical equipment', 'Personal comfort', 'Service charges', 'Home visit charges', 'War', 'Radioactivity', 'Outside India treatment']}\n", "Number of chunks added for the page11 is 7\n", "Document_metadata type: \n", "extracted_metadata type: \n", "extracted_metadata type: {'doc_id': 'NICHLIP25039V032425', 'doc_category': 'Insurance', 'doc_type': 'Mediclaim Policy', 'jurisdiction': 'India', 'parties': ['National Insurance Co. Ltd.', 'insured person', 'TPA'], 'obligations': 'Notify TPA/Company for claims within prescribed time limits (72 hrs planned, 24 hrs emergency, 24 hrs prior vaccination). Complete cashless request form. Verify/sign discharge papers. Submit original documents for reimbursement.', 'penalties': 'Denial of pre-authorization if relevant medical details not provided.', 'notes': 'Details claim notification procedures and required documents for cashless and reimbursement claims.', 'policy_number': 'NICHLIP25039V032425', 'coverage_type': 'Mediclaim', 'exclusions': ['Non-medical expenses', 'Inadmissible expenses']}\n", "Number of chunks added for the page12 is 8\n", "Document_metadata type: \n", "extracted_metadata type: \n", "extracted_metadata type: {'doc_id': 'NICHLIP25039V032425', 'doc_category': 'Insurance', 'doc_type': 'Mediclaim Policy', 'jurisdiction': 'India', 'parties': ['National Insurance Co. Ltd.', 'policyholder', 'insured person'], 'obligations': 'Submit documents within 15 days for various claims; Company to settle/reject claims within 15-45 days.', 'penalties': 'Company pays interest (2% above bank rate) for delayed claim payment.', 'notes': 'Includes details on claim submission time limits, claim settlement process, TPA services, waiver conditions, and co-payment rules based on geographical zones.', 'policy_number': 'NICHLIP25039V032425', 'coverage_type': 'Mediclaim Plus'}\n", "Number of chunks added for the page13 is 7\n", "Document_metadata type: \n", "extracted_metadata type: \n", "extracted_metadata type: {'doc_category': 'Insurance', 'doc_type': 'Policy', 'jurisdiction': 'India', 'parties': ['Insured', 'Company'], 'obligations': 'Pay claims, Settle claims, Repay fraud', 'penalties': 'Forfeiture, Repayment, Cancellation', 'notes': 'Co-payment options, Moratorium period, Multiple policies, Territorial limit', 'policy_number': 'NICHLIP25039V032425', 'coverage_type': 'Mediclaim, Critical illness, Outpatient, Diabetes, Hypertension', 'exclusions': ['Outside India', 'Fraud', 'Misrepresentation', 'Non-disclosure', 'Critical illness co-payment', 'Outpatient co-payment']}\n", "Number of chunks added for the page14 is 8\n", "Document_metadata type: \n", "extracted_metadata type: \n", "extracted_metadata type: {'doc_id': 'NICHLIP25039V032425', 'doc_category': 'Insurance', 'doc_type': 'Policy', 'jurisdiction': 'India', 'parties': ['Policyholder', 'Insurer', 'Insured Person'], 'obligations': 'Policyholder: cancellation notice, renewal premium, travel info, migration application. Insurer: premium refund, offer renewal.', 'penalties': 'No premium refund for claims. Claim abandoned if disclaimer not challenged.', 'coverage_type': 'Mediclaim, Health', 'exclusions': ['Claim admitted', 'Claim lodged', 'Benefit availed']}\n", "Number of chunks added for the page15 is 9\n", "Document_metadata type: \n", "extracted_metadata type: \n", "extracted_metadata type: {'doc_id': 'NICHLIP25039V032425', 'doc_category': 'Insurance', 'doc_type': 'Mediclaim Policy', 'jurisdiction': 'India', 'parties': ['Insured', 'Company', 'Policyholder'], 'obligations': 'Apply for portability, make nomination, communicate changes, intimate withdrawal, revise terms.', 'penalties': 'Deductions during free look', 'notes': 'Grievance redressal, helpline, senior citizen email', 'policy_number': 'NICHLIP25039V032425', 'coverage_type': 'Health', 'exclusions': ['Additional sum insured', 'Renewals', 'Porting/migrating']}\n", "Number of chunks added for the page16 is 8\n", "Document_metadata type: \n", "extracted_metadata type: \n", "extracted_metadata type: {'doc_id': 'NICHLIP25039V032425', 'doc_category': 'Insurance', 'doc_type': 'Mediclaim Policy', 'jurisdiction': 'India', 'parties': ['Company', 'insured'], 'obligations': 'pay additional premium', 'notes': 'Tax benefits under Section 80D', 'coverage_type': 'Mediclaim Plus', 'exclusions': ['Other than Allopathy', 'Cosmetic dental treatment']}\n", "Number of chunks added for the page17 is 5\n", "Document_metadata type: \n", "extracted_metadata type: \n", "extracted_metadata type: {'doc_id': 'NICHLIP25039V032425', 'doc_category': 'Insurance', 'doc_type': 'Policy', 'jurisdiction': 'India', 'parties': ['National Insurance Co. Ltd.', 'insured person'], 'obligations': 'Submit documents within thirty days for out-patient treatments. Claim must be supported by original bills, prescriptions, diagnostic reports.', 'notes': 'Entry age 18-65 years. Critical Illness cover renewable annually for lifetime. No tax benefit on Critical Illness premium.', 'policy_number': 'NICHLIP25039V032425', 'coverage_type': 'Mediclaim Plus, Critical Illness', 'exclusions': ['TIA', 'traumatic brain injury', 'vascular eye disease', 'carcinoma in situ', 'benign tumors', 'non-melanoma skin carcinoma (without metastases)']}\n", "Number of chunks added for the page18 is 6\n", "Document_metadata type: \n", "extracted_metadata type: \n", "extracted_metadata type: {'doc_category': 'Insurance', 'doc_type': 'Policy doc', 'parties': ['National Insurance Co. Ltd.', 'insured person'], 'obligations': 'Insured to intimate company in writing within fifteen days of diagnosis of illness.', 'notes': 'UIN: NICHLIP25039V032425', 'policy_number': 'NICHLIP25039V032425', 'coverage_type': 'Critical Illness', 'exclusions': ['Malignant melanoma', 'Prostate tumors', 'Thyroid cancers', 'Chronic leukaemia', 'Other stem-cell', 'Angioplasty, laser', 'Pre-existing illness', 'Illness within 90 days']}\n", "Number of chunks added for the page19 is 6\n", "Document_metadata type: \n", "extracted_metadata type: \n", "extracted_metadata type: {'doc_id': 'NICHLIP25039V032425', 'doc_category': 'Insurance', 'doc_type': 'Policy doc', 'jurisdiction': 'null', 'effective_date': 'null', 'expiry_date': 'null', 'parties': ['National Insurance Co. Ltd.', 'Insured'], 'obligations': 'Submit documents within sixty days from diagnosis. Claim supported by original documents.', 'penalties': 'null', 'notes': 'Benefit amount enhancement at renewal, company discretion.', 'policy_number': 'NICHLIP25039V032425', 'coverage_type': 'Critical illness', 'premium_amount': 'null', 'exclusions': ['further critical illness', 'already claimed illness']}\n", "Number of chunks added for the page20 is 2\n", "Document_metadata type: \n", "extracted_metadata type: \n", "extracted_metadata type: {'doc_id': 'NICHLIP25039V032425', 'doc_category': 'Insurance', 'doc_type': 'Policy', 'jurisdiction': 'India', 'parties': ['National Insurance Co. Ltd.', 'Insured'], 'obligations': 'Declare PEDs, Waiting periods, Continuous coverage', 'notes': 'Multi-plan, Tiered benefits, Discounts, Add-ons', 'policy_number': 'NICHLIP25039V032425', 'coverage_type': 'Health, Mediclaim', 'exclusions': ['Air Ambulance', 'Medical Reunion']}\n", "Number of chunks added for the page21 is 8\n", "Document_metadata type: \n", "extracted_metadata type: \n", "extracted_metadata type: {'doc_category': 'Insurance', 'doc_type': 'Policy', 'jurisdiction': 'India', 'parties': ['National Insurance Co. Ltd.', 'Insured'], 'notes': 'Annexure I: Vaccinations for Children', 'policy_number': 'NICHLIP25039V032425', 'coverage_type': 'Mediclaim, Vaccinations'}\n", "Number of chunks added for the page22 is 2\n", "Document_metadata type: \n", "extracted_metadata type: \n", "extracted_metadata type: {'doc_category': 'Insurance', 'doc_type': 'Policy doc', 'jurisdiction': 'India', 'parties': ['National Insurance Co. Ltd.', 'Insured Family'], 'policy_number': 'NICHLIP25039V032425', 'coverage_type': 'Mediclaim Plus', 'exclusions': ['Baby food', 'Baby utilities', 'Beauty services', 'Belts/braces', 'Buds', 'Cold/hot pack', 'Carry bags', 'Email/internet charges', 'Food charges', 'Leggings', 'Laundry charges', 'Mineral water', 'Sanitary pad', 'Telephone charges', 'Guest services', 'Crepe bandage', 'Diaper', 'Eyelet collar', 'Slings', 'Blood grouping', 'Service charges', 'Television charges', 'Surcharges', 'Attendant charges', 'Extra diet', 'Birth certificate', 'Certificate charges', 'Courier charges', 'Conveyance charges', 'Medical certificate', 'Medical records', 'Photocopies charges', 'Mortuary charges', 'Walking aids', 'Oxygen cylinder', 'Spacer', 'Spirometre', 'Nebulizer kit', 'Steam inhaler', 'Armsling', 'Thermometer', 'Cervical collar', 'Splint', 'Diabetic footwear', 'Knee braces', 'Knee immobilizer', 'Lumbo sacral belt', 'Nimbus bed', 'Ambulance collar', 'Ambulance equipment', 'Abdominal binder', 'Private nurses', 'Sugar free tablets', 'Creams powders lotions', 'ECG electrodes', 'Gloves', 'Nebulisation kit', 'Any kit', 'Kidney tray', 'Mask', 'Ounce glass', 'Oxygen mask', 'Pelvic traction belt', 'Pan can', 'Trolly cover', 'Urometer, urine jug', 'Vasofix safety']}\n", "Number of chunks added for the page23 is 6\n", "Document_metadata type: \n", "extracted_metadata type: \n", "extracted_metadata type: {'doc_id': 'NICHLIP25039V032425', 'doc_category': 'Insurance', 'doc_type': 'Policy', 'parties': ['National Insurance Co. Ltd.', 'Insured'], 'notes': 'Annexure III: Contact details of Insurance Ombudsman offices.', 'policy_number': 'NICHLIP25039V032425', 'coverage_type': 'Mediclaim Plus'}\n", "Number of chunks added for the page24 is 8\n" ] } ], "source": [ "# ## creating chunks\n", "# from langchain_core.documents import Document\n", "# from langchain.text_splitter import RecursiveCharacterTextSplitter\n", "# from langchain.prompts import PromptTemplate\n", "# from uuid import uuid4\n", "# from typing import List, Dict\n", "\n", "\n", "# class splitting_text:\n", "\n", "# def _clean_text(self, text:str)-> str: \n", "# \"\"\"Clean extracted page content\"\"\"\n", "# # remove excessive whitespace \n", "# text = \" \".join(text.split())\n", "# return text\n", "\n", "# def text_splitting(self, doc_content: List[Document]) -> List[Document]:\n", "# splitter = RecursiveCharacterTextSplitter(chunk_size=800, chunk_overlap=100)\n", "# all_chunks = []\n", "\n", "# for i, page in enumerate(doc_content): \n", "# # reset per page\n", "# try:\n", "# text = page.get_text()\n", "# except:\n", "# text = page.page_content\n", " \n", "# text = self._clean_text(text)\n", "# Document_metadata = extractInsuranceMetadata(page)\n", "# print(f\"Document_metadata type: {type(Document_metadata)}\")\n", "# extracted_metadata = Document_metadata.model_dump(exclude_none=True)\n", "# print(f\"extracted_metadata type: {type(extracted_metadata)}\")\n", "# print(f\"extracted_metadata type: {extracted_metadata}\")\n", " \n", "# if text.strip():\n", "# uuid = str(uuid4())\n", "# temp_doc = Document(\n", "# page_content=text,\n", "# metadata={\n", "# **page.metadata,\n", "# **extracted_metadata,\n", "# \"page_no\": i,\n", "# \"doc_id\": uuid,\n", "# \"chunk_id\": f\"{uuid}_p{i}\",\n", "# \"type\": \"text\"\n", "# }\n", "# )\n", "# chunks = splitter.split_documents([temp_doc])\n", "# print(f\"Number of chunks added for the page{i} is {len(chunks)}\")\n", "# all_chunks.extend(chunks)\n", "\n", "# return all_chunks\n", "\n", "# objec2 = splitting_text()\n", "# chunk= objec2.text_splitting(doc)" ] }, { "cell_type": "code", "execution_count": 39, "id": "505eaeaa", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'producer': 'Microsoft® Word LTSC',\n", " 'creator': 'Microsoft® Word LTSC',\n", " 'creationdate': '2025-02-11T11:39:19+05:30',\n", " 'source': 'app\\\\uploads\\\\policy.pdf',\n", " 'file_path': 'app\\\\uploads\\\\policy.pdf',\n", " 'total_pages': 25,\n", " 'format': 'PDF 1.7',\n", " 'title': 'National Parivar Mediclaim Plus Policy (NPMPP)',\n", " 'author': 'Avishek Banerjee',\n", " 'subject': '',\n", " 'keywords': '',\n", " 'moddate': '2025-02-11T11:39:19+05:30',\n", " 'trapped': '',\n", " 'modDate': \"D:20250211113919+05'30'\",\n", " 'creationDate': \"D:20250211113919+05'30'\",\n", " 'page': 0,\n", " 'doc_id': '55395f6d-5e08-4e02-965d-9122f1d1f692',\n", " 'doc_category': 'Insurance',\n", " 'doc_type': 'Mediclaim Policy',\n", " 'jurisdiction': 'India',\n", " 'parties': ['National Insurance Company Ltd.', 'Proposer', 'Insured Persons'],\n", " 'obligations': 'Indemnify reasonable and customary charges for medically necessary treatment and hospitalization.',\n", " 'notes': 'Includes definitions for Accident, Age, AIDS, Any One Illness, AYUSH Day Care Centre, AYUSH Treatment, AYUSH Hospital, Break in policy.',\n", " 'policy_number': 'NICHLIP25039V032425',\n", " 'coverage_type': 'Health Insurance',\n", " 'exclusions': [],\n", " 'page_no': 0,\n", " 'chunk_id': '55395f6d-5e08-4e02-965d-9122f1d1f692_p0',\n", " 'type': 'text'}" ] }, "execution_count": 39, "metadata": {}, "output_type": "execute_result" } ], "source": [ "chunk[1].metadata" ] }, { "cell_type": "markdown", "id": "03e75f38", "metadata": {}, "source": [ "Creating a vectore store" ] }, { "cell_type": "code", "execution_count": 182, "id": "fedfe95f", "metadata": {}, "outputs": [], "source": [ "import os\n", "from dotenv import load_dotenv\n", "from pinecone import Pinecone\n", "from pinecone import ServerlessSpec\n", "from langchain_pinecone import PineconeVectorStore\n", "from datetime import datetime\n", "from uuid import uuid4\n", "\n", "current_time = datetime.now()\n", "\n", "def create_vectore_store(text_chunks:list, embedding_model):\n", " load_dotenv()\n", " pinecone_key = os.getenv(\"PINECONE_API_KEY\")\n", " pc = Pinecone(api_key=pinecone_key)\n", " # pc._vector_api.api_client.pool_threads = 1 \n", " time_string = current_time.strftime(\"%Y-%m-%d-%H-%M\")\n", " index_name = f\"rag-project\"\n", " if not pc.has_index(index_name):\n", " pc.create_index(\n", " name = index_name,\n", " dimension=1024,\n", " metric=\"cosine\",\n", " spec = ServerlessSpec(cloud=\"aws\", region=\"us-east-1\")\n", " )\n", "\n", " index = pc.Index(index_name)\n", " # model_loader = ModelLoader(model_provider=\"openai\")\n", " # embedding_model = model_loader.load_llm()\n", " uuids = [str(uuid4()) for _ in range(len(text_chunks)) ]\n", " vector_store = PineconeVectorStore(index = index, embedding=embedding_model)\n", " name_space = f\"rag-project{time_string}\"\n", " vector_store.add_documents(documents=text_chunks, ids = uuids,namespace = name_space )\n", "\n", " return index, name_space\n", "\n", "\n" ] }, { "cell_type": "code", "execution_count": 184, "id": "b691efc8", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Xet Storage is enabled for this repo, but the 'hf_xet' package is not installed. Falling back to regular HTTP download. For better performance, install the package with: `pip install huggingface_hub[hf_xet]` or `pip install hf_xet`\n" ] } ], "source": [ "# 1. Import the HuggingFaceEmbeddings class\n", "from langchain_huggingface import HuggingFaceEmbeddings\n", "from dotenv import load_dotenv\n", "load_dotenv()\n", "# 2. Define the model name\n", "# \"all-MiniLM-L6-v2\" is a popular and efficient embedding model.\n", "# model_name = \"sentence-transformers/all-MiniLM-L6-v2\"\n", "model_name = \"mixedbread-ai/mxbai-embed-large-v1\"\n", "\n", "# 3. Initialize the embedding model\n", "# This will automatically download and load the model from Hugging Face Hub.\n", "api_key = os.getenv(\"HF_TOKEN\")\n", "embeddings = HuggingFaceEmbeddings(model_name=model_name)\n", "\n", "\n", "# 5. Embed a query string\n", "query = \"What is LangChain?\"\n", "query_result = embeddings.embed_query(query)\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "id": "73f679a7", "metadata": {}, "outputs": [], "source": [ "# from langchain_google_genai import GoogleGenerativeAIEmbeddings\n", "# from dotenv import load_dotenv\n", "# load_dotenv()\n", "# api_key = os.getenv(\"GEMINI_API_KEY\")\n", "# # If GOOGLE_API_KEY environment variable is set, no argument needed\n", "# embeddings = GoogleGenerativeAIEmbeddings(model=\"gemini-embedding-001\", google_api_key = api_key,output_dimensionality=1536)\n", "\n", "# # Alternatively, pass the API key directly\n", "# # embeddings = GoogleGenerativeAIEmbeddings(google_api_key=\"your_api_key_here\", model=\"models/embedding-001\")" ] }, { "cell_type": "code", "execution_count": 187, "id": "f07cf86c", "metadata": {}, "outputs": [], "source": [ "# from app.utils.model_loader import ModelLoader\n", "\n", "# model_loader = ModelLoader(model_provider=\"openai\")\n", "# embedding_llm = model_loader.load_llm()\n", "\n", "index, namespace = create_vectore_store(all_chunks,embeddings)" ] }, { "cell_type": "code", "execution_count": null, "id": "bfbba953", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 192, "id": "5e2ce8c1", "metadata": {}, "outputs": [], "source": [ "query = \"Under what circumstances will the National Insurance Company Ltd. indemnify the insured or hospital for medical expenses?\"" ] }, { "cell_type": "code", "execution_count": 189, "id": "d91ee329", "metadata": {}, "outputs": [], "source": [ "def format_metadata_for_pinecone(metadata: dict) -> dict:\n", " \"\"\"\n", " Convert list fields in metadata to Pinecone's valid filter format using $in.\n", " \"\"\"\n", " formatted = {}\n", " for key, value in metadata.items():\n", " if isinstance(value, list):\n", " if len(value) > 0:\n", " formatted[key] = {\"$in\": value}\n", " else:\n", " formatted[key] = value\n", " return formatted\n" ] }, { "cell_type": "code", "execution_count": 194, "id": "930cdd8f", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "doc_id=None doc_category=['Insurance'] doc_type=['Policy'] jurisdiction=['India'] effective_date=None expiry_date=None parties=['National Insurance Company Ltd.', 'Insured', 'Hospital'] obligations=['indemnify medical treatment charges'] penalties=None notes=None policy_number=None coverage_type=None premium_amount=None exclusions=None added_new_keyword=False\n", "Document content: Under what circumstances will the National Insurance Company Ltd. indemnify the insured or hospital for medical expenses?\n", "Document with metadata content: Under what circumstances will the National Insurance Company Ltd. indemnify the insured or hospital for medical expenses?\n", "Document metadata: {'doc_category': {'$in': ['Insurance']}, 'doc_type': {'$in': ['Policy']}, 'jurisdiction': {'$in': ['India']}, 'parties': {'$in': ['National Insurance Company Ltd.', 'Insured', 'Hospital']}, 'obligations': {'$in': ['indemnify medical treatment charges']}, 'added_new_keyword': False}\n" ] } ], "source": [ "# Create a Document object from the string\n", "langchain_doc = Document(page_content=query)\n", "\n", "# Call the embedding method directly, outside of the chain\n", "embedding = embeddings.embed_query(query)\n", "output_path = r\"app\\data\\appuploadspolicypdf.json\"\n", "with open(output_path, \"r\") as f:\n", " known_keywords = json.load(f)\n", "# Now, call the metadata extraction function, which internally uses a valid LCEL chain\n", "metadata = extractInsuranceMetadata_query(langchain_doc,known_keywords=known_keywords )\n", "dict_metadata = metadata.model_dump(exclude_none=True)# Convert the Pydantic model to a dictionary\n", "formated_metadata = format_metadata_for_pinecone(dict_metadata)\n", "print(metadata)\n", "\n", "# Create the final document with the extracted metadata\n", "langchain_doc_with_metadata = Document(\n", " page_content=langchain_doc.page_content,\n", " metadata=formated_metadata \n", ")\n", "\n", "# Access the content and metadata\n", "print(f\"Document content: {langchain_doc.page_content}\")\n", "print(f\"Document with metadata content: {langchain_doc_with_metadata.page_content}\")\n", "print(f\"Document metadata: {langchain_doc_with_metadata.metadata}\")\n" ] }, { "cell_type": "code", "execution_count": 199, "id": "3c2686ad", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'matches': [{'id': '29369574-c3ce-4fcd-8145-93438372bd06',\n", " 'metadata': {'added_new_keyword': True,\n", " 'author': 'Avishek Banerjee',\n", " 'chunk_id': '2bd32cef-2cf1-45b1-8118-11980584d242_p0',\n", " 'coverage_type': ['Mediclaim',\n", " 'Hospitalisation',\n", " 'In-Patient Care',\n", " 'Day Care Treatment',\n", " 'Domiciliary Hospitalisation',\n", " 'AYUSH Treatment'],\n", " 'creationDate': \"D:20250211113919+05'30'\",\n", " 'creationdate': '2025-02-11T11:39:19+05:30',\n", " 'creator': 'Microsoft® Word LTSC',\n", " 'doc_category': 'Insurance',\n", " 'doc_id': '2bd32cef-2cf1-45b1-8118-11980584d242',\n", " 'doc_type': 'Policy',\n", " 'file_path': 'app\\\\uploads\\\\policy.pdf',\n", " 'format': 'PDF 1.7',\n", " 'jurisdiction': 'India',\n", " 'keywords': '',\n", " 'modDate': \"D:20250211113919+05'30'\",\n", " 'moddate': '2025-02-11T11:39:19+05:30',\n", " 'notes': 'CIN - U10200WB1906GOI001713, IRDAI Regn. '\n", " 'No. – 58',\n", " 'obligations': ['indemnify medical treatment '\n", " 'charges'],\n", " 'page': 0.0,\n", " 'page_no': 0.0,\n", " 'parties': ['National Insurance Company Ltd.',\n", " 'Proposer',\n", " 'Insured Persons'],\n", " 'policy_number': 'NICHLIP25039V032425',\n", " 'producer': 'Microsoft® Word LTSC',\n", " 'source': 'app\\\\uploads\\\\policy.pdf',\n", " 'subject': '',\n", " 'text': '(hereinafter called the Insured Persons) '\n", " 'and has paid the premium as consideration '\n", " 'for such insurance. \\n'\n", " ' \\n'\n", " '1 PREAMBLE \\n'\n", " 'The Company undertakes that if during the '\n", " 'Policy Period, any Insured Person shall '\n", " 'suffer any illness or disease (hereinafter '\n", " 'called \\n'\n", " 'Illness) or sustain any bodily injury due '\n", " 'to an Accident (hereinafter called Injury) '\n", " 'requiring Hospitalisation of such '\n", " 'Insured \\n'\n", " 'Person(s) for In-Patient Care at any '\n", " 'hospital/nursing home (hereinafter called '\n", " 'Hospital) or for Day Care Treatment at any '\n", " 'Day \\n'\n", " 'Care Center or to undergo treatment under '\n", " 'Domiciliary Hospitalisation, following the '\n", " 'Medical Advice of a duly qualified '\n", " 'Medical \\n'\n", " 'Practitioner, the Company shall indemnify '\n", " 'the Hospital or the Insured, Reasonable '\n", " 'and Customary Charges incurred for '\n", " 'Medically',\n", " 'title': 'National Parivar Mediclaim Plus Policy '\n", " '(NPMPP)',\n", " 'total_pages': 25.0,\n", " 'trapped': '',\n", " 'type': 'text'},\n", " 'score': 0.834982455,\n", " 'values': []},\n", " {'id': '90070302-df96-4485-9a5a-d0382af6e2c4',\n", " 'metadata': {'added_new_keyword': True,\n", " 'author': 'Avishek Banerjee',\n", " 'chunk_id': 'f1fd648d-c977-4c21-acce-21491846bc32_p7',\n", " 'coverage_type': ['ZIFT',\n", " 'Domiciliary Hospitalisation',\n", " 'In-Patient Care',\n", " 'Day Care Treatment',\n", " 'Vaccination for Children',\n", " 'HIV/ AIDS Cover',\n", " 'Pre Hospitalisation Expenses',\n", " 'Post Hospitalisation Expenses',\n", " 'Mental Illness Cover',\n", " 'Mental Illnesses',\n", " 'Modern Treatments',\n", " 'Day Care Procedure',\n", " 'UAE & HIFU',\n", " 'Balloon Sinuplasty',\n", " 'Deep Brain Stimulation',\n", " 'Oral Chemotherapy',\n", " 'Immunotherapy',\n", " 'Intravitreal injections',\n", " 'Robotic Surgery',\n", " 'Stereotactic Radio surgeries',\n", " 'Bronchial Thermoplasty',\n", " 'Vaporization of the prostrate',\n", " 'IONM',\n", " 'Stem cell therapy',\n", " 'Morbid Obesity Treatment',\n", " 'surgical treatment of obesity',\n", " 'Obesity-related cardiomyopathy',\n", " 'Coronary heart disease',\n", " 'Severe Sleep Apnea',\n", " 'Uncontrolled Type 2 Diabetes'],\n", " 'creationDate': \"D:20250211113919+05'30'\",\n", " 'creationdate': '2025-02-11T11:39:19+05:30',\n", " 'creator': 'Microsoft® Word LTSC',\n", " 'doc_category': 'Insurance',\n", " 'doc_id': 'f1fd648d-c977-4c21-acce-21491846bc32',\n", " 'doc_type': 'Policy',\n", " 'exclusions': ['Psychological counselling',\n", " 'cognitive therapy',\n", " 'family therapy',\n", " 'group therapy',\n", " 'behavior therapy',\n", " 'palliative therapy',\n", " 'psychotherapy without '\n", " 'hospitalisation',\n", " 'incidental charges (Oral '\n", " 'Chemotherapy)',\n", " 'investigations (Oral Chemotherapy)',\n", " 'consultation charges (Oral '\n", " 'Chemotherapy)'],\n", " 'file_path': 'app\\\\uploads\\\\policy.pdf',\n", " 'format': 'PDF 1.7',\n", " 'jurisdiction': 'India',\n", " 'keywords': '',\n", " 'modDate': \"D:20250211113919+05'30'\",\n", " 'moddate': '2025-02-11T11:39:19+05:30',\n", " 'notes': 'National Parivar Mediclaim Plus Policy',\n", " 'obligations': ['children covered by Policy',\n", " 'treatment at Hospital with '\n", " 'specific department for Mental '\n", " 'Illness',\n", " 'treatment under qualified Medical '\n", " 'Practitioner/Psychiatrist',\n", " 'medically indicated Modern '\n", " 'Treatments',\n", " 'limit 25% Sum Insured for Modern '\n", " 'Treatment',\n", " 'Waiting Period of three years '\n", " '(obesity treatment)',\n", " 'treatment upon Medical '\n", " 'Practitioner advice (obesity)',\n", " 'surgery/Procedure supported by '\n", " 'clinical protocols (obesity)',\n", " 'Insured Person 18 years or older '\n", " '(obesity)',\n", " 'BMI greater than or equal to 40',\n", " 'BMI greater than or equal to 35 '\n", " 'with co-morbidities',\n", " 'failure of less invasive weight '\n", " 'loss methods'],\n", " 'page': 7.0,\n", " 'page_no': 7.0,\n", " 'parties': ['National Insurance Company Ltd.',\n", " 'Insured',\n", " 'Hospital',\n", " 'Medical Practitioner',\n", " 'children',\n", " 'Psychiatrist'],\n", " 'policy_number': 'NICHLIP25039V032425',\n", " 'producer': 'Microsoft® Word LTSC',\n", " 'source': 'app\\\\uploads\\\\policy.pdf',\n", " 'subject': '',\n", " 'text': 'are covered by the Policy. Hospitalisation '\n", " 'is not required for this benefit. \\n'\n", " ' \\n'\n", " '3.1.17 HIV/ AIDS Cover \\n'\n", " 'The Company shall indemnify the Hospital '\n", " 'or the Insured the Medical Expenses '\n", " '(including Pre and Post Hospitalisation '\n", " 'Expenses) \\n'\n", " 'related to following stages of HIV '\n", " 'infection: \\n'\n", " 'i. \\n'\n", " 'Acute HIV infection – acute flu-like '\n", " 'symptoms \\n'\n", " 'ii. Clinical latency – usually '\n", " 'asymptomatic or mild symptoms \\n'\n", " 'iii. AIDS – full-blown disease; CD4 < '\n", " '200 \\n'\n", " ' \\n'\n", " '3.1.18 Mental Illness Cover \\n'\n", " 'The Company shall indemnify the Hospital '\n", " 'or the Insured the Medical Expenses '\n", " '(including Pre and Post Hospitalisation '\n", " 'Expenses) \\n'\n", " 'related to Mental Illnesses, provided the '\n", " 'treatment shall be undertaken at a '\n", " 'Hospital with a specific department for '\n", " 'Mental Illness,',\n", " 'title': 'National Parivar Mediclaim Plus Policy '\n", " '(NPMPP)',\n", " 'total_pages': 25.0,\n", " 'trapped': '',\n", " 'type': 'text'},\n", " 'score': 0.738199532,\n", " 'values': []},\n", " {'id': '16e47fd3-1ae5-4506-8f82-bd3d571f9e35',\n", " 'metadata': {'added_new_keyword': True,\n", " 'author': 'Avishek Banerjee',\n", " 'chunk_id': 'c3c700ff-f23b-4b20-90ac-a6169defc622_p1',\n", " 'coverage_type': ['Mediclaim',\n", " 'Hospitalisation',\n", " 'In-Patient Care',\n", " 'Day Care Treatment',\n", " 'Domiciliary Hospitalisation',\n", " 'AYUSH Treatment',\n", " 'Dental Treatment'],\n", " 'creationDate': \"D:20250211113919+05'30'\",\n", " 'creationdate': '2025-02-11T11:39:19+05:30',\n", " 'creator': 'Microsoft® Word LTSC',\n", " 'doc_category': 'Insurance',\n", " 'doc_id': 'c3c700ff-f23b-4b20-90ac-a6169defc622',\n", " 'doc_type': 'Policy',\n", " 'exclusions': ['out-patient treatment',\n", " 'cosmetic surgery',\n", " 'implants'],\n", " 'file_path': 'app\\\\uploads\\\\policy.pdf',\n", " 'format': 'PDF 1.7',\n", " 'jurisdiction': 'India',\n", " 'keywords': '',\n", " 'modDate': \"D:20250211113919+05'30'\",\n", " 'moddate': '2025-02-11T11:39:19+05:30',\n", " 'notes': 'CIN - U10200WB1906GOI001713, IRDAI Regn. '\n", " 'No. – 58, National Parivar Mediclaim Plus '\n", " 'Policy',\n", " 'obligations': ['indemnify medical treatment '\n", " 'charges',\n", " 'bear co-payment',\n", " 'maintain patient records',\n", " 'make records accessible to company',\n", " 'pay premium for renewal'],\n", " 'page': 1.0,\n", " 'page_no': 1.0,\n", " 'parties': ['National Insurance Company Ltd.',\n", " 'Proposer',\n", " 'Insured Persons',\n", " 'Insured',\n", " 'Network Provider',\n", " 'Non Network Provider'],\n", " 'penalties': 'no coverage without premium',\n", " 'policy_number': 'NICHLIP25039V032425',\n", " 'producer': 'Microsoft® Word LTSC',\n", " 'source': 'app\\\\uploads\\\\policy.pdf',\n", " 'subject': '',\n", " 'text': 'National Insurance Co. Ltd. \\n'\n", " 'Premises No. 18-0374, Plot no. CBD-81, \\n'\n", " 'New Town, Kolkata - 700156 \\n'\n", " 'Page 2 of 25 \\n'\n", " 'National Parivar Mediclaim Plus Policy \\n'\n", " 'UIN: NICHLIP25039V032425 \\n'\n", " ' \\n'\n", " '2.9 Cashless Facility means a facility '\n", " 'extended by the Company to the Insured '\n", " 'where the payments of the costs of '\n", " 'treatment \\n'\n", " 'undergone by the Insured in accordance '\n", " 'with the Policy terms and conditions, are '\n", " 'directly made to the Network Provider or '\n", " 'a \\n'\n", " 'Non Network Provider to the extent '\n", " 'pre-authorization approved. \\n'\n", " ' \\n'\n", " '2.10 Condition Precedent means a Policy '\n", " 'term or condition upon which the Company’s '\n", " 'liability by the Policy is conditional '\n", " 'upon. \\n'\n", " ' \\n'\n", " '2.11 Contract means prospectus, proposal, '\n", " 'Policy, and the policy schedule. Any '\n", " 'alteration with the mutual consent of the '\n", " 'insured',\n", " 'title': 'National Parivar Mediclaim Plus Policy '\n", " '(NPMPP)',\n", " 'total_pages': 25.0,\n", " 'trapped': '',\n", " 'type': 'text'},\n", " 'score': 0.721536279,\n", " 'values': []}],\n", " 'namespace': 'rag-project2025-08-25-22-55',\n", " 'usage': {'read_units': 1}}" ] }, "execution_count": 199, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Remove obligations & exclusions from metadata before using as a filter\n", "filter_metadata = {\n", " k: v for k, v in langchain_doc_with_metadata.metadata.items()\n", " if k not in [\"obligations\", \"exclusions\", \"notes\",\"added_new_keyword\"]\n", "}\n", "\n", "res = index.query(\n", " vector= embedding,\n", " top_k =3 ,\n", " include_metadata = True, \n", " include_values = False, \n", " filter = filter_metadata,\n", " namespace = namespace\n", ")\n", "res" ] }, { "cell_type": "code", "execution_count": 200, "id": "fd6ade64", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'doc_category': {'$in': ['Insurance']},\n", " 'doc_type': {'$in': ['Policy']},\n", " 'jurisdiction': {'$in': ['India']},\n", " 'parties': {'$in': ['National Insurance Company Ltd.',\n", " 'Insured',\n", " 'Hospital']}}" ] }, "execution_count": 200, "metadata": {}, "output_type": "execute_result" } ], "source": [ "filter_metadata" ] }, { "cell_type": "code", "execution_count": 1, "id": "8ae23fd3", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "c:\\code\\Bajaj HackRx\\Rag_app\\.venv\\Lib\\site-packages\\tqdm\\auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", " from .autonotebook import tqdm as notebook_tqdm\n" ] } ], "source": [ "from typing import List \n", "from app.utils.model_loader import ModelLoader\n", "from app.ingestion.file_loader import FileLoader\n", "from app.ingestion.text_splitter import splitting_text\n", "from app.retrieval.retriever import Retriever\n", "from app.embedding.embeder import QueryEmbedding\n", "from app.embedding.vectore_store import VectorStore\n", "from app.metadata_extraction.metadata_ext import MetadataExtractor\n", "from app.utils.metadata_utils import MetadataService\n", "# from app.utils.document_op import DocumentOperation\n", "\n", "class RAGService: \n", " def __init__(self):\n", " self._init_models()\n", " self.Docuement_Type = None \n", " self.Pinecone_index = None\n", " self.Document_path = None\n", " self.Document_Type = None\n", " self.DocumentTypeScheme = None\n", " self.url = None\n", " self.chunks = None\n", " self.vector_store = None\n", " self.index = None\n", " self.namespace = None\n", " self.retriever = None\n", " self.metadataservice = MetadataService()\n", " \n", "\n", " def _init_models(self):\n", " \"\"\"Initialize LLM and embedding Models\"\"\"\n", " self.model_loader = ModelLoader(model_provider=\"gemini\")\n", " self.llm = self.model_loader.load_llm()\n", " self.model_loader = ModelLoader(model_provider=\"huggingface\")\n", " self.embedding_model = self.model_loader.load_llm()\n", " \n", "\n", "\n", " def load_and_split_document(self, type:str, path:str= None, url:str = None):\n", " \"\"\"Load and chunk document from local path or URL\"\"\"\n", " file_loader = FileLoader(llm = self.llm)\n", " if type == \"pdf\":\n", " if path:\n", " doc = file_loader.load_pdf(path)\n", " elif url:\n", " doc = file_loader.load_documents_from_url(url)\n", " else:\n", " raise ValueError(\"Either path or url must be provided for PDF.\")\n", " elif type == \"word\":\n", " if path:\n", " doc = file_loader.load_word_document(path)\n", " elif url:\n", " raise ValueError(\"URL loading not supported for Word documents.\")\n", " else:\n", " raise ValueError(\"Path must be provided for Word document.\")\n", " else:\n", " raise ValueError(\"Unsupported document type. Use 'pdf' or 'word'.\")\n", " \n", " self.DocumentTypeScheme = file_loader.detect_document_type(doc[0:2])\n", " self.Document_Type = self.metadataservice.Return_document_model(self.DocumentTypeScheme)\n", " self.splitter = splitting_text(documentTypeSchema=self.Document_Type, llm=self.llm)\n", " self.chunks = self.splitter.text_splitting(doc)\n", " print(f\"Total chunks created: {len(self.chunks)}\")\n", "\n", " def create_query_embedding(self, query: str):\n", "\n", " self.query_embedder = QueryEmbedding(query=query, embedding_model=self.embedding_model)\n", " self.query_embedding = self.query_embedder.get_embedding()\n", " langchain_doc = Document(page_content=query)\n", " self.metadataExtractor = MetadataExtractor(llm=self.llm)\n", " with open(self.splitter.Keywordsfile_path, \"r\") as f:\n", " known_keywords = json.load(f)\n", " self.query_metadata = self.metadataExtractor.extractMetadata_query(self.Document_Type,langchain_doc, known_keywords = known_keywords)\n", "\n", " def create_vector_store(self):\n", " self.vector_store = VectorStore(self.chunks, self.embedding_model)\n", " self.index, self.namespace = self.vector_store.create_vectorestore()\n", "\n", " def retrive_documents(self):\n", " self.retriever = Retriever(self.index,self.query_embedding, self.embedding_model,self.query_metadata, self.namespace)\n", " self.result = self.retriever.retrieval_from_pinecone_vectoreStore()\n", " self.result = self.result\n", "\n", " def answer_query(self, raw_query:str) -> str:\n", " \"\"\"Answer user query using retrieved documents and LLM\"\"\"\n", " top_clauses = self.result\n", " if not top_clauses:\n", " return \"No relevant information found in the document.\"\n", "\n", " context_clauses = [\n", " f'{i+1}. (DocID: {c.doc_id}, Page: {c.page}) \"{c.text[:200]}...\"' \n", " for i, c in enumerate(top_clauses)\n", " ]\n", "\n", " prompt = f\"\"\"\n", " You are a legal/insurance domain expert and policy analyst. \n", " Use the following extracted clauses from policy documents to answer the question. \n", " If you can't find the answer, say \"I don't know\".\n", " Context clauses:\n", " {\"\".join(context_clauses)}\n", " Question: {raw_query}\n", " \"\"\"\n", " response = self.llm.invoke(prompt)\n", " return response\n", " " ] }, { "cell_type": "code", "execution_count": 5, "id": "f8a83387", "metadata": {}, "outputs": [], "source": [ "query = \"Under what circumstances will the National Insurance Company Ltd. indemnify the insured or hospital for medical expenses?\"" ] }, { "cell_type": "code", "execution_count": 1, "id": "969eb757", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "c:\\code\\Bajaj HackRx\\Rag_app\\.venv\\Lib\\site-packages\\tqdm\\auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", " from .autonotebook import tqdm as notebook_tqdm\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "[RAGService] Initializing service...\n", "[RAGService] Loading LLM model (gemini)...\n", "Loading config....\n", "LLM loading...\n", "Loading model from provider: \n", "Loading model from gemini:\n", "[RAGService] LLM model loaded.\n", "[RAGService] Loading embedding model (huggingface)...\n", "Loading config....\n", "LLM loading...\n", "Loading model from provider: \n", "Loading model from huggingface:\n", "[RAGService] Embedding model loaded.\n", "[RAGService] Initialization complete.\n", "[RAGService] Loading document. Type: pdf, Path: app\\uploads\\policy-1-5.pdf, URL: None\n", "[RAGService] Loading PDF from path: app\\uploads\\policy-1-5.pdf\n", "[RAGService] Detecting document type scheme...\n", "[RAGService] Document type scheme detected: document_types='Insurance'\n", "[RAGService] Document type model: \n", "[RAGService] Splitting document into chunks...\n", "doc number: 0\n", "doc number: 1\n", "doc number: 2\n", "doc number: 3\n", "doc number: 4\n", "[RAGService] Total chunks created: 34\n" ] } ], "source": [ "from app.services.RAG_service import RAGService\n", "ragservice = RAGService()\n", "ragservice.load_and_split_document(type=\"pdf\", path=r\"app\\uploads\\policy-1-5.pdf\")\n" ] }, { "cell_type": "code", "execution_count": 6, "id": "11702ff5", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[RAGService] Creating vector store...\n", "[RAGService] Vector store created. Index: , Namespace: hackrx-index2025-08-31-16-44\n" ] } ], "source": [ "ragservice.create_vector_store()" ] }, { "cell_type": "code", "execution_count": 11, "id": "5063b018", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[RAGService] Creating query embedding...\n", "[RAGService] Query embedding created: [-0.8603366613388062, -0.570717453956604, -0.34522899985313416, 0.16601255536079407, -0.24724343419075012, -0.5776598453521729, 0.06773030757904053, -0.37220603227615356, 0.04772556573152542, 0.45760732889175415, 0.5835538506507874, 1.1237809658050537, 0.6570431590080261, -0.021462753415107727, -0.3690760135650635, 0.7206573486328125, -0.9792659282684326, -0.6745959520339966, 0.6139264702796936, 0.6773326396942139, 0.26511913537979126, 0.02896019071340561, -1.0298562049865723, -0.08510465919971466, -0.28914597630500793, 0.4489798843860626, 0.6205315589904785, -0.3424016535282135, 0.8850194215774536, 0.5542510151863098, -0.8981160521507263, 0.4385377764701843, 0.08767246454954147, 0.41202402114868164, -0.2126251608133316, -0.4365808069705963, -0.17071902751922607, -0.8426147103309631, 0.19907844066619873, -0.10970558226108551, -0.6989074945449829, 0.6822434663772583, 0.6546234488487244, -0.6311490535736084, -0.419131338596344, -0.43486663699150085, -0.9979442358016968, -0.3636943995952606, 0.5418152213096619, -0.5228120684623718, 0.32965967059135437, -0.020741594955325127, 0.009532235562801361, -0.04877936467528343, -0.41593122482299805, -0.011670615524053574, -0.059681277722120285, -0.5411169528961182, -0.4598591923713684, 0.16965138912200928, -0.5981170535087585, -0.6764969229698181, 1.269866704940796, -0.5952215194702148, 0.5385794639587402, 0.48234009742736816, -0.28119969367980957, 0.42279306054115295, -0.19056262075901031, 0.3323802351951599, 1.0100988149642944, -0.04509022459387779, -0.450788289308548, 0.22236961126327515, 0.3247843086719513, 0.3596532642841339, 0.6776524186134338, -0.2771018147468567, 0.4750179648399353, -0.272795706987381, 0.06372702121734619, -0.03656938672065735, 0.484089732170105, -0.9391509890556335, -0.469627320766449, 0.4701458811759949, 0.48329249024391174, 0.718686044216156, 0.6275887489318848, -0.3545490801334381, -0.3707812428474426, 0.1515081524848938, -0.09899330139160156, 0.21147030591964722, -0.3916902244091034, 0.005648448131978512, -1.4796407222747803, 0.4922502934932709, 0.41259387135505676, 0.3861837089061737, 0.2885802686214447, 0.03265722468495369, 0.33298730850219727, 0.6758648753166199, -0.35590386390686035, 0.6071678996086121, 0.07657430320978165, -0.4950539469718933, -0.7816869020462036, -0.19982916116714478, 0.2657483220100403, -0.7114686965942383, -0.2790968418121338, -1.0573067665100098, 0.5531938076019287, 0.6054178476333618, -0.6668511629104614, 0.20570220053195953, -0.6435935497283936, 1.0776041746139526, 0.6949087977409363, 0.300161212682724, 1.3094419240951538, -0.6329105496406555, 0.09089755266904831, 0.5068932771682739, 0.2343149185180664, 0.5364036560058594, -0.8030732274055481, -0.44995224475860596, 0.26124992966651917, 0.018877461552619934, -0.328591912984848, 0.32118478417396545, 0.09997376054525375, 0.22591283917427063, 0.29700830578804016, 0.43993857502937317, 0.7677856087684631, 0.5759483575820923, -0.16725704073905945, 0.6708597540855408, 0.24592968821525574, 1.060701847076416, -0.08366739749908447, 1.5838823318481445, -0.28296929597854614, -0.5816439986228943, -0.7947790622711182, 0.282768577337265, -0.7781724333763123, 0.006456074304878712, 0.9545721411705017, 0.4215579628944397, 0.8419412970542908, 0.03655420243740082, -1.3066558837890625, -1.1121793985366821, 0.3360479176044464, 0.36923131346702576, -1.0767834186553955, -0.14395807683467865, -0.23286592960357666, 1.1930011510849, -0.1922733187675476, -0.020326770842075348, 0.12076810002326965, 0.008508387953042984, -0.36556926369667053, -0.4275655150413513, 0.39237841963768005, -0.41965487599372864, -0.4994206428527832, 0.014632046222686768, 0.6856486797332764, 1.1280436515808105, 1.7885860204696655, 0.24804003536701202, 0.2229556143283844, 0.04371480643749237, -0.7365517020225525, 0.2554525136947632, -0.04445328563451767, 0.25302642583847046, 0.5050696134567261, 0.6628846526145935, 0.6963392496109009, 0.004126666113734245, 0.05100439488887787, -0.5797492265701294, 0.6921287775039673, -0.1860702931880951, -0.9704614877700806, 1.472691535949707, -0.46087270975112915, 0.10305436700582504, -0.7344096302986145, 0.09751887619495392, -0.16495570540428162, -0.8560068607330322, -0.536500871181488, -0.08443763852119446, -0.7527978420257568, 0.6417099833488464, 0.075804203748703, -0.1886061429977417, 0.8626828193664551, 0.7617500424385071, 0.22849741578102112, 0.6187096238136292, 0.20122696459293365, 0.6710953712463379, -0.6297173500061035, -0.4790228307247162, 0.5926417112350464, 1.3525768518447876, -0.23343272507190704, 0.07500746846199036, -1.147060751914978, -0.18650923669338226, -1.0420364141464233, 0.7081589698791504, 0.398161381483078, 0.5838255286216736, 0.3048601448535919, -0.42283564805984497, 0.3136441111564636, 0.328476220369339, -0.26201948523521423, 0.37119099497795105, -0.3710317313671112, -0.12878534197807312, -0.2008943259716034, 0.7865197062492371, 0.016837529838085175, -0.27719277143478394, 0.1209426298737526, 0.09458416700363159, 0.3348194360733032, 0.4715481996536255, -0.3798612952232361, 0.4698401987552643, 0.8226529955863953, 0.02560059353709221, 0.03965210169553757, 0.49308159947395325, 0.4582320749759674, -0.5330755710601807, -0.5945115685462952, 0.17707541584968567, 0.5964130759239197, 0.20269502699375153, 0.43890854716300964, 1.137032151222229, -0.15026555955410004, 0.8406538367271423, 1.0773800611495972, 0.3142930269241333, -0.29579755663871765, -1.0103107690811157, -0.25941962003707886, 0.645112156867981, -0.8197670578956604, 0.2836706042289734, 0.7918447852134705, -0.7640669345855713, 0.9036519527435303, -0.74195396900177, -0.39111921191215515, -0.4819728434085846, -0.1579606533050537, 0.27951762080192566, -0.025871364399790764, -0.16179585456848145, -0.5539743304252625, -1.514493703842163, 0.5217194557189941, -0.19359846413135529, 0.06235641986131668, -0.532980740070343, 0.0069984630681574345, -0.06727446615695953, -0.3317905068397522, 0.6535046100616455, -0.339053213596344, 0.12640726566314697, -1.455363154411316, 0.5339310169219971, 0.09585107862949371, 0.07267910242080688, 0.7185985445976257, 0.2640569806098938, 0.023218344897031784, -0.3611353933811188, 0.7375033497810364, -0.6416553258895874, 0.21131788194179535, 0.3277553915977478, -1.188575029373169, -0.3814670741558075, -0.1051805391907692, -0.3655241131782532, -0.125950425863266, 0.10342933237552643, 0.1546335071325302, 0.39061465859413147, 0.5023150444030762, -0.2037353217601776, 0.4768263101577759, -0.08536596596240997, -0.19260026514530182, 0.5138483047485352, -0.15396927297115326, -0.4266148805618286, -0.8365256190299988, 0.2601850628852844, -0.020110536366701126, -0.15119141340255737, -0.8540163636207581, 0.06806881725788116, -0.40376898646354675, 0.0010243430733680725, -0.8347283601760864, 0.3015129566192627, 0.10896852612495422, -0.2864687442779541, 1.261461615562439, -1.3678776025772095, 0.0017650519730523229, -0.5086532831192017, -0.4269801378250122, -1.0302062034606934, 0.07050594687461853, 0.36052337288856506, -0.7295159697532654, -0.11519113183021545, -0.8098714351654053, -0.5406626462936401, -0.75873202085495, -1.3303018808364868, 0.8725192546844482, -0.4355540871620178, 0.1563960164785385, -0.4792560338973999, -0.36997172236442566, 1.2977689504623413, 0.3836655616760254, -0.05462374538183212, -0.3851611912250519, -0.14649632573127747, -0.4415591359138489, 0.4230036735534668, -0.15491515398025513, -0.10117834806442261, -0.4235314130783081, 1.299603819847107, 0.5408402681350708, 0.27244889736175537, -0.5183252096176147, 0.13259926438331604, 0.5455774068832397, 0.12102965265512466, -0.3050030469894409, -0.5698559284210205, -0.07523781061172485, -0.9196527004241943, -0.4064880907535553, -0.36558157205581665, 0.6938713192939758, -0.1916867345571518, 1.1455384492874146, -0.16943661868572235, -0.2686749994754791, -0.2529793381690979, -0.5880717635154724, -1.168932318687439, 0.10454432666301727, -0.04031442850828171, 0.3435821235179901, -0.9440358877182007, 0.3398871123790741, -0.09754349291324615, 0.09828361868858337, -0.06490528583526611, -0.7683921456336975, 0.41742560267448425, -0.2780107259750366, -0.29349109530448914, -0.2648105025291443, -0.11909100413322449, -0.17402544617652893, -0.4351215660572052, 0.7962142825126648, 0.48315951228141785, -0.8757777214050293, -0.09530308842658997, -0.13842877745628357, -0.45567330718040466, 0.11531683057546616, -0.006921231746673584, 0.850473940372467, 0.3862159550189972, 0.5789031982421875, 0.6757336854934692, 0.1646341234445572, -0.6447497010231018, 0.13396215438842773, 0.4615304172039032, -0.2538212537765503, -0.3389425277709961, -1.3686047792434692, 0.1324748694896698, 0.24677100777626038, 0.23666542768478394, -0.2248625010251999, -0.20651137828826904, -0.509544849395752, -0.06863351166248322, -0.33658599853515625, -0.5875144600868225, 0.28495028614997864, -0.5745041966438293, -0.22077086567878723, 0.6125624179840088, 0.667155385017395, -1.2220878601074219, 0.7133581042289734, -0.28854596614837646, 0.224154993891716, -0.2627195119857788, 0.5411970615386963, -0.7552139759063721, 0.2122541069984436, -0.13031047582626343, -0.00490492582321167, 0.19603700935840607, -0.21689781546592712, -0.3926554322242737, 0.6026667952537537, -0.44021421670913696, 0.3432596027851105, 0.7797017097473145, -0.4971054196357727, 0.013597546145319939, 0.02182171866297722, 0.5105577707290649, 0.7206698656082153, 0.4449895918369293, 0.3705386221408844, -0.5213057994842529, 0.41107994318008423, -0.5915321111679077, 0.596398115158081, 0.0625627189874649, -0.6461838483810425, 0.30733954906463623, -0.23870760202407837, -0.23671886324882507, 0.41960883140563965, -0.6400614380836487, -0.2686879336833954, -0.26798543334007263, 0.6516044735908508, -0.8541534543037415, 0.21075640618801117, 0.8637982606887817, 0.45874908566474915, -0.3101629614830017, 1.6935176849365234, -0.06852594017982483, 0.17889080941677094, -0.38488566875457764, 0.13413158059120178, 0.18229369819164276, 0.785063624382019, 0.3413366973400116, -0.0783960223197937, -0.35454487800598145, -0.48641109466552734, 0.4431784451007843, -0.159215047955513, -0.13293875753879547, -0.11533457040786743, 0.5356506109237671, -0.13353390991687775, -1.1776626110076904, -0.49066412448883057, 0.5662490725517273, -0.3427337408065796, 0.7278738021850586, 0.711039662361145, 0.22100234031677246, -0.00784769095480442, -0.6566939949989319, 0.1770506054162979, -0.44434115290641785, -0.6722993850708008, -0.5701971054077148, -0.48523062467575073, -0.719138503074646, -0.035835206508636475, -0.1467561572790146, -0.08640019595623016, -0.2706433832645416, 0.18812674283981323, -0.7204006910324097, -0.6555923223495483, -0.0709051638841629, -0.3620237410068512, -0.33494168519973755, -0.318647563457489, 0.4358185827732086, 0.49508821964263916, 0.0891190841794014, 1.2528715133666992, 0.892665684223175, 0.531717836856842, -0.6004273891448975, 0.4540843069553375, 0.4177263081073761, 0.5905497074127197, -0.3773697316646576, -1.1342483758926392, 0.06558223068714142, -0.2388104796409607, 0.1989879459142685, -0.07664047181606293, 0.4235016107559204, -0.2159450799226761, -1.4234206676483154, 0.3281432092189789, -0.8287595510482788, -0.8093162178993225, -0.13589879870414734, -1.0091066360473633, 0.05632174760103226, 0.6696903109550476, -0.046426717191934586, -0.07002845406532288, -0.6183600425720215, -1.0922093391418457, 1.2929812669754028, 0.09723334014415741, -0.4217694103717804, 0.17528733611106873, -1.3618648052215576, 0.1500246524810791, 0.8266279101371765, 0.6519342064857483, 0.20296666026115417, -0.9541494846343994, -0.14599555730819702, 1.0977610349655151, -0.009647751227021217, 0.05069424957036972, -0.22598299384117126, 0.23929338157176971, 0.5046960115432739, 0.6855521202087402, 1.119672179222107, -0.38511478900909424, 1.1891874074935913, 0.143587127327919, 0.09648725390434265, -0.9012134671211243, -0.09369336813688278, -0.5949082970619202, -0.3442935049533844, 0.04463423416018486, -0.9285247921943665, -0.484125554561615, 0.18978722393512726, 0.09809868782758713, 0.7161828875541687, 0.188322514295578, 0.040207065641880035, -0.3371500074863434, -1.2074191570281982, -0.9635929465293884, 0.6200101375579834, 0.4912131428718567, -0.6356111168861389, 0.49527212977409363, 0.06092679128050804, 0.43116191029548645, -0.12454228848218918, 0.015564151108264923, 0.7467666268348694, -0.4058563709259033, -0.5881712436676025, -0.3175191283226013, 0.6594282388687134, 0.9670323729515076, -0.38860344886779785, -0.15500056743621826, -0.1720384657382965, -0.09583033621311188, -0.25562480092048645, -0.8041850328445435, -0.8825818300247192, -0.9710862040519714, 0.23327186703681946, 0.09854386001825333, -0.31542038917541504, 0.32083794474601746, -0.6518469452857971, -0.3248211443424225, -0.814388632774353, 0.9968970417976379, -0.1006031483411789, -0.3126799166202545, 1.9109784364700317, -0.05220983177423477, -0.2257789820432663, 0.3217199444770813, -0.9846692085266113, -0.12870703637599945, -0.0995953232049942, -0.03915712237358093, 0.10123415291309357, -1.1965841054916382, 0.48235684633255005, 0.4590212106704712, -0.5099117755889893, -0.4570617973804474, 0.45591840147972107, -0.7194918394088745, -0.37551769614219666, -0.3345124423503876, 0.3474261164665222, 0.8314245939254761, 0.7685109972953796, 0.35256049036979675, -0.3110496699810028, 0.10265517234802246, 0.10221941024065018, 0.06932760030031204, 0.9813084006309509, -0.276655912399292, -0.199928417801857, 0.20574019849300385, -0.17076513171195984, -0.14145925641059875, -0.3426133990287781, -0.24171140789985657, -0.39117684960365295, 0.8098270297050476, 0.05614154785871506, 0.1738211214542389, -0.39644330739974976, 0.2291540950536728, 0.31756365299224854, 0.49091410636901855, -0.0235237255692482, 0.07439138740301132, 0.707788348197937, -0.3805168867111206, 0.05750901252031326, 0.06235778331756592, -0.07561866194009781, -0.20177239179611206, -0.2160705029964447, -0.6648254990577698, 0.052757591009140015, 0.9877351522445679, 1.089125394821167, 1.1144365072250366, -0.5586932897567749, -0.1425173133611679, 0.1673925817012787, -0.08535781502723694, -0.34391045570373535, 0.22348088026046753, 0.4000142216682434, 0.19652962684631348, -0.062225986272096634, -0.9722151160240173, -0.3482121229171753, -0.10156208276748657, -0.9292646646499634, -0.3445979058742523, 0.2491150051355362, -0.21535730361938477, 0.43627631664276123, -1.0099663734436035, -0.059413306415081024, -0.3851551115512848, -0.5082497000694275, 0.3987419009208679, 0.08773404359817505, -0.29631736874580383, 0.24653904139995575, -0.31573960185050964, -0.5130584836006165, -0.42133858799934387, 0.8303518891334534, -0.10052938014268875, 0.8546417355537415, 1.4155396223068237, 0.41202226281166077, 0.32349950075149536, 1.3503880500793457, 0.10098809748888016, 0.5978941321372986, 0.49438047409057617, -0.13861556351184845, 0.08225663006305695, 0.3379018306732178, -0.16478656232357025, -0.2992511987686157, 0.24084815382957458, -0.8363417983055115, -0.4482113718986511, -0.20043043792247772, -0.13275893032550812, -0.21674245595932007, 0.5512347221374512, 0.37054669857025146, 0.4617774486541748, -0.5193992257118225, -0.033443763852119446, -0.9550479650497437, 0.3941212296485901, 0.4660748839378357, 0.4806491732597351, 0.7223198413848877, 0.9448751211166382, 0.8843069672584534, 0.022959046065807343, 0.9052661657333374, -0.6150215268135071, -0.945559561252594, -0.23366501927375793, 0.2318839728832245, -0.1440443992614746, -0.07562485337257385, 0.049818940460681915, -1.0039129257202148, -0.17707820236682892, -0.028662554919719696, 0.23172321915626526, 1.2836381196975708, 0.33244794607162476, 1.6053739786148071, -0.14138725399971008, -1.1472002267837524, -1.0115995407104492, -0.4405966103076935, -0.20387859642505646, 0.8403642773628235, -0.5854346752166748, -0.02645675092935562, -0.7891899347305298, -0.9128605127334595, 0.5036547183990479, -0.36841219663619995, -0.5820671916007996, -0.06201581656932831, 0.7783399224281311, 0.02918851561844349, -0.09181985259056091, -0.03615836426615715, 0.35532936453819275, 0.343374639749527, 0.5940067768096924, -0.6981809735298157, -0.7250673174858093, 0.007869742810726166, -0.012582018971443176, -0.08930594474077225, 0.468065470457077, 0.4173561930656433, -0.19463054835796356, -1.107336401939392, 0.8380171656608582, -0.31736522912979126, -0.109514981508255, -0.35244134068489075, -0.7223466634750366, 0.026787592098116875, 0.5207688808441162, -0.730949878692627, 0.886661171913147, -0.14437513053417206, -1.4927784204483032, -0.9820917844772339, -0.7887128591537476, 0.7997300028800964, 0.3048294484615326, -0.12003497779369354, 0.5226487517356873, 1.217190146446228, -0.13837358355522156, -0.4476281702518463, -0.03992200642824173, 0.9442427754402161, 0.3993394672870636, -0.15783855319023132, -0.13316519558429718, 0.6084871292114258, 0.1673276722431183, 0.09648291766643524, -1.378421425819397, 0.0008641853928565979, -0.4947916269302368, -0.029297329485416412, -0.06989727914333344, -0.10585850477218628, 0.6349356174468994, -0.06223105639219284, -1.1856263875961304, 0.20414821803569794, -0.42543694376945496, 0.4704970419406891, 0.006174817681312561, -0.7478955984115601, 0.15134292840957642, -0.8050072193145752, -0.21709102392196655, -0.409406840801239, 0.06610046327114105, 0.928687572479248, -0.05100984871387482, -0.15010908246040344, -0.08161018788814545, 0.7575573921203613, 0.7740848064422607, 0.6952190399169922, 0.16574446856975555, -0.1622888445854187, -0.9317472577095032, 0.24829275906085968, -0.9919333457946777, -0.6829149723052979, 0.04017406329512596, 0.6050066351890564, -0.007574155926704407, -0.6668479442596436, -0.7789987921714783, -0.009110070765018463, -0.12503185868263245, 0.23250389099121094, -0.2510136365890503, 0.22770854830741882, -0.7311257719993591, 0.40256619453430176, -1.5055943727493286, -0.24695658683776855, 0.44744443893432617, 0.4114123582839966, -0.040992967784404755, 0.40716907382011414, 0.3097412884235382, 0.1829366385936737, 0.45874646306037903, -0.17392398416996002, 0.8271622061729431, 0.19449733197689056, 0.16207031905651093, -0.9853590130805969, -0.04071641340851784, -0.42136651277542114, 0.22357407212257385, -0.5154065489768982, 0.12734408676624298, -0.04508306086063385, -0.6019384264945984, 0.3433404266834259, -0.7926715016365051, -0.5868115425109863, -0.11822165548801422, 0.9301235675811768, -1.178655982017517, -0.9070127010345459, -0.3264298439025879, 0.6446837186813354, 0.3751564621925354, -0.37998488545417786, 1.64453125, -0.4841631352901459, -0.3516600728034973, -0.4310632348060608, 0.10234852135181427, 0.26944804191589355, -1.59700345993042, 0.535156786441803, -0.613686740398407, -0.2471684068441391, -1.7009804248809814, -0.6598629355430603, 0.23618584871292114, 0.6936094164848328, -0.9455260634422302, 0.16495157778263092, 0.8436883091926575, 0.9616954326629639, -0.9861839413642883, 0.48794686794281006, -0.33777639269828796, 0.247349813580513, 1.1234828233718872, 0.4605461359024048, -0.2258790135383606, 0.9857402443885803, -0.5706501603126526, 0.10760022699832916, 0.26500388979911804, -0.3818593919277191, -0.019298339262604713, 0.5142523646354675, -0.21567590534687042, 0.33272311091423035, 0.2821095585823059, -0.49720942974090576, -0.6735041737556458, 0.7973208427429199, 0.8310099840164185, 0.34131675958633423, -0.1841636747121811, -0.23998840153217316, 0.22247053682804108, -0.841377854347229, 0.8677225112915039, 0.05734883248806, 0.06475834548473358, -0.4298834800720215, 0.41410142183303833, 0.5393757224082947, -0.5971944332122803, 3.549190044403076, 0.047434400767087936, -0.29557856917381287, -0.17626409232616425, 1.2848196029663086, 0.7868889570236206, -0.7681962251663208, 0.04188777878880501, 0.2101193368434906, -0.318083256483078, 0.354533851146698, 0.5720810890197754, -0.0663369670510292, 0.5900956392288208, 0.23748566210269928, -0.1353508085012436, -0.23571333289146423, 1.6488866806030273, 0.11992111057043076, -0.7313017249107361, -0.48426494002342224, 0.49429887533187866, 0.14245188236236572, 1.120867133140564, -0.5037834644317627, -0.01772240549325943, 0.03621198236942291, -0.2962735593318939, -0.26124680042266846, -0.7587198615074158, 0.6516925096511841, -1.2889670133590698, 0.8676629066467285, -1.2267626523971558, -1.0782818794250488, 0.44680485129356384, 0.23054741322994232, -0.2598174810409546, -0.3070398271083832, -0.5218173265457153, -0.4787178635597229, 0.930364191532135, 0.3815813958644867, -0.7456197738647461, -0.454980731010437, -0.2569456398487091, -0.7136440873146057, 0.9141756296157837, -0.17779292166233063, -0.061149194836616516, 0.48280611634254456, 0.12840518355369568, -0.22309689223766327, -0.027117647230625153, -0.6482493877410889, -0.692912220954895, -0.4195660650730133, 0.2174762785434723, -0.5254086256027222, 0.05755229294300079, -0.0760922059416771, 0.27570515871047974, 0.13341625034809113, 0.3518025875091553, 0.33387914299964905, 1.1461304426193237, 0.738774836063385, 0.6530015468597412, -0.33877846598625183, 0.735017716884613, 0.7870914936065674, -0.2926076352596283, -0.17145425081253052, -0.001245349645614624, 0.6629992127418518, -0.16091302037239075, -0.23402990400791168, 0.07279575616121292, 0.08361431956291199, 0.12532104551792145, -0.41508692502975464, -0.14180609583854675, 0.3592752516269684, 0.9697443246841431, -0.5099834203720093, -0.16255660355091095, -0.3002346158027649, -0.4230375289916992, -0.21180853247642517, -0.1206309050321579, 0.2085934579372406, 0.1332968771457672, -0.4911423623561859, -0.1205999106168747, 0.20984643697738647]\n", "[RAGService] Extracting metadata for the query...\n", "[RAGService] Query metadata extracted: doc_id=None doc_category=['Insurance'] doc_type=['Policy Document'] jurisdiction=None effective_date=None expiry_date=None parties=['National Insurance Company Ltd.', 'Insured', 'Hospital'] penalties=None notes=None policy_number=None coverage_type=None premium_amount=None exclusions=None added_new_keyword=True\n", "[RAGService] Query metadata type: \n", "[RAGService] Query metadata: {'doc_category': {'$in': ['Insurance']}, 'doc_type': {'$in': ['Policy Document']}, 'parties': {'$in': ['National Insurance Company Ltd.', 'Insured', 'Hospital']}}\n" ] } ], "source": [ "ragservice.create_query_embedding(query)\n" ] }, { "cell_type": "code", "execution_count": 20, "id": "9862526e", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'parties': {'$in': ['National Insurance Company Ltd.', 'Insured']}}" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ragservice.query_metadata" ] }, { "cell_type": "markdown", "id": "25e173d8", "metadata": {}, "source": [] }, { "cell_type": "code", "execution_count": 75, "id": "9da7d25e", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[RAGService] Retrieving documents from vector store...\n", "[RAGService] Retrieval result: {'matches': [{'id': 'aa5601d8-11e1-4a5f-99aa-46119946f8af',\n", " 'metadata': {'added_new_keyword': True,\n", " 'author': '',\n", " 'chunk_id': '52373623-1c20-4d0c-aa57-74e600da1cd7_p0',\n", " 'coverage_type': ['Mediclaim',\n", " 'In-Patient Care',\n", " 'Day Care Treatment',\n", " 'Domiciliary Hospitalisation',\n", " 'AYUSH Treatment'],\n", " 'creationDate': '',\n", " 'creationdate': '',\n", " 'creator': '',\n", " 'doc_category': ['Insurance'],\n", " 'doc_id': '52373623-1c20-4d0c-aa57-74e600da1cd7',\n", " 'doc_type': ['Policy Document', 'Mediclaim Policy'],\n", " 'file_path': 'app\\\\uploads\\\\policy-1-5.pdf',\n", " 'format': 'PDF 1.7',\n", " 'jurisdiction': ['India'],\n", " 'keywords': '',\n", " 'modDate': 'D:20250830075253Z',\n", " 'moddate': '2025-08-30T07:52:53+00:00',\n", " 'page': 0.0,\n", " 'page_no': 0.0,\n", " 'parties': ['National Insurance Company Ltd.',\n", " 'Proposer',\n", " 'Insured Persons'],\n", " 'policy_number': ['NICHLIP25039V032425'],\n", " 'producer': 'iLovePDF',\n", " 'source': 'app\\\\uploads\\\\policy-1-5.pdf',\n", " 'subject': '',\n", " 'text': '(hereinafter called the Insured Persons) '\n", " 'and has paid the premium as consideration '\n", " 'for such insurance. \\n'\n", " ' \\n'\n", " '1 PREAMBLE \\n'\n", " 'The Company undertakes that if during the '\n", " 'Policy Period, any Insured Person shall '\n", " 'suffer any illness or disease (hereinafter '\n", " 'called \\n'\n", " 'Illness) or sustain any bodily injury due '\n", " 'to an Accident (hereinafter called Injury) '\n", " 'requiring Hospitalisation of such '\n", " 'Insured \\n'\n", " 'Person(s) for In-Patient Care at any '\n", " 'hospital/nursing home (hereinafter called '\n", " 'Hospital) or for Day Care Treatment at any '\n", " 'Day \\n'\n", " 'Care Center or to undergo treatment under '\n", " 'Domiciliary Hospitalisation, following the '\n", " 'Medical Advice of a duly qualified '\n", " 'Medical \\n'\n", " 'Practitioner, the Company shall indemnify '\n", " 'the Hospital or the Insured, Reasonable '\n", " 'and Customary Charges incurred for '\n", " 'Medically',\n", " 'title': '',\n", " 'total_pages': 5.0,\n", " 'trapped': '',\n", " 'type': 'text'},\n", " 'score': 0.834982336,\n", " 'values': []},\n", " {'id': '92bdedc4-44c4-46d2-a373-2ba1a7d1fd20',\n", " 'metadata': {'added_new_keyword': True,\n", " 'author': '',\n", " 'chunk_id': '3b8adc99-e347-44fd-83fd-b5b27e368f0d_p4',\n", " 'coverage_type': ['Surgery or Surgical Procedure',\n", " 'Hospitalisation',\n", " 'Dental Treatment',\n", " 'Day Care Treatment',\n", " 'Mediclaim',\n", " 'AYUSH Treatment',\n", " 'Intensive Care Unit',\n", " 'In-Patient Care',\n", " 'Domiciliary Hospitalisation',\n", " 'In-patient Treatment',\n", " 'internal surgical implants',\n", " 'Dental treatment due to injury',\n", " 'Plastic surgery due to disease '\n", " 'or injury',\n", " 'Hormone replacement therapy',\n", " 'Vitamins and tonics for '\n", " 'treatment',\n", " 'Circumcision for treatment',\n", " 'Diagnostic procedures',\n", " 'Cataract Surgery',\n", " 'Hazardous sports treatment',\n", " 'Pre Hospitalisation',\n", " 'Post Hospitalisation'],\n", " 'creationDate': '',\n", " 'creationdate': '',\n", " 'creator': '',\n", " 'doc_category': ['Insurance'],\n", " 'doc_id': '3b8adc99-e347-44fd-83fd-b5b27e368f0d',\n", " 'doc_type': ['Policy Document', 'Mediclaim Policy'],\n", " 'exclusions': ['out-patient treatment',\n", " 'Unproven/ Experimental Treatment',\n", " 'Pre existing disease',\n", " 'cosmetic surgery',\n", " 'implants',\n", " 'Waiting Period',\n", " 'domiciliary treatment less than '\n", " 'three days',\n", " 'alternative domiciliary treatment',\n", " 'maternity domiciliary expenses',\n", " 'infertility domiciliary expenses',\n", " 'Asthma in domiciliary '\n", " 'hospitalization',\n", " 'Bronchitis in domiciliary '\n", " 'hospitalization',\n", " 'Chronic nephritis in domiciliary '\n", " 'hospitalization',\n", " 'Nephritic syndrome in domiciliary '\n", " 'hospitalization',\n", " 'Diarrhoea in domiciliary '\n", " 'hospitalization',\n", " 'Dysenteries in domiciliary '\n", " 'hospitalization',\n", " 'Gastroenteritis in domiciliary '\n", " 'hospitalization',\n", " 'Epilepsy in domiciliary '\n", " 'hospitalization',\n", " 'Influenza in domiciliary '\n", " 'hospitalization',\n", " 'Cough and cold in domiciliary '\n", " 'hospitalization',\n", " 'Psychiatric disorders in '\n", " 'domiciliary hospitalization',\n", " 'Psychosomatic disorders in '\n", " 'domiciliary hospitalization',\n", " 'Pyrexia of unknown origin in '\n", " 'domiciliary hospitalization',\n", " 'Tonsillitis in domiciliary '\n", " 'hospitalization',\n", " 'Upper respiratory tract infection '\n", " 'in domiciliary hospitalization',\n", " 'Laryngitis in domiciliary '\n", " 'hospitalization',\n", " 'Pharingitis in domiciliary '\n", " 'hospitalization',\n", " 'Arthritis in domiciliary '\n", " 'hospitalization',\n", " 'Gout in domiciliary hospitalization',\n", " 'Rheumatism in domiciliary '\n", " 'hospitalization'],\n", " 'file_path': 'app\\\\uploads\\\\policy-1-5.pdf',\n", " 'format': 'PDF 1.7',\n", " 'jurisdiction': ['India'],\n", " 'keywords': '',\n", " 'modDate': 'D:20250830075253Z',\n", " 'moddate': '2025-08-30T07:52:53+00:00',\n", " 'page': 4.0,\n", " 'page_no': 4.0,\n", " 'parties': ['National Insurance Company Ltd.',\n", " 'Insured Person',\n", " 'Medical Practitioner'],\n", " 'policy_number': ['NICHLIP25039V032425'],\n", " 'producer': 'iLovePDF',\n", " 'source': 'app\\\\uploads\\\\policy-1-5.pdf',\n", " 'subject': '',\n", " 'text': 'National Insurance Co. Ltd. \\n'\n", " 'Premises No. 18-0374, Plot no. CBD-81, \\n'\n", " 'New Town, Kolkata - 700156 \\n'\n", " 'Page 5 of 25 \\n'\n", " 'National Parivar Mediclaim Plus Policy \\n'\n", " 'UIN: NICHLIP25039V032425 \\n'\n", " ' \\n'\n", " '3 BENEFITS COVERED UNDER THE POLICY \\n'\n", " '3.1COVERAGE \\n'\n", " '3.1.1 In-patient Treatment \\n'\n", " 'The Company shall indemnify the medical '\n", " 'expenses for: \\n'\n", " 'i. \\n'\n", " 'Room charges and intensive care unit '\n", " 'charges (including diet charges, nursing '\n", " 'care by qualified nurse, RMO charges, \\n'\n", " 'administration charges for IV fluids/blood '\n", " 'transfusion/injection), subject to limit '\n", " 'as per Section 3.1.1.1 \\n'\n", " 'ii. Medical practitioner(s) \\n'\n", " 'iii. Anaesthesia, blood, oxygen, operation '\n", " 'theatre charges, surgical appliances \\n'\n", " 'iv. Medicines and drugs \\n'\n", " 'v. Diagnostic procedures',\n", " 'title': '',\n", " 'total_pages': 5.0,\n", " 'trapped': '',\n", " 'type': 'text'},\n", " 'score': 0.806417465,\n", " 'values': []},\n", " {'id': 'c1e7cdf9-ad8f-4a75-af86-30268c13c7be',\n", " 'metadata': {'added_new_keyword': True,\n", " 'author': '',\n", " 'chunk_id': '3b8adc99-e347-44fd-83fd-b5b27e368f0d_p4',\n", " 'coverage_type': ['Surgery or Surgical Procedure',\n", " 'Hospitalisation',\n", " 'Dental Treatment',\n", " 'Day Care Treatment',\n", " 'Mediclaim',\n", " 'AYUSH Treatment',\n", " 'Intensive Care Unit',\n", " 'In-Patient Care',\n", " 'Domiciliary Hospitalisation',\n", " 'In-patient Treatment',\n", " 'internal surgical implants',\n", " 'Dental treatment due to injury',\n", " 'Plastic surgery due to disease '\n", " 'or injury',\n", " 'Hormone replacement therapy',\n", " 'Vitamins and tonics for '\n", " 'treatment',\n", " 'Circumcision for treatment',\n", " 'Diagnostic procedures',\n", " 'Cataract Surgery',\n", " 'Hazardous sports treatment',\n", " 'Pre Hospitalisation',\n", " 'Post Hospitalisation'],\n", " 'creationDate': '',\n", " 'creationdate': '',\n", " 'creator': '',\n", " 'doc_category': ['Insurance'],\n", " 'doc_id': '3b8adc99-e347-44fd-83fd-b5b27e368f0d',\n", " 'doc_type': ['Policy Document', 'Mediclaim Policy'],\n", " 'exclusions': ['out-patient treatment',\n", " 'Unproven/ Experimental Treatment',\n", " 'Pre existing disease',\n", " 'cosmetic surgery',\n", " 'implants',\n", " 'Waiting Period',\n", " 'domiciliary treatment less than '\n", " 'three days',\n", " 'alternative domiciliary treatment',\n", " 'maternity domiciliary expenses',\n", " 'infertility domiciliary expenses',\n", " 'Asthma in domiciliary '\n", " 'hospitalization',\n", " 'Bronchitis in domiciliary '\n", " 'hospitalization',\n", " 'Chronic nephritis in domiciliary '\n", " 'hospitalization',\n", " 'Nephritic syndrome in domiciliary '\n", " 'hospitalization',\n", " 'Diarrhoea in domiciliary '\n", " 'hospitalization',\n", " 'Dysenteries in domiciliary '\n", " 'hospitalization',\n", " 'Gastroenteritis in domiciliary '\n", " 'hospitalization',\n", " 'Epilepsy in domiciliary '\n", " 'hospitalization',\n", " 'Influenza in domiciliary '\n", " 'hospitalization',\n", " 'Cough and cold in domiciliary '\n", " 'hospitalization',\n", " 'Psychiatric disorders in '\n", " 'domiciliary hospitalization',\n", " 'Psychosomatic disorders in '\n", " 'domiciliary hospitalization',\n", " 'Pyrexia of unknown origin in '\n", " 'domiciliary hospitalization',\n", " 'Tonsillitis in domiciliary '\n", " 'hospitalization',\n", " 'Upper respiratory tract infection '\n", " 'in domiciliary hospitalization',\n", " 'Laryngitis in domiciliary '\n", " 'hospitalization',\n", " 'Pharingitis in domiciliary '\n", " 'hospitalization',\n", " 'Arthritis in domiciliary '\n", " 'hospitalization',\n", " 'Gout in domiciliary hospitalization',\n", " 'Rheumatism in domiciliary '\n", " 'hospitalization'],\n", " 'file_path': 'app\\\\uploads\\\\policy-1-5.pdf',\n", " 'format': 'PDF 1.7',\n", " 'jurisdiction': ['India'],\n", " 'keywords': '',\n", " 'modDate': 'D:20250830075253Z',\n", " 'moddate': '2025-08-30T07:52:53+00:00',\n", " 'page': 4.0,\n", " 'page_no': 4.0,\n", " 'parties': ['National Insurance Company Ltd.',\n", " 'Insured Person',\n", " 'Medical Practitioner'],\n", " 'policy_number': ['NICHLIP25039V032425'],\n", " 'producer': 'iLovePDF',\n", " 'source': 'app\\\\uploads\\\\policy-1-5.pdf',\n", " 'subject': '',\n", " 'text': 'Pre hospitalisation shall be considered as '\n", " 'part of the Hospitalisation claim. \\n'\n", " ' \\n'\n", " '3.1.3 Post Hospitalisation \\n'\n", " 'The Company shall indemnify the medical '\n", " 'expenses incurred up to sixty days '\n", " 'immediately after the insured person is '\n", " 'discharged \\n'\n", " 'from hospital, provided that: \\n'\n", " 'i. \\n'\n", " 'such medical expenses are incurred for the '\n", " 'same condition for which the insured '\n", " 'person’s hospitalisation was required, '\n", " 'and \\n'\n", " 'ii. the in-patient hospitalisation claim '\n", " 'for such hospitalisation is admissible by '\n", " 'the Company \\n'\n", " 'Post hospitalisation shall be considered '\n", " 'as part of the hospitalisation claim. \\n'\n", " ' \\n'\n", " '3.1.4 Domiciliary Hospitalisation \\n'\n", " 'The Company shall Company shall indemnify '\n", " 'the medical expenses incurred under '\n", " 'domiciliary hospitalization, including Pre',\n", " 'title': '',\n", " 'total_pages': 5.0,\n", " 'trapped': '',\n", " 'type': 'text'},\n", " 'score': 0.779073536,\n", " 'values': []}],\n", " 'namespace': 'hackrx-index2025-08-31-16-44',\n", " 'usage': {'read_units': 1}}\n" ] } ], "source": [ "result = ragservice.retrive_documents()" ] }, { "cell_type": "code", "execution_count": 101, "id": "ac825f51", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'matches': [{'id': 'aa5601d8-11e1-4a5f-99aa-46119946f8af',\n", " 'metadata': {'added_new_keyword': True,\n", " 'author': '',\n", " 'chunk_id': '52373623-1c20-4d0c-aa57-74e600da1cd7_p0',\n", " 'coverage_type': ['Mediclaim',\n", " 'In-Patient Care',\n", " 'Day Care Treatment',\n", " 'Domiciliary Hospitalisation',\n", " 'AYUSH Treatment'],\n", " 'creationDate': '',\n", " 'creationdate': '',\n", " 'creator': '',\n", " 'doc_category': ['Insurance'],\n", " 'doc_id': '52373623-1c20-4d0c-aa57-74e600da1cd7',\n", " 'doc_type': ['Policy Document', 'Mediclaim Policy'],\n", " 'file_path': 'app\\\\uploads\\\\policy-1-5.pdf',\n", " 'format': 'PDF 1.7',\n", " 'jurisdiction': ['India'],\n", " 'keywords': '',\n", " 'modDate': 'D:20250830075253Z',\n", " 'moddate': '2025-08-30T07:52:53+00:00',\n", " 'page': 0.0,\n", " 'page_no': 0.0,\n", " 'parties': ['National Insurance Company Ltd.',\n", " 'Proposer',\n", " 'Insured Persons'],\n", " 'policy_number': ['NICHLIP25039V032425'],\n", " 'producer': 'iLovePDF',\n", " 'source': 'app\\\\uploads\\\\policy-1-5.pdf',\n", " 'subject': '',\n", " 'text': '(hereinafter called the Insured Persons) '\n", " 'and has paid the premium as consideration '\n", " 'for such insurance. \\n'\n", " ' \\n'\n", " '1 PREAMBLE \\n'\n", " 'The Company undertakes that if during the '\n", " 'Policy Period, any Insured Person shall '\n", " 'suffer any illness or disease (hereinafter '\n", " 'called \\n'\n", " 'Illness) or sustain any bodily injury due '\n", " 'to an Accident (hereinafter called Injury) '\n", " 'requiring Hospitalisation of such '\n", " 'Insured \\n'\n", " 'Person(s) for In-Patient Care at any '\n", " 'hospital/nursing home (hereinafter called '\n", " 'Hospital) or for Day Care Treatment at any '\n", " 'Day \\n'\n", " 'Care Center or to undergo treatment under '\n", " 'Domiciliary Hospitalisation, following the '\n", " 'Medical Advice of a duly qualified '\n", " 'Medical \\n'\n", " 'Practitioner, the Company shall indemnify '\n", " 'the Hospital or the Insured, Reasonable '\n", " 'and Customary Charges incurred for '\n", " 'Medically',\n", " 'title': '',\n", " 'total_pages': 5.0,\n", " 'trapped': '',\n", " 'type': 'text'},\n", " 'score': 0.834982336,\n", " 'values': []},\n", " {'id': '92bdedc4-44c4-46d2-a373-2ba1a7d1fd20',\n", " 'metadata': {'added_new_keyword': True,\n", " 'author': '',\n", " 'chunk_id': '3b8adc99-e347-44fd-83fd-b5b27e368f0d_p4',\n", " 'coverage_type': ['Surgery or Surgical Procedure',\n", " 'Hospitalisation',\n", " 'Dental Treatment',\n", " 'Day Care Treatment',\n", " 'Mediclaim',\n", " 'AYUSH Treatment',\n", " 'Intensive Care Unit',\n", " 'In-Patient Care',\n", " 'Domiciliary Hospitalisation',\n", " 'In-patient Treatment',\n", " 'internal surgical implants',\n", " 'Dental treatment due to injury',\n", " 'Plastic surgery due to disease '\n", " 'or injury',\n", " 'Hormone replacement therapy',\n", " 'Vitamins and tonics for '\n", " 'treatment',\n", " 'Circumcision for treatment',\n", " 'Diagnostic procedures',\n", " 'Cataract Surgery',\n", " 'Hazardous sports treatment',\n", " 'Pre Hospitalisation',\n", " 'Post Hospitalisation'],\n", " 'creationDate': '',\n", " 'creationdate': '',\n", " 'creator': '',\n", " 'doc_category': ['Insurance'],\n", " 'doc_id': '3b8adc99-e347-44fd-83fd-b5b27e368f0d',\n", " 'doc_type': ['Policy Document', 'Mediclaim Policy'],\n", " 'exclusions': ['out-patient treatment',\n", " 'Unproven/ Experimental Treatment',\n", " 'Pre existing disease',\n", " 'cosmetic surgery',\n", " 'implants',\n", " 'Waiting Period',\n", " 'domiciliary treatment less than '\n", " 'three days',\n", " 'alternative domiciliary treatment',\n", " 'maternity domiciliary expenses',\n", " 'infertility domiciliary expenses',\n", " 'Asthma in domiciliary '\n", " 'hospitalization',\n", " 'Bronchitis in domiciliary '\n", " 'hospitalization',\n", " 'Chronic nephritis in domiciliary '\n", " 'hospitalization',\n", " 'Nephritic syndrome in domiciliary '\n", " 'hospitalization',\n", " 'Diarrhoea in domiciliary '\n", " 'hospitalization',\n", " 'Dysenteries in domiciliary '\n", " 'hospitalization',\n", " 'Gastroenteritis in domiciliary '\n", " 'hospitalization',\n", " 'Epilepsy in domiciliary '\n", " 'hospitalization',\n", " 'Influenza in domiciliary '\n", " 'hospitalization',\n", " 'Cough and cold in domiciliary '\n", " 'hospitalization',\n", " 'Psychiatric disorders in '\n", " 'domiciliary hospitalization',\n", " 'Psychosomatic disorders in '\n", " 'domiciliary hospitalization',\n", " 'Pyrexia of unknown origin in '\n", " 'domiciliary hospitalization',\n", " 'Tonsillitis in domiciliary '\n", " 'hospitalization',\n", " 'Upper respiratory tract infection '\n", " 'in domiciliary hospitalization',\n", " 'Laryngitis in domiciliary '\n", " 'hospitalization',\n", " 'Pharingitis in domiciliary '\n", " 'hospitalization',\n", " 'Arthritis in domiciliary '\n", " 'hospitalization',\n", " 'Gout in domiciliary hospitalization',\n", " 'Rheumatism in domiciliary '\n", " 'hospitalization'],\n", " 'file_path': 'app\\\\uploads\\\\policy-1-5.pdf',\n", " 'format': 'PDF 1.7',\n", " 'jurisdiction': ['India'],\n", " 'keywords': '',\n", " 'modDate': 'D:20250830075253Z',\n", " 'moddate': '2025-08-30T07:52:53+00:00',\n", " 'page': 4.0,\n", " 'page_no': 4.0,\n", " 'parties': ['National Insurance Company Ltd.',\n", " 'Insured Person',\n", " 'Medical Practitioner'],\n", " 'policy_number': ['NICHLIP25039V032425'],\n", " 'producer': 'iLovePDF',\n", " 'source': 'app\\\\uploads\\\\policy-1-5.pdf',\n", " 'subject': '',\n", " 'text': 'National Insurance Co. Ltd. \\n'\n", " 'Premises No. 18-0374, Plot no. CBD-81, \\n'\n", " 'New Town, Kolkata - 700156 \\n'\n", " 'Page 5 of 25 \\n'\n", " 'National Parivar Mediclaim Plus Policy \\n'\n", " 'UIN: NICHLIP25039V032425 \\n'\n", " ' \\n'\n", " '3 BENEFITS COVERED UNDER THE POLICY \\n'\n", " '3.1COVERAGE \\n'\n", " '3.1.1 In-patient Treatment \\n'\n", " 'The Company shall indemnify the medical '\n", " 'expenses for: \\n'\n", " 'i. \\n'\n", " 'Room charges and intensive care unit '\n", " 'charges (including diet charges, nursing '\n", " 'care by qualified nurse, RMO charges, \\n'\n", " 'administration charges for IV fluids/blood '\n", " 'transfusion/injection), subject to limit '\n", " 'as per Section 3.1.1.1 \\n'\n", " 'ii. Medical practitioner(s) \\n'\n", " 'iii. Anaesthesia, blood, oxygen, operation '\n", " 'theatre charges, surgical appliances \\n'\n", " 'iv. Medicines and drugs \\n'\n", " 'v. Diagnostic procedures',\n", " 'title': '',\n", " 'total_pages': 5.0,\n", " 'trapped': '',\n", " 'type': 'text'},\n", " 'score': 0.806417465,\n", " 'values': []},\n", " {'id': 'c1e7cdf9-ad8f-4a75-af86-30268c13c7be',\n", " 'metadata': {'added_new_keyword': True,\n", " 'author': '',\n", " 'chunk_id': '3b8adc99-e347-44fd-83fd-b5b27e368f0d_p4',\n", " 'coverage_type': ['Surgery or Surgical Procedure',\n", " 'Hospitalisation',\n", " 'Dental Treatment',\n", " 'Day Care Treatment',\n", " 'Mediclaim',\n", " 'AYUSH Treatment',\n", " 'Intensive Care Unit',\n", " 'In-Patient Care',\n", " 'Domiciliary Hospitalisation',\n", " 'In-patient Treatment',\n", " 'internal surgical implants',\n", " 'Dental treatment due to injury',\n", " 'Plastic surgery due to disease '\n", " 'or injury',\n", " 'Hormone replacement therapy',\n", " 'Vitamins and tonics for '\n", " 'treatment',\n", " 'Circumcision for treatment',\n", " 'Diagnostic procedures',\n", " 'Cataract Surgery',\n", " 'Hazardous sports treatment',\n", " 'Pre Hospitalisation',\n", " 'Post Hospitalisation'],\n", " 'creationDate': '',\n", " 'creationdate': '',\n", " 'creator': '',\n", " 'doc_category': ['Insurance'],\n", " 'doc_id': '3b8adc99-e347-44fd-83fd-b5b27e368f0d',\n", " 'doc_type': ['Policy Document', 'Mediclaim Policy'],\n", " 'exclusions': ['out-patient treatment',\n", " 'Unproven/ Experimental Treatment',\n", " 'Pre existing disease',\n", " 'cosmetic surgery',\n", " 'implants',\n", " 'Waiting Period',\n", " 'domiciliary treatment less than '\n", " 'three days',\n", " 'alternative domiciliary treatment',\n", " 'maternity domiciliary expenses',\n", " 'infertility domiciliary expenses',\n", " 'Asthma in domiciliary '\n", " 'hospitalization',\n", " 'Bronchitis in domiciliary '\n", " 'hospitalization',\n", " 'Chronic nephritis in domiciliary '\n", " 'hospitalization',\n", " 'Nephritic syndrome in domiciliary '\n", " 'hospitalization',\n", " 'Diarrhoea in domiciliary '\n", " 'hospitalization',\n", " 'Dysenteries in domiciliary '\n", " 'hospitalization',\n", " 'Gastroenteritis in domiciliary '\n", " 'hospitalization',\n", " 'Epilepsy in domiciliary '\n", " 'hospitalization',\n", " 'Influenza in domiciliary '\n", " 'hospitalization',\n", " 'Cough and cold in domiciliary '\n", " 'hospitalization',\n", " 'Psychiatric disorders in '\n", " 'domiciliary hospitalization',\n", " 'Psychosomatic disorders in '\n", " 'domiciliary hospitalization',\n", " 'Pyrexia of unknown origin in '\n", " 'domiciliary hospitalization',\n", " 'Tonsillitis in domiciliary '\n", " 'hospitalization',\n", " 'Upper respiratory tract infection '\n", " 'in domiciliary hospitalization',\n", " 'Laryngitis in domiciliary '\n", " 'hospitalization',\n", " 'Pharingitis in domiciliary '\n", " 'hospitalization',\n", " 'Arthritis in domiciliary '\n", " 'hospitalization',\n", " 'Gout in domiciliary hospitalization',\n", " 'Rheumatism in domiciliary '\n", " 'hospitalization'],\n", " 'file_path': 'app\\\\uploads\\\\policy-1-5.pdf',\n", " 'format': 'PDF 1.7',\n", " 'jurisdiction': ['India'],\n", " 'keywords': '',\n", " 'modDate': 'D:20250830075253Z',\n", " 'moddate': '2025-08-30T07:52:53+00:00',\n", " 'page': 4.0,\n", " 'page_no': 4.0,\n", " 'parties': ['National Insurance Company Ltd.',\n", " 'Insured Person',\n", " 'Medical Practitioner'],\n", " 'policy_number': ['NICHLIP25039V032425'],\n", " 'producer': 'iLovePDF',\n", " 'source': 'app\\\\uploads\\\\policy-1-5.pdf',\n", " 'subject': '',\n", " 'text': 'Pre hospitalisation shall be considered as '\n", " 'part of the Hospitalisation claim. \\n'\n", " ' \\n'\n", " '3.1.3 Post Hospitalisation \\n'\n", " 'The Company shall indemnify the medical '\n", " 'expenses incurred up to sixty days '\n", " 'immediately after the insured person is '\n", " 'discharged \\n'\n", " 'from hospital, provided that: \\n'\n", " 'i. \\n'\n", " 'such medical expenses are incurred for the '\n", " 'same condition for which the insured '\n", " 'person’s hospitalisation was required, '\n", " 'and \\n'\n", " 'ii. the in-patient hospitalisation claim '\n", " 'for such hospitalisation is admissible by '\n", " 'the Company \\n'\n", " 'Post hospitalisation shall be considered '\n", " 'as part of the hospitalisation claim. \\n'\n", " ' \\n'\n", " '3.1.4 Domiciliary Hospitalisation \\n'\n", " 'The Company shall Company shall indemnify '\n", " 'the medical expenses incurred under '\n", " 'domiciliary hospitalization, including Pre',\n", " 'title': '',\n", " 'total_pages': 5.0,\n", " 'trapped': '',\n", " 'type': 'text'},\n", " 'score': 0.779073536,\n", " 'values': []}],\n", " 'namespace': 'hackrx-index2025-08-31-16-44',\n", " 'usage': {'read_units': 1}}" ] }, "execution_count": 101, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ragservice.result" ] }, { "cell_type": "code", "execution_count": null, "id": "320520fb", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 79, "id": "7d177e6e", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "dict" ] }, "execution_count": 79, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from copy import deepcopy\n", "type(deepcopy(result[0].__dict__))" ] }, { "cell_type": "code", "execution_count": 105, "id": "d2e28132", "metadata": {}, "outputs": [], "source": [ "result = ragservice.result['matches']\n" ] }, { "cell_type": "code", "execution_count": 93, "id": "730af2fe", "metadata": {}, "outputs": [], "source": [ "import json\n", "result = ragservice.result['matches']\n", "result_dicts = [r.to_dict() for r in result]\n", "context = json.dumps(result_dicts, separators=(\",\", \":\"))\n" ] }, { "cell_type": "code", "execution_count": null, "id": "5ba95e03", "metadata": {}, "outputs": [], "source": [ "llm" ] }, { "cell_type": "code", "execution_count": 102, "id": "68686b33", "metadata": {}, "outputs": [], "source": [ "def answer_query( raw_query:str) -> str:\n", " \"\"\"Answer user query using retrieved documents and LLM\"\"\"\n", " print(f\"[RAGService] Answering query: {raw_query}\")\n", " # top_clauses = self.result\n", " # if not top_clauses:\n", " # print(\"[RAGService] No relevant information found in the document.\")\n", " # return \"No relevant information found in the document.\"\n", "\n", " # context_clauses = [\n", " # f'{i+1}. (DocID: {c.doc_id}, Page: {c.page}) \"{c.text[:200]}...\"' \n", " # for i, c in enumerate(top_clauses)\n", " # ]\n", " top_clause = ragservice.result['matches']\n", " top_clause_dicts = [r.to_dict() for r in top_clause]\n", " keys_to_remove = {\"file_path\", \"source\", \"producer\", \"keywords\", \"subject\", \"added_new_keyword\", \"author\", \"chunk_id\"}\n", " for r in top_clause_dicts:\n", " meta = r.get(\"metadata\", {})\n", " for k in keys_to_remove:\n", " meta.pop(k, None)\n", "\n", " context_clauses = json.dumps(top_clause_dicts, separators=(\",\", \":\"))\n", "\n", " print(f\"context_clauses: {context_clauses}\")\n", "\n", " prompt = f\"\"\"\n", " You are a legal/insurance domain expert and policy analyst. \n", " Use the following extracted clauses from policy documents to answer the question. \n", " If you can't find the answer, say \"I don't know\".\n", " Context clauses:\n", " {\"\".join(context_clauses)}\n", " Question: {raw_query}\n", " \"\"\"\n", " print(\"[RAGService] Invoking LLM with prompt...\")\n", " response = ragservice.llm.invoke(prompt)\n", " print(f\"[RAGService] LLM response: {response}\")\n", " \n", " # Extract string content from response object\n", " if hasattr(response, 'content'):\n", " return response.content\n", " elif isinstance(response, str):\n", " return response\n", " else:\n", " return str(response)" ] }, { "cell_type": "code", "execution_count": 103, "id": "a27f9c71", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[RAGService] Answering query: Under what circumstances will the National Insurance Company Ltd. indemnify the insured or hospital for medical expenses?\n", "context_clauses: [{\"id\":\"aa5601d8-11e1-4a5f-99aa-46119946f8af\",\"score\":0.834982336,\"values\":[],\"metadata\":{\"coverage_type\":[\"Mediclaim\",\"In-Patient Care\",\"Day Care Treatment\",\"Domiciliary Hospitalisation\",\"AYUSH Treatment\"],\"creationDate\":\"\",\"creationdate\":\"\",\"creator\":\"\",\"doc_category\":[\"Insurance\"],\"doc_id\":\"52373623-1c20-4d0c-aa57-74e600da1cd7\",\"doc_type\":[\"Policy Document\",\"Mediclaim Policy\"],\"format\":\"PDF 1.7\",\"jurisdiction\":[\"India\"],\"modDate\":\"D:20250830075253Z\",\"moddate\":\"2025-08-30T07:52:53+00:00\",\"page\":0.0,\"page_no\":0.0,\"parties\":[\"National Insurance Company Ltd.\",\"Proposer\",\"Insured Persons\"],\"policy_number\":[\"NICHLIP25039V032425\"],\"text\":\"(hereinafter called the Insured Persons) and has paid the premium as consideration for such insurance. \\n \\n1 PREAMBLE \\nThe Company undertakes that if during the Policy Period, any Insured Person shall suffer any illness or disease (hereinafter called \\nIllness) or sustain any bodily injury due to an Accident (hereinafter called Injury) requiring Hospitalisation of such Insured \\nPerson(s) for In-Patient Care at any hospital/nursing home (hereinafter called Hospital) or for Day Care Treatment at any Day \\nCare Center or to undergo treatment under Domiciliary Hospitalisation, following the Medical Advice of a duly qualified Medical \\nPractitioner, the Company shall indemnify the Hospital or the Insured, Reasonable and Customary Charges incurred for Medically\",\"title\":\"\",\"total_pages\":5.0,\"trapped\":\"\",\"type\":\"text\"}},{\"id\":\"92bdedc4-44c4-46d2-a373-2ba1a7d1fd20\",\"score\":0.806417465,\"values\":[],\"metadata\":{\"coverage_type\":[\"Surgery or Surgical Procedure\",\"Hospitalisation\",\"Dental Treatment\",\"Day Care Treatment\",\"Mediclaim\",\"AYUSH Treatment\",\"Intensive Care Unit\",\"In-Patient Care\",\"Domiciliary Hospitalisation\",\"In-patient Treatment\",\"internal surgical implants\",\"Dental treatment due to injury\",\"Plastic surgery due to disease or injury\",\"Hormone replacement therapy\",\"Vitamins and tonics for treatment\",\"Circumcision for treatment\",\"Diagnostic procedures\",\"Cataract Surgery\",\"Hazardous sports treatment\",\"Pre Hospitalisation\",\"Post Hospitalisation\"],\"creationDate\":\"\",\"creationdate\":\"\",\"creator\":\"\",\"doc_category\":[\"Insurance\"],\"doc_id\":\"3b8adc99-e347-44fd-83fd-b5b27e368f0d\",\"doc_type\":[\"Policy Document\",\"Mediclaim Policy\"],\"exclusions\":[\"out-patient treatment\",\"Unproven/ Experimental Treatment\",\"Pre existing disease\",\"cosmetic surgery\",\"implants\",\"Waiting Period\",\"domiciliary treatment less than three days\",\"alternative domiciliary treatment\",\"maternity domiciliary expenses\",\"infertility domiciliary expenses\",\"Asthma in domiciliary hospitalization\",\"Bronchitis in domiciliary hospitalization\",\"Chronic nephritis in domiciliary hospitalization\",\"Nephritic syndrome in domiciliary hospitalization\",\"Diarrhoea in domiciliary hospitalization\",\"Dysenteries in domiciliary hospitalization\",\"Gastroenteritis in domiciliary hospitalization\",\"Epilepsy in domiciliary hospitalization\",\"Influenza in domiciliary hospitalization\",\"Cough and cold in domiciliary hospitalization\",\"Psychiatric disorders in domiciliary hospitalization\",\"Psychosomatic disorders in domiciliary hospitalization\",\"Pyrexia of unknown origin in domiciliary hospitalization\",\"Tonsillitis in domiciliary hospitalization\",\"Upper respiratory tract infection in domiciliary hospitalization\",\"Laryngitis in domiciliary hospitalization\",\"Pharingitis in domiciliary hospitalization\",\"Arthritis in domiciliary hospitalization\",\"Gout in domiciliary hospitalization\",\"Rheumatism in domiciliary hospitalization\"],\"format\":\"PDF 1.7\",\"jurisdiction\":[\"India\"],\"modDate\":\"D:20250830075253Z\",\"moddate\":\"2025-08-30T07:52:53+00:00\",\"page\":4.0,\"page_no\":4.0,\"parties\":[\"National Insurance Company Ltd.\",\"Insured Person\",\"Medical Practitioner\"],\"policy_number\":[\"NICHLIP25039V032425\"],\"text\":\"National Insurance Co. Ltd. \\nPremises No. 18-0374, Plot no. CBD-81, \\nNew Town, Kolkata - 700156 \\nPage 5 of 25 \\nNational Parivar Mediclaim Plus Policy \\nUIN: NICHLIP25039V032425 \\n \\n3 BENEFITS COVERED UNDER THE POLICY \\n3.1COVERAGE \\n3.1.1 In-patient Treatment \\nThe Company shall indemnify the medical expenses for: \\ni. \\nRoom charges and intensive care unit charges (including diet charges, nursing care by qualified nurse, RMO charges, \\nadministration charges for IV fluids/blood transfusion/injection), subject to limit as per Section 3.1.1.1 \\nii. Medical practitioner(s) \\niii. Anaesthesia, blood, oxygen, operation theatre charges, surgical appliances \\niv. Medicines and drugs \\nv. Diagnostic procedures\",\"title\":\"\",\"total_pages\":5.0,\"trapped\":\"\",\"type\":\"text\"}},{\"id\":\"c1e7cdf9-ad8f-4a75-af86-30268c13c7be\",\"score\":0.779073536,\"values\":[],\"metadata\":{\"coverage_type\":[\"Surgery or Surgical Procedure\",\"Hospitalisation\",\"Dental Treatment\",\"Day Care Treatment\",\"Mediclaim\",\"AYUSH Treatment\",\"Intensive Care Unit\",\"In-Patient Care\",\"Domiciliary Hospitalisation\",\"In-patient Treatment\",\"internal surgical implants\",\"Dental treatment due to injury\",\"Plastic surgery due to disease or injury\",\"Hormone replacement therapy\",\"Vitamins and tonics for treatment\",\"Circumcision for treatment\",\"Diagnostic procedures\",\"Cataract Surgery\",\"Hazardous sports treatment\",\"Pre Hospitalisation\",\"Post Hospitalisation\"],\"creationDate\":\"\",\"creationdate\":\"\",\"creator\":\"\",\"doc_category\":[\"Insurance\"],\"doc_id\":\"3b8adc99-e347-44fd-83fd-b5b27e368f0d\",\"doc_type\":[\"Policy Document\",\"Mediclaim Policy\"],\"exclusions\":[\"out-patient treatment\",\"Unproven/ Experimental Treatment\",\"Pre existing disease\",\"cosmetic surgery\",\"implants\",\"Waiting Period\",\"domiciliary treatment less than three days\",\"alternative domiciliary treatment\",\"maternity domiciliary expenses\",\"infertility domiciliary expenses\",\"Asthma in domiciliary hospitalization\",\"Bronchitis in domiciliary hospitalization\",\"Chronic nephritis in domiciliary hospitalization\",\"Nephritic syndrome in domiciliary hospitalization\",\"Diarrhoea in domiciliary hospitalization\",\"Dysenteries in domiciliary hospitalization\",\"Gastroenteritis in domiciliary hospitalization\",\"Epilepsy in domiciliary hospitalization\",\"Influenza in domiciliary hospitalization\",\"Cough and cold in domiciliary hospitalization\",\"Psychiatric disorders in domiciliary hospitalization\",\"Psychosomatic disorders in domiciliary hospitalization\",\"Pyrexia of unknown origin in domiciliary hospitalization\",\"Tonsillitis in domiciliary hospitalization\",\"Upper respiratory tract infection in domiciliary hospitalization\",\"Laryngitis in domiciliary hospitalization\",\"Pharingitis in domiciliary hospitalization\",\"Arthritis in domiciliary hospitalization\",\"Gout in domiciliary hospitalization\",\"Rheumatism in domiciliary hospitalization\"],\"format\":\"PDF 1.7\",\"jurisdiction\":[\"India\"],\"modDate\":\"D:20250830075253Z\",\"moddate\":\"2025-08-30T07:52:53+00:00\",\"page\":4.0,\"page_no\":4.0,\"parties\":[\"National Insurance Company Ltd.\",\"Insured Person\",\"Medical Practitioner\"],\"policy_number\":[\"NICHLIP25039V032425\"],\"text\":\"Pre hospitalisation shall be considered as part of the Hospitalisation claim. \\n \\n3.1.3 Post Hospitalisation \\nThe Company shall indemnify the medical expenses incurred up to sixty days immediately after the insured person is discharged \\nfrom hospital, provided that: \\ni. \\nsuch medical expenses are incurred for the same condition for which the insured person\\u2019s hospitalisation was required, and \\nii. the in-patient hospitalisation claim for such hospitalisation is admissible by the Company \\nPost hospitalisation shall be considered as part of the hospitalisation claim. \\n \\n3.1.4 Domiciliary Hospitalisation \\nThe Company shall Company shall indemnify the medical expenses incurred under domiciliary hospitalization, including Pre\",\"title\":\"\",\"total_pages\":5.0,\"trapped\":\"\",\"type\":\"text\"}}]\n", "[RAGService] Invoking LLM with prompt...\n", "[RAGService] LLM response: content='The National Insurance Company Ltd. will indemnify the insured or hospital for medical expenses under the following circumstances:\\n\\n1. **Illness, Disease, or Injury Requiring Hospitalisation:** If, during the Policy Period, any Insured Person suffers an illness or disease, or sustains a bodily injury due to an accident, requiring:\\n * Hospitalisation for In-Patient Care at any hospital/nursing home.\\n * Day Care Treatment at any Day Care Center.\\n * Treatment under Domiciliary Hospitalisation.\\n * All of the above must follow the Medical Advice of a duly qualified Medical Practitioner. The company will indemnify Reasonable and Customary Charges incurred for Medically necessary treatment.\\n\\n2. **Post Hospitalisation:** Medical expenses incurred up to sixty days immediately after the insured person is discharged from the hospital, provided that:\\n * Such medical expenses are incurred for the same condition for which the insured person’s hospitalisation was required.\\n * The in-patient hospitalisation claim for such hospitalisation is admissible by the Company.\\n\\n3. **Specific In-patient Treatment Expenses:** The company shall indemnify medical expenses for:\\n * Room charges and intensive care unit charges (including diet, nursing care, RMO charges, administration charges for IV fluids/blood transfusion/injection).\\n * Medical practitioner(s) fees.\\n * Anaesthesia, blood, oxygen, operation theatre charges, surgical appliances.\\n * Medicines and drugs.\\n * Diagnostic procedures.\\n\\n4. **Domiciliary Hospitalisation:** Medical expenses incurred under domiciliary hospitalization, including Pre-hospitalisation.' additional_kwargs={} response_metadata={'prompt_feedback': {'block_reason': 0, 'safety_ratings': []}, 'finish_reason': 'STOP', 'model_name': 'gemini-2.5-flash', 'safety_ratings': []} id='run--21a1c3ac-56a9-4f74-8a8e-72f64a1c4d06-0' usage_metadata={'input_tokens': 2038, 'output_tokens': 1591, 'total_tokens': 3629, 'input_token_details': {'cache_read': 0}, 'output_token_details': {'reasoning': 1247}}\n" ] } ], "source": [ "result = answer_query(query)" ] }, { "cell_type": "code", "execution_count": 104, "id": "00d6eec0", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'The National Insurance Company Ltd. will indemnify the insured or hospital for medical expenses under the following circumstances:\\n\\n1. **Illness, Disease, or Injury Requiring Hospitalisation:** If, during the Policy Period, any Insured Person suffers an illness or disease, or sustains a bodily injury due to an accident, requiring:\\n * Hospitalisation for In-Patient Care at any hospital/nursing home.\\n * Day Care Treatment at any Day Care Center.\\n * Treatment under Domiciliary Hospitalisation.\\n * All of the above must follow the Medical Advice of a duly qualified Medical Practitioner. The company will indemnify Reasonable and Customary Charges incurred for Medically necessary treatment.\\n\\n2. **Post Hospitalisation:** Medical expenses incurred up to sixty days immediately after the insured person is discharged from the hospital, provided that:\\n * Such medical expenses are incurred for the same condition for which the insured person’s hospitalisation was required.\\n * The in-patient hospitalisation claim for such hospitalisation is admissible by the Company.\\n\\n3. **Specific In-patient Treatment Expenses:** The company shall indemnify medical expenses for:\\n * Room charges and intensive care unit charges (including diet, nursing care, RMO charges, administration charges for IV fluids/blood transfusion/injection).\\n * Medical practitioner(s) fees.\\n * Anaesthesia, blood, oxygen, operation theatre charges, surgical appliances.\\n * Medicines and drugs.\\n * Diagnostic procedures.\\n\\n4. **Domiciliary Hospitalisation:** Medical expenses incurred under domiciliary hospitalization, including Pre-hospitalisation.'" ] }, "execution_count": 104, "metadata": {}, "output_type": "execute_result" } ], "source": [ "result" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[RAGService] Answering query: Under what circumstances will the National Insurance Company Ltd. indemnify the insured or hospital for medical expenses?\n" ] }, { "ename": "PineconeApiAttributeError", "evalue": "QueryResponse has no attribute '0' at ['['received_data']']", "output_type": "error", "traceback": [ "\u001b[31m---------------------------------------------------------------------------\u001b[39m", "\u001b[31mPineconeApiAttributeError\u001b[39m Traceback (most recent call last)", "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[14]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[43mragservice\u001b[49m\u001b[43m.\u001b[49m\u001b[43manswer_query\u001b[49m\u001b[43m(\u001b[49m\u001b[43mquery\u001b[49m\u001b[43m)\u001b[49m\n", "\u001b[36mFile \u001b[39m\u001b[32mc:\\code\\Bajaj HackRx\\Rag_app\\app\\services\\RAG_service.py:126\u001b[39m, in \u001b[36mRAGService.answer_query\u001b[39m\u001b[34m(self, raw_query)\u001b[39m\n\u001b[32m 123\u001b[39m \u001b[38;5;28mprint\u001b[39m(\u001b[33m\"\u001b[39m\u001b[33m[RAGService] No relevant information found in the document.\u001b[39m\u001b[33m\"\u001b[39m)\n\u001b[32m 124\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[33m\"\u001b[39m\u001b[33mNo relevant information found in the document.\u001b[39m\u001b[33m\"\u001b[39m\n\u001b[32m--> \u001b[39m\u001b[32m126\u001b[39m context_clauses = \u001b[43m[\u001b[49m\n\u001b[32m 127\u001b[39m \u001b[43m \u001b[49m\u001b[33;43mf\u001b[39;49m\u001b[33;43m'\u001b[39;49m\u001b[38;5;132;43;01m{\u001b[39;49;00m\u001b[43mi\u001b[49m\u001b[43m+\u001b[49m\u001b[32;43m1\u001b[39;49m\u001b[38;5;132;43;01m}\u001b[39;49;00m\u001b[33;43m. (DocID: \u001b[39;49m\u001b[38;5;132;43;01m{\u001b[39;49;00m\u001b[43mc\u001b[49m\u001b[43m.\u001b[49m\u001b[43mdoc_id\u001b[49m\u001b[38;5;132;43;01m}\u001b[39;49;00m\u001b[33;43m, Page: \u001b[39;49m\u001b[38;5;132;43;01m{\u001b[39;49;00m\u001b[43mc\u001b[49m\u001b[43m.\u001b[49m\u001b[43mpage\u001b[49m\u001b[38;5;132;43;01m}\u001b[39;49;00m\u001b[33;43m) \u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[38;5;132;43;01m{\u001b[39;49;00m\u001b[43mc\u001b[49m\u001b[43m.\u001b[49m\u001b[43mtext\u001b[49m\u001b[43m[\u001b[49m\u001b[43m:\u001b[49m\u001b[32;43m200\u001b[39;49m\u001b[43m]\u001b[49m\u001b[38;5;132;43;01m}\u001b[39;49;00m\u001b[33;43m...\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43m'\u001b[39;49m\u001b[43m \u001b[49m\n\u001b[32m 128\u001b[39m \u001b[43m \u001b[49m\u001b[38;5;28;43;01mfor\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mi\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mc\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01min\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43menumerate\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mtop_clauses\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 129\u001b[39m \u001b[43m\u001b[49m\u001b[43m]\u001b[49m\n\u001b[32m 130\u001b[39m \u001b[38;5;28mprint\u001b[39m(\u001b[33mf\u001b[39m\u001b[33m\"\u001b[39m\u001b[33mcontext_clauses: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mcontext_clauses\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m\"\u001b[39m)\n\u001b[32m 132\u001b[39m prompt = \u001b[33mf\u001b[39m\u001b[33m\"\"\"\u001b[39m\n\u001b[32m 133\u001b[39m \u001b[33mYou are a legal/insurance domain expert and policy analyst. \u001b[39m\n\u001b[32m 134\u001b[39m \u001b[33mUse the following extracted clauses from policy documents to answer the question. \u001b[39m\n\u001b[32m (...)\u001b[39m\u001b[32m 138\u001b[39m \u001b[33mQuestion: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mraw_query\u001b[38;5;132;01m}\u001b[39;00m\n\u001b[32m 139\u001b[39m \u001b[33m\u001b[39m\u001b[33m\"\"\"\u001b[39m\n", "\u001b[36mFile \u001b[39m\u001b[32mc:\\code\\Bajaj HackRx\\Rag_app\\.venv\\Lib\\site-packages\\pinecone\\openapi_support\\model_utils.py:470\u001b[39m, in \u001b[36mModelNormal.__getitem__\u001b[39m\u001b[34m(self, name)\u001b[39m\n\u001b[32m 467\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m name \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m:\n\u001b[32m 468\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m.get(name)\n\u001b[32m--> \u001b[39m\u001b[32m470\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m PineconeApiAttributeError(\n\u001b[32m 471\u001b[39m \u001b[33m\"\u001b[39m\u001b[38;5;132;01m{0}\u001b[39;00m\u001b[33m has no attribute \u001b[39m\u001b[33m'\u001b[39m\u001b[38;5;132;01m{1}\u001b[39;00m\u001b[33m'\u001b[39m\u001b[33m\"\u001b[39m.format(\u001b[38;5;28mtype\u001b[39m(\u001b[38;5;28mself\u001b[39m).\u001b[34m__name__\u001b[39m, name),\n\u001b[32m 472\u001b[39m [e \u001b[38;5;28;01mfor\u001b[39;00m e \u001b[38;5;129;01min\u001b[39;00m [\u001b[38;5;28mself\u001b[39m._path_to_item, name] \u001b[38;5;28;01mif\u001b[39;00m e],\n\u001b[32m 473\u001b[39m )\n", "\u001b[31mPineconeApiAttributeError\u001b[39m: QueryResponse has no attribute '0' at ['['received_data']']" ] } ], "source": [ "ragservice.answer_query(query)" ] } ], "metadata": { "kernelspec": { "display_name": "rag-app", "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.12.4" } }, "nbformat": 4, "nbformat_minor": 5 }