# embeddings_queue

created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 1238080f-fc68-4f72-86de-5848cdbba1e0
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Getting_started_with_Milvus_and_OpenAI.ipynb", "title": "Getting Started with Milvus and OpenAI", "tokens": 11649, "retrieve_doc": false, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"1238080f-fc68-4f72-86de-5848cdbba1e0\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Getting_started_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Getting Started with Milvus and OpenAI\", \"tokens\": 11649, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"7f3966ec-be9b-4c81-9cc2-3d3f3d4b532a\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Getting_started_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Getting Started with Milvus and OpenAI\", \"tokens\": 11649, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"08c6a77c234553e2b0977ce8ec8638a156b231ccbdf1ea631386a5119a9268d4\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"1a98da4a-702d-443c-a382-557fc0ab37b1\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Getting_started_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Getting Started with Milvus and OpenAI\", \"tokens\": 11649, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"f93ee46a07f19d85701ad559e08a5c7ba002a0d1a0efdaecad09ca357c8d4688\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"f9b72876-1b4a-4b5e-b8da-488ee722bc08\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"d6ff75ce25211dd6029a9c3b99652e2a740920ea843d6467510bb82aa1daf864\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 23198, \"end_char_idx\": 25463, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "7f3966ec-be9b-4c81-9cc2-3d3f3d4b532a", "doc_id": "7f3966ec-be9b-4c81-9cc2-3d3f3d4b532a", "ref_doc_id": "7f3966ec-be9b-4c81-9cc2-3d3f3d4b532a", "chroma:document": "```python\n# Simple function that converts the texts to embeddings\ndef embed(texts):\n    embeddings = openai.Embedding.create(\n        input=texts,\n        engine=OPENAI_ENGINE\n    )\n    return [x['embedding'] for x in embeddings['data']]\n\n```\n\nThis next step does the actual inserting. Due to having so many datapoints, if you want to immidiately test it out you can stop the inserting cell block early and move along. Doing this will probably decrease the accuracy of the results due to less datapoints, but it should still be good enough. \n\n\n```python\nfrom tqdm import tqdm\n\ndata = [\n    [], # title\n    [], # description\n]\n\n# Embed and insert in batches\nfor i in tqdm(range(0, len(dataset))):\n    data[0].append(dataset[i]['title'])\n    data[1].append(dataset[i]['description'])\n    if len(data[0]) % BATCH_SIZE == 0:\n        data.append(embed(data[1]))\n        collection.insert(data)\n        data = [[],[]]\n\n# Embed and insert the remainder \nif len(data[0]) != 0:\n    data.append(embed(data[1]))\n    collection.insert(data)\n    data = [[],[]]\n\n```\n\n      0%|          | 1999/1032335 [00:06<57:22, 299.31it/s]  \n\n\n\n    ---------------------------------------------------------------------------\n\n    KeyboardInterrupt                         Traceback (most recent call last)\n\n    Cell In[18], line 13\n         11 data[1].append(dataset[i]['description'])\n         12 if len(data[0]) % BATCH_SIZE == 0:\n    ---> 13     data.append(embed(data[1]))\n         14     collection.insert(data)\n         15     data = [[],[]]\n\n\n    Cell In[17], line 3, in embed(texts)\n          2 def embed(texts):\n    ----> 3     embeddings = openai.Embedding.create(\n          4         input=texts,\n          5         engine=OPENAI_ENGINE\n          6     )\n          7     return [x['embedding'] for x in embeddings['data']]\n\n\n    File ~/miniconda3/envs/haystack/lib/python3.9/site-packages/openai/api_resources/embedding.py:33, in Embedding.create(cls, *args, **kwargs)\n         31 while True:\n         32     try:\n    ---> 33         response = super().create(*args, **kwargs)\n         35         # If a user specifies base64, we'll just return the encoded string.\n         36         # This is only for the default case.\n         37         if not user_provided_encoding_format:"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: f9b72876-1b4a-4b5e-b8da-488ee722bc08
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Getting_started_with_Milvus_and_OpenAI.ipynb", "title": "Getting Started with Milvus and OpenAI", "tokens": 11649, "retrieve_doc": false, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"f9b72876-1b4a-4b5e-b8da-488ee722bc08\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Getting_started_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Getting Started with Milvus and OpenAI\", \"tokens\": 11649, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"7f3966ec-be9b-4c81-9cc2-3d3f3d4b532a\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Getting_started_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Getting Started with Milvus and OpenAI\", \"tokens\": 11649, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"08c6a77c234553e2b0977ce8ec8638a156b231ccbdf1ea631386a5119a9268d4\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"1238080f-fc68-4f72-86de-5848cdbba1e0\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Getting_started_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Getting Started with Milvus and OpenAI\", \"tokens\": 11649, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"3aed3aeb9c4346b8eac9f6064d9fbe60d0c474576c0effe62f028e2487981ec7\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"c6111576-3ed0-48ef-9da3-ee708ee5752a\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"ced7d2c290925705047f42c8457ce4d95c177f15d40a2cbca5292a2c41486635\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 24321, \"end_char_idx\": 27437, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "7f3966ec-be9b-4c81-9cc2-3d3f3d4b532a", "doc_id": "7f3966ec-be9b-4c81-9cc2-3d3f3d4b532a", "ref_doc_id": "7f3966ec-be9b-4c81-9cc2-3d3f3d4b532a", "chroma:document": "---------------------------------------------------------------------------\n\n    KeyboardInterrupt                         Traceback (most recent call last)\n\n    Cell In[18], line 13\n         11 data[1].append(dataset[i]['description'])\n         12 if len(data[0]) % BATCH_SIZE == 0:\n    ---> 13     data.append(embed(data[1]))\n         14     collection.insert(data)\n         15     data = [[],[]]\n\n\n    Cell In[17], line 3, in embed(texts)\n          2 def embed(texts):\n    ----> 3     embeddings = openai.Embedding.create(\n          4         input=texts,\n          5         engine=OPENAI_ENGINE\n          6     )\n          7     return [x['embedding'] for x in embeddings['data']]\n\n\n    File ~/miniconda3/envs/haystack/lib/python3.9/site-packages/openai/api_resources/embedding.py:33, in Embedding.create(cls, *args, **kwargs)\n         31 while True:\n         32     try:\n    ---> 33         response = super().create(*args, **kwargs)\n         35         # If a user specifies base64, we'll just return the encoded string.\n         36         # This is only for the default case.\n         37         if not user_provided_encoding_format:\n\n\n    File ~/miniconda3/envs/haystack/lib/python3.9/site-packages/openai/api_resources/abstract/engine_api_resource.py:153, in EngineAPIResource.create(cls, api_key, api_base, api_type, request_id, api_version, organization, **params)\n        127 @classmethod\n        128 def create(\n        129     cls,\n       (...)\n        136     **params,\n        137 ):\n        138     (\n        139         deployment_id,\n        140         engine,\n       (...)\n        150         api_key, api_base, api_type, api_version, organization, **params\n        151     )\n    --> 153     response, _, api_key = requestor.request(\n        154         \"post\",\n        155         url,\n        156         params=params,\n        157         headers=headers,\n        158         stream=stream,\n        159         request_id=request_id,\n        160         request_timeout=request_timeout,\n        161     )\n        163     if stream:\n        164         # must be an iterator\n        165         assert not isinstance(response, OpenAIResponse)\n\n\n    File ~/miniconda3/envs/haystack/lib/python3.9/site-packages/openai/api_requestor.py:216, in APIRequestor.request(self, method, url, params, headers, files, stream, request_id, request_timeout)\n        205 def request(\n        206     self,\n        207     method,\n       (...)\n        214     request_timeout: Optional[Union[float, Tuple[float, float]]] = None,\n        215 ) -> Tuple[Union[OpenAIResponse, Iterator[OpenAIResponse]], bool, str]:\n    --> 216     result = self.request_raw(\n        217         method.lower(),\n        218         url,\n        219         params=params,\n        220         supplied_headers=headers,\n        221         files=files,\n        222         stream=stream,\n        223         request_id=request_id,\n        224         request_timeout=request_timeout,\n        225     )\n        226     resp, got_stream = self._interpret_response(result, stream)\n        227     return resp, got_stream, self.api_key"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: c6111576-3ed0-48ef-9da3-ee708ee5752a
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Getting_started_with_Milvus_and_OpenAI.ipynb", "title": "Getting Started with Milvus and OpenAI", "tokens": 11649, "retrieve_doc": false, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"c6111576-3ed0-48ef-9da3-ee708ee5752a\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Getting_started_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Getting Started with Milvus and OpenAI\", \"tokens\": 11649, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"7f3966ec-be9b-4c81-9cc2-3d3f3d4b532a\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Getting_started_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Getting Started with Milvus and OpenAI\", \"tokens\": 11649, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"08c6a77c234553e2b0977ce8ec8638a156b231ccbdf1ea631386a5119a9268d4\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"f9b72876-1b4a-4b5e-b8da-488ee722bc08\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Getting_started_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Getting Started with Milvus and OpenAI\", \"tokens\": 11649, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"3de736c4e44152e84e0c3dca2e270f88ecbf06489c5bccce435ea8eaae0548bb\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"2f4c04bc-1003-45c5-924b-bf1b698b7943\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"32c1ac354de1714a15cf950b771097a2137e20c99b78824acba78f4a1f3f4d83\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 26495, \"end_char_idx\": 29058, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "7f3966ec-be9b-4c81-9cc2-3d3f3d4b532a", "doc_id": "7f3966ec-be9b-4c81-9cc2-3d3f3d4b532a", "ref_doc_id": "7f3966ec-be9b-4c81-9cc2-3d3f3d4b532a", "chroma:document": "File ~/miniconda3/envs/haystack/lib/python3.9/site-packages/openai/api_requestor.py:216, in APIRequestor.request(self, method, url, params, headers, files, stream, request_id, request_timeout)\n        205 def request(\n        206     self,\n        207     method,\n       (...)\n        214     request_timeout: Optional[Union[float, Tuple[float, float]]] = None,\n        215 ) -> Tuple[Union[OpenAIResponse, Iterator[OpenAIResponse]], bool, str]:\n    --> 216     result = self.request_raw(\n        217         method.lower(),\n        218         url,\n        219         params=params,\n        220         supplied_headers=headers,\n        221         files=files,\n        222         stream=stream,\n        223         request_id=request_id,\n        224         request_timeout=request_timeout,\n        225     )\n        226     resp, got_stream = self._interpret_response(result, stream)\n        227     return resp, got_stream, self.api_key\n\n\n    File ~/miniconda3/envs/haystack/lib/python3.9/site-packages/openai/api_requestor.py:516, in APIRequestor.request_raw(self, method, url, params, supplied_headers, files, stream, request_id, request_timeout)\n        514     _thread_context.session = _make_session()\n        515 try:\n    --> 516     result = _thread_context.session.request(\n        517         method,\n        518         abs_url,\n        519         headers=headers,\n        520         data=data,\n        521         files=files,\n        522         stream=stream,\n        523         timeout=request_timeout if request_timeout else TIMEOUT_SECS,\n        524     )\n        525 except requests.exceptions.Timeout as e:\n        526     raise error.Timeout(\"Request timed out: {}\".format(e)) from e\n\n\n    File ~/miniconda3/envs/haystack/lib/python3.9/site-packages/requests/sessions.py:587, in Session.request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)\n        582 send_kwargs = {\n        583     \"timeout\": timeout,\n        584     \"allow_redirects\": allow_redirects,\n        585 }\n        586 send_kwargs.update(settings)\n    --> 587 resp = self.send(prep, **send_kwargs)\n        589 return resp\n\n\n    File ~/miniconda3/envs/haystack/lib/python3.9/site-packages/requests/sessions.py:701, in Session.send(self, request, **kwargs)\n        698 start = preferred_clock()\n        700 # Send the request\n    --> 701 r = adapter.send(request, **kwargs)\n        703 # Total elapsed time of the request (approximately)\n        704 elapsed = preferred_clock() - start"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 2f4c04bc-1003-45c5-924b-bf1b698b7943
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Getting_started_with_Milvus_and_OpenAI.ipynb", "title": "Getting Started with Milvus and OpenAI", "tokens": 11649, "retrieve_doc": false, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"2f4c04bc-1003-45c5-924b-bf1b698b7943\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Getting_started_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Getting Started with Milvus and OpenAI\", \"tokens\": 11649, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"7f3966ec-be9b-4c81-9cc2-3d3f3d4b532a\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Getting_started_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Getting Started with Milvus and OpenAI\", \"tokens\": 11649, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"08c6a77c234553e2b0977ce8ec8638a156b231ccbdf1ea631386a5119a9268d4\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"c6111576-3ed0-48ef-9da3-ee708ee5752a\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Getting_started_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Getting Started with Milvus and OpenAI\", \"tokens\": 11649, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"62c0094a00e8625ed86bad848696844321bcea3324fed88f65575f6cfe6a8cee\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"9d0e1dbc-2464-4f27-bf73-17acc2c62445\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"0f5f41412fbe5ff3d1983a3a4f67bb81332081a5e0d476b41cd5471547d7c3ee\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 27444, \"end_char_idx\": 29891, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "7f3966ec-be9b-4c81-9cc2-3d3f3d4b532a", "doc_id": "7f3966ec-be9b-4c81-9cc2-3d3f3d4b532a", "ref_doc_id": "7f3966ec-be9b-4c81-9cc2-3d3f3d4b532a", "chroma:document": "File ~/miniconda3/envs/haystack/lib/python3.9/site-packages/openai/api_requestor.py:516, in APIRequestor.request_raw(self, method, url, params, supplied_headers, files, stream, request_id, request_timeout)\n        514     _thread_context.session = _make_session()\n        515 try:\n    --> 516     result = _thread_context.session.request(\n        517         method,\n        518         abs_url,\n        519         headers=headers,\n        520         data=data,\n        521         files=files,\n        522         stream=stream,\n        523         timeout=request_timeout if request_timeout else TIMEOUT_SECS,\n        524     )\n        525 except requests.exceptions.Timeout as e:\n        526     raise error.Timeout(\"Request timed out: {}\".format(e)) from e\n\n\n    File ~/miniconda3/envs/haystack/lib/python3.9/site-packages/requests/sessions.py:587, in Session.request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)\n        582 send_kwargs = {\n        583     \"timeout\": timeout,\n        584     \"allow_redirects\": allow_redirects,\n        585 }\n        586 send_kwargs.update(settings)\n    --> 587 resp = self.send(prep, **send_kwargs)\n        589 return resp\n\n\n    File ~/miniconda3/envs/haystack/lib/python3.9/site-packages/requests/sessions.py:701, in Session.send(self, request, **kwargs)\n        698 start = preferred_clock()\n        700 # Send the request\n    --> 701 r = adapter.send(request, **kwargs)\n        703 # Total elapsed time of the request (approximately)\n        704 elapsed = preferred_clock() - start\n\n\n    File ~/miniconda3/envs/haystack/lib/python3.9/site-packages/requests/adapters.py:489, in HTTPAdapter.send(self, request, stream, timeout, verify, cert, proxies)\n        487 try:\n        488     if not chunked:\n    --> 489         resp = conn.urlopen(\n        490             method=request.method,\n        491             url=url,\n        492             body=request.body,\n        493             headers=request.headers,\n        494             redirect=False,\n        495             assert_same_host=False,\n        496             preload_content=False,\n        497             decode_content=False,\n        498             retries=self.max_retries,\n        499             timeout=timeout,\n        500         )\n        502     # Send the request.\n        503     else:\n        504         if hasattr(conn, \"proxy_pool\"):"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 9d0e1dbc-2464-4f27-bf73-17acc2c62445
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Getting_started_with_Milvus_and_OpenAI.ipynb", "title": "Getting Started with Milvus and OpenAI", "tokens": 11649, "retrieve_doc": false, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"9d0e1dbc-2464-4f27-bf73-17acc2c62445\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Getting_started_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Getting Started with Milvus and OpenAI\", \"tokens\": 11649, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"7f3966ec-be9b-4c81-9cc2-3d3f3d4b532a\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Getting_started_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Getting Started with Milvus and OpenAI\", \"tokens\": 11649, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"08c6a77c234553e2b0977ce8ec8638a156b231ccbdf1ea631386a5119a9268d4\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"2f4c04bc-1003-45c5-924b-bf1b698b7943\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Getting_started_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Getting Started with Milvus and OpenAI\", \"tokens\": 11649, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"c72099acd4fbff3c80de864e973afd01a386cc6a99db9e8f9a7b219cb3956291\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"d386bbca-edd3-443a-97c9-b99d8b20657c\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"4c33a55a6575ff5ded176eeb4cc3934a59d14d4f93540625e72e1f42e6c0a3b0\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 28703, \"end_char_idx\": 31628, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "7f3966ec-be9b-4c81-9cc2-3d3f3d4b532a", "doc_id": "7f3966ec-be9b-4c81-9cc2-3d3f3d4b532a", "ref_doc_id": "7f3966ec-be9b-4c81-9cc2-3d3f3d4b532a", "chroma:document": "File ~/miniconda3/envs/haystack/lib/python3.9/site-packages/requests/sessions.py:701, in Session.send(self, request, **kwargs)\n        698 start = preferred_clock()\n        700 # Send the request\n    --> 701 r = adapter.send(request, **kwargs)\n        703 # Total elapsed time of the request (approximately)\n        704 elapsed = preferred_clock() - start\n\n\n    File ~/miniconda3/envs/haystack/lib/python3.9/site-packages/requests/adapters.py:489, in HTTPAdapter.send(self, request, stream, timeout, verify, cert, proxies)\n        487 try:\n        488     if not chunked:\n    --> 489         resp = conn.urlopen(\n        490             method=request.method,\n        491             url=url,\n        492             body=request.body,\n        493             headers=request.headers,\n        494             redirect=False,\n        495             assert_same_host=False,\n        496             preload_content=False,\n        497             decode_content=False,\n        498             retries=self.max_retries,\n        499             timeout=timeout,\n        500         )\n        502     # Send the request.\n        503     else:\n        504         if hasattr(conn, \"proxy_pool\"):\n\n\n    File ~/miniconda3/envs/haystack/lib/python3.9/site-packages/urllib3/connectionpool.py:703, in HTTPConnectionPool.urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)\n        700     self._prepare_proxy(conn)\n        702 # Make the request on the httplib connection object.\n    --> 703 httplib_response = self._make_request(\n        704     conn,\n        705     method,\n        706     url,\n        707     timeout=timeout_obj,\n        708     body=body,\n        709     headers=headers,\n        710     chunked=chunked,\n        711 )\n        713 # If we're going to release the connection in ``finally:``, then\n        714 # the response doesn't need to know about the connection. Otherwise\n        715 # it will also try to release it and we'll have a double-release\n        716 # mess.\n        717 response_conn = conn if not release_conn else None\n\n\n    File ~/miniconda3/envs/haystack/lib/python3.9/site-packages/urllib3/connectionpool.py:449, in HTTPConnectionPool._make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)\n        444             httplib_response = conn.getresponse()\n        445         except BaseException as e:\n        446             # Remove the TypeError from the exception chain in\n        447             # Python 3 (including for exceptions like SystemExit).\n        448             # Otherwise it looks like a bug in the code.\n    --> 449             six.raise_from(e, None)\n        450 except (SocketTimeout, BaseSSLError, SocketError) as e:\n        451     self._raise_timeout(err=e, url=url, timeout_value=read_timeout)\n\n\n    File <string>:3, in raise_from(value, from_value)"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: d386bbca-edd3-443a-97c9-b99d8b20657c
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Getting_started_with_Milvus_and_OpenAI.ipynb", "title": "Getting Started with Milvus and OpenAI", "tokens": 11649, "retrieve_doc": false, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"d386bbca-edd3-443a-97c9-b99d8b20657c\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Getting_started_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Getting Started with Milvus and OpenAI\", \"tokens\": 11649, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"7f3966ec-be9b-4c81-9cc2-3d3f3d4b532a\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Getting_started_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Getting Started with Milvus and OpenAI\", \"tokens\": 11649, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"08c6a77c234553e2b0977ce8ec8638a156b231ccbdf1ea631386a5119a9268d4\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"9d0e1dbc-2464-4f27-bf73-17acc2c62445\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Getting_started_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Getting Started with Milvus and OpenAI\", \"tokens\": 11649, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"1f4c83096ae27d2fb38ca9e6b6b49ecd418e42a02687c9730e1f4cc90f75da87\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"adb7d01c-7e47-4234-9a08-225199189c58\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"5b9413599f83f9778509110fc9e2752a98b353bf9474ce9d1b1d859e87c7b56c\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 30853, \"end_char_idx\": 33404, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "7f3966ec-be9b-4c81-9cc2-3d3f3d4b532a", "doc_id": "7f3966ec-be9b-4c81-9cc2-3d3f3d4b532a", "ref_doc_id": "7f3966ec-be9b-4c81-9cc2-3d3f3d4b532a", "chroma:document": "File ~/miniconda3/envs/haystack/lib/python3.9/site-packages/urllib3/connectionpool.py:449, in HTTPConnectionPool._make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)\n        444             httplib_response = conn.getresponse()\n        445         except BaseException as e:\n        446             # Remove the TypeError from the exception chain in\n        447             # Python 3 (including for exceptions like SystemExit).\n        448             # Otherwise it looks like a bug in the code.\n    --> 449             six.raise_from(e, None)\n        450 except (SocketTimeout, BaseSSLError, SocketError) as e:\n        451     self._raise_timeout(err=e, url=url, timeout_value=read_timeout)\n\n\n    File <string>:3, in raise_from(value, from_value)\n\n\n    File ~/miniconda3/envs/haystack/lib/python3.9/site-packages/urllib3/connectionpool.py:444, in HTTPConnectionPool._make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)\n        441 except TypeError:\n        442     # Python 3\n        443     try:\n    --> 444         httplib_response = conn.getresponse()\n        445     except BaseException as e:\n        446         # Remove the TypeError from the exception chain in\n        447         # Python 3 (including for exceptions like SystemExit).\n        448         # Otherwise it looks like a bug in the code.\n        449         six.raise_from(e, None)\n\n\n    File ~/miniconda3/envs/haystack/lib/python3.9/http/client.py:1377, in HTTPConnection.getresponse(self)\n       1375 try:\n       1376     try:\n    -> 1377         response.begin()\n       1378     except ConnectionError:\n       1379         self.close()\n\n\n    File ~/miniconda3/envs/haystack/lib/python3.9/http/client.py:320, in HTTPResponse.begin(self)\n        318 # read until we get a non-100 response\n        319 while True:\n    --> 320     version, status, reason = self._read_status()\n        321     if status != CONTINUE:\n        322         break\n\n\n    File ~/miniconda3/envs/haystack/lib/python3.9/http/client.py:281, in HTTPResponse._read_status(self)\n        280 def _read_status(self):\n    --> 281     line = str(self.fp.readline(_MAXLINE + 1), \"iso-8859-1\")\n        282     if len(line) > _MAXLINE:\n        283         raise LineTooLong(\"status line\")\n\n\n    File ~/miniconda3/envs/haystack/lib/python3.9/socket.py:704, in SocketIO.readinto(self, b)\n        702 while True:\n        703     try:\n    --> 704         return self._sock.recv_into(b)\n        705     except timeout:\n        706         self._timeout_occurred = True"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: adb7d01c-7e47-4234-9a08-225199189c58
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Getting_started_with_Milvus_and_OpenAI.ipynb", "title": "Getting Started with Milvus and OpenAI", "tokens": 11649, "retrieve_doc": false, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"adb7d01c-7e47-4234-9a08-225199189c58\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Getting_started_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Getting Started with Milvus and OpenAI\", \"tokens\": 11649, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"7f3966ec-be9b-4c81-9cc2-3d3f3d4b532a\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Getting_started_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Getting Started with Milvus and OpenAI\", \"tokens\": 11649, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"08c6a77c234553e2b0977ce8ec8638a156b231ccbdf1ea631386a5119a9268d4\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"d386bbca-edd3-443a-97c9-b99d8b20657c\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Getting_started_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Getting Started with Milvus and OpenAI\", \"tokens\": 11649, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"09ecd8f113b9c3da0654820b963de9fe292584089e20c3185e823a212d611da3\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"613a6cfb-9f4c-4478-b3cd-9979af25de9e\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"d4ca4518f0f25df700197279255ff974056451eb23c8b5bf14c92496b43590ee\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 32267, \"end_char_idx\": 35058, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "7f3966ec-be9b-4c81-9cc2-3d3f3d4b532a", "doc_id": "7f3966ec-be9b-4c81-9cc2-3d3f3d4b532a", "ref_doc_id": "7f3966ec-be9b-4c81-9cc2-3d3f3d4b532a", "chroma:document": "File ~/miniconda3/envs/haystack/lib/python3.9/http/client.py:1377, in HTTPConnection.getresponse(self)\n       1375 try:\n       1376     try:\n    -> 1377         response.begin()\n       1378     except ConnectionError:\n       1379         self.close()\n\n\n    File ~/miniconda3/envs/haystack/lib/python3.9/http/client.py:320, in HTTPResponse.begin(self)\n        318 # read until we get a non-100 response\n        319 while True:\n    --> 320     version, status, reason = self._read_status()\n        321     if status != CONTINUE:\n        322         break\n\n\n    File ~/miniconda3/envs/haystack/lib/python3.9/http/client.py:281, in HTTPResponse._read_status(self)\n        280 def _read_status(self):\n    --> 281     line = str(self.fp.readline(_MAXLINE + 1), \"iso-8859-1\")\n        282     if len(line) > _MAXLINE:\n        283         raise LineTooLong(\"status line\")\n\n\n    File ~/miniconda3/envs/haystack/lib/python3.9/socket.py:704, in SocketIO.readinto(self, b)\n        702 while True:\n        703     try:\n    --> 704         return self._sock.recv_into(b)\n        705     except timeout:\n        706         self._timeout_occurred = True\n\n\n    File ~/miniconda3/envs/haystack/lib/python3.9/ssl.py:1242, in SSLSocket.recv_into(self, buffer, nbytes, flags)\n       1238     if flags != 0:\n       1239         raise ValueError(\n       1240           \"non-zero flags not allowed in calls to recv_into() on %s\" %\n       1241           self.__class__)\n    -> 1242     return self.read(nbytes, buffer)\n       1243 else:\n       1244     return super().recv_into(buffer, nbytes, flags)\n\n\n    File ~/miniconda3/envs/haystack/lib/python3.9/ssl.py:1100, in SSLSocket.read(self, len, buffer)\n       1098 try:\n       1099     if buffer is not None:\n    -> 1100         return self._sslobj.read(len, buffer)\n       1101     else:\n       1102         return self._sslobj.read(len)\n\n\n    KeyboardInterrupt: \n\n\n## Query the Database\nWith our data safely inserted in Milvus, we can now perform a query. The query takes in a string or a list of strings and searches them. The resuts print out your provided description and the results that include the result score, the result title, and the result book description. \n\n\n```python\nimport textwrap\n\ndef query(queries, top_k = 5):\n    if type(queries) != list:\n        queries = [queries]\n    res = collection.search(embed(queries), anns_field='embedding', param=QUERY_PARAM, limit = top_k, output_fields=['title', 'description'])\n    for i, hit in enumerate(res):\n        print('Description:', queries[i])\n        print('Results:')\n        for ii, hits in enumerate(hit):\n            print('\\t' + 'Rank:', ii + 1, 'Score:', hits.score, 'Title:', hits.entity.get('title'))\n            print(textwrap.fill(hits.entity.get('description'), 88))\n            print()\n```"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 613a6cfb-9f4c-4478-b3cd-9979af25de9e
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Getting_started_with_Milvus_and_OpenAI.ipynb", "title": "Getting Started with Milvus and OpenAI", "tokens": 11649, "retrieve_doc": false, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"613a6cfb-9f4c-4478-b3cd-9979af25de9e\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Getting_started_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Getting Started with Milvus and OpenAI\", \"tokens\": 11649, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"7f3966ec-be9b-4c81-9cc2-3d3f3d4b532a\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Getting_started_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Getting Started with Milvus and OpenAI\", \"tokens\": 11649, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"08c6a77c234553e2b0977ce8ec8638a156b231ccbdf1ea631386a5119a9268d4\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"adb7d01c-7e47-4234-9a08-225199189c58\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Getting_started_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Getting Started with Milvus and OpenAI\", \"tokens\": 11649, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"e159f8b326b97c6c38c1395c0ada681408ed3b49860afb7f9748df16c68a7912\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"0ae86e5d-e49b-4ee5-b29b-312f59b58f48\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"298e4ad1cca7c341fbdc4d4a9ebbec3851271fe8f097e0be9daa102dd65c4d05\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 33849, \"end_char_idx\": 36671, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "7f3966ec-be9b-4c81-9cc2-3d3f3d4b532a", "doc_id": "7f3966ec-be9b-4c81-9cc2-3d3f3d4b532a", "ref_doc_id": "7f3966ec-be9b-4c81-9cc2-3d3f3d4b532a", "chroma:document": "File ~/miniconda3/envs/haystack/lib/python3.9/ssl.py:1100, in SSLSocket.read(self, len, buffer)\n       1098 try:\n       1099     if buffer is not None:\n    -> 1100         return self._sslobj.read(len, buffer)\n       1101     else:\n       1102         return self._sslobj.read(len)\n\n\n    KeyboardInterrupt: \n\n\n## Query the Database\nWith our data safely inserted in Milvus, we can now perform a query. The query takes in a string or a list of strings and searches them. The resuts print out your provided description and the results that include the result score, the result title, and the result book description. \n\n\n```python\nimport textwrap\n\ndef query(queries, top_k = 5):\n    if type(queries) != list:\n        queries = [queries]\n    res = collection.search(embed(queries), anns_field='embedding', param=QUERY_PARAM, limit = top_k, output_fields=['title', 'description'])\n    for i, hit in enumerate(res):\n        print('Description:', queries[i])\n        print('Results:')\n        for ii, hits in enumerate(hit):\n            print('\\t' + 'Rank:', ii + 1, 'Score:', hits.score, 'Title:', hits.entity.get('title'))\n            print(textwrap.fill(hits.entity.get('description'), 88))\n            print()\n```\n\n\n```python\nquery('Book about a k-9 from europe')\n```\n\n    RPC error: [search], <MilvusException: (code=1, message=code: UnexpectedError, reason: code: CollectionNotExists, reason: can't find collection: book_search)>, <Time:{'RPC start': '2023-03-17 14:22:18.368461', 'RPC error': '2023-03-17 14:22:18.382086'}>\n\n\n\n    ---------------------------------------------------------------------------\n\n    MilvusException                           Traceback (most recent call last)\n\n    Cell In[32], line 1\n    ----> 1 query('Book about a k-9 from europe')\n\n\n    Cell In[31], line 6, in query(queries, top_k)\n          4 if type(queries) != list:\n          5     queries = [queries]\n    ----> 6 res = collection.search(embed(queries), anns_field='embedding', param=QUERY_PARAM, limit = top_k, output_fields=['title', 'description'])\n          7 for i, hit in enumerate(res):\n          8     print('Description:', queries[i])\n\n\n    File ~/miniconda3/envs/haystack/lib/python3.9/site-packages/pymilvus/orm/collection.py:614, in Collection.search(self, data, anns_field, param, limit, expr, partition_names, output_fields, timeout, round_decimal, **kwargs)\n        611     raise DataTypeNotMatchException(message=ExceptionsMessage.ExprType % type(expr))\n        613 conn = self._get_connection()\n    --> 614 res = conn.search(self._name, data, anns_field, param, limit, expr,\n        615                   partition_names, output_fields, round_decimal, timeout=timeout,\n        616                   schema=self._schema_dict, **kwargs)\n        617 if kwargs.get(\"_async\", False):\n        618     return SearchFuture(res)"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 0ae86e5d-e49b-4ee5-b29b-312f59b58f48
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Getting_started_with_Milvus_and_OpenAI.ipynb", "title": "Getting Started with Milvus and OpenAI", "tokens": 11649, "retrieve_doc": false, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"0ae86e5d-e49b-4ee5-b29b-312f59b58f48\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Getting_started_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Getting Started with Milvus and OpenAI\", \"tokens\": 11649, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"7f3966ec-be9b-4c81-9cc2-3d3f3d4b532a\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Getting_started_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Getting Started with Milvus and OpenAI\", \"tokens\": 11649, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"08c6a77c234553e2b0977ce8ec8638a156b231ccbdf1ea631386a5119a9268d4\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"613a6cfb-9f4c-4478-b3cd-9979af25de9e\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Getting_started_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Getting Started with Milvus and OpenAI\", \"tokens\": 11649, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"533b414558c74f563a3d04194b595215b1d930a9269312d4438d9721a4d0cc93\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"44b9b5e3-0c40-45c5-b238-d33a9b59c61a\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"d45753293a9531e227d0e23d0a52f666557917e516b676cdc371ddc8416ed92b\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 35379, \"end_char_idx\": 38226, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "7f3966ec-be9b-4c81-9cc2-3d3f3d4b532a", "doc_id": "7f3966ec-be9b-4c81-9cc2-3d3f3d4b532a", "ref_doc_id": "7f3966ec-be9b-4c81-9cc2-3d3f3d4b532a", "chroma:document": "---------------------------------------------------------------------------\n\n    MilvusException                           Traceback (most recent call last)\n\n    Cell In[32], line 1\n    ----> 1 query('Book about a k-9 from europe')\n\n\n    Cell In[31], line 6, in query(queries, top_k)\n          4 if type(queries) != list:\n          5     queries = [queries]\n    ----> 6 res = collection.search(embed(queries), anns_field='embedding', param=QUERY_PARAM, limit = top_k, output_fields=['title', 'description'])\n          7 for i, hit in enumerate(res):\n          8     print('Description:', queries[i])\n\n\n    File ~/miniconda3/envs/haystack/lib/python3.9/site-packages/pymilvus/orm/collection.py:614, in Collection.search(self, data, anns_field, param, limit, expr, partition_names, output_fields, timeout, round_decimal, **kwargs)\n        611     raise DataTypeNotMatchException(message=ExceptionsMessage.ExprType % type(expr))\n        613 conn = self._get_connection()\n    --> 614 res = conn.search(self._name, data, anns_field, param, limit, expr,\n        615                   partition_names, output_fields, round_decimal, timeout=timeout,\n        616                   schema=self._schema_dict, **kwargs)\n        617 if kwargs.get(\"_async\", False):\n        618     return SearchFuture(res)\n\n\n    File ~/miniconda3/envs/haystack/lib/python3.9/site-packages/pymilvus/decorators.py:109, in error_handler.<locals>.wrapper.<locals>.handler(*args, **kwargs)\n        107     record_dict[\"RPC error\"] = str(datetime.datetime.now())\n        108     LOGGER.error(f\"RPC error: [{inner_name}], {e}, <Time:{record_dict}>\")\n    --> 109     raise e\n        110 except grpc.FutureTimeoutError as e:\n        111     record_dict[\"gRPC timeout\"] = str(datetime.datetime.now())\n\n\n    File ~/miniconda3/envs/haystack/lib/python3.9/site-packages/pymilvus/decorators.py:105, in error_handler.<locals>.wrapper.<locals>.handler(*args, **kwargs)\n        103 try:\n        104     record_dict[\"RPC start\"] = str(datetime.datetime.now())\n    --> 105     return func(*args, **kwargs)\n        106 except MilvusException as e:\n        107     record_dict[\"RPC error\"] = str(datetime.datetime.now())\n\n\n    File ~/miniconda3/envs/haystack/lib/python3.9/site-packages/pymilvus/decorators.py:136, in tracing_request.<locals>.wrapper.<locals>.handler(self, *args, **kwargs)\n        134 if req_id:\n        135     self.set_onetime_request_id(req_id)\n    --> 136 ret = func(self, *args, **kwargs)\n        137 return ret\n\n\n    File ~/miniconda3/envs/haystack/lib/python3.9/site-packages/pymilvus/decorators.py:85, in retry_on_rpc_failure.<locals>.wrapper.<locals>.handler(self, *args, **kwargs)\n         83         back_off = min(back_off * back_off_multiplier, max_back_off)\n         84     else:\n    ---> 85         raise e\n         86 except Exception as e:\n         87     raise e"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 44b9b5e3-0c40-45c5-b238-d33a9b59c61a
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Getting_started_with_Milvus_and_OpenAI.ipynb", "title": "Getting Started with Milvus and OpenAI", "tokens": 11649, "retrieve_doc": false, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"44b9b5e3-0c40-45c5-b238-d33a9b59c61a\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Getting_started_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Getting Started with Milvus and OpenAI\", \"tokens\": 11649, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"7f3966ec-be9b-4c81-9cc2-3d3f3d4b532a\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Getting_started_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Getting Started with Milvus and OpenAI\", \"tokens\": 11649, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"08c6a77c234553e2b0977ce8ec8638a156b231ccbdf1ea631386a5119a9268d4\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"0ae86e5d-e49b-4ee5-b29b-312f59b58f48\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Getting_started_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Getting Started with Milvus and OpenAI\", \"tokens\": 11649, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"64b28ca6d8851b18c09707ff44bba3d2b96ce446a680cd7e0527565faf121f55\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"066c7299-a04a-4b4f-9a00-e190fdb3d33d\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"133309850c8fdd5b5181d4e47f2d5e41ee9080f6d2a40e4b79926de739e57461\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 37146, \"end_char_idx\": 39952, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "7f3966ec-be9b-4c81-9cc2-3d3f3d4b532a", "doc_id": "7f3966ec-be9b-4c81-9cc2-3d3f3d4b532a", "ref_doc_id": "7f3966ec-be9b-4c81-9cc2-3d3f3d4b532a", "chroma:document": "File ~/miniconda3/envs/haystack/lib/python3.9/site-packages/pymilvus/decorators.py:105, in error_handler.<locals>.wrapper.<locals>.handler(*args, **kwargs)\n        103 try:\n        104     record_dict[\"RPC start\"] = str(datetime.datetime.now())\n    --> 105     return func(*args, **kwargs)\n        106 except MilvusException as e:\n        107     record_dict[\"RPC error\"] = str(datetime.datetime.now())\n\n\n    File ~/miniconda3/envs/haystack/lib/python3.9/site-packages/pymilvus/decorators.py:136, in tracing_request.<locals>.wrapper.<locals>.handler(self, *args, **kwargs)\n        134 if req_id:\n        135     self.set_onetime_request_id(req_id)\n    --> 136 ret = func(self, *args, **kwargs)\n        137 return ret\n\n\n    File ~/miniconda3/envs/haystack/lib/python3.9/site-packages/pymilvus/decorators.py:85, in retry_on_rpc_failure.<locals>.wrapper.<locals>.handler(self, *args, **kwargs)\n         83         back_off = min(back_off * back_off_multiplier, max_back_off)\n         84     else:\n    ---> 85         raise e\n         86 except Exception as e:\n         87     raise e\n\n\n    File ~/miniconda3/envs/haystack/lib/python3.9/site-packages/pymilvus/decorators.py:50, in retry_on_rpc_failure.<locals>.wrapper.<locals>.handler(self, *args, **kwargs)\n         48 while True:\n         49     try:\n    ---> 50         return func(self, *args, **kwargs)\n         51     except grpc.RpcError as e:\n         52         # DEADLINE_EXCEEDED means that the task wat not completed\n         53         # UNAVAILABLE means that the service is not reachable currently\n         54         # Reference: https://grpc.github.io/grpc/python/grpc.html#grpc-status-code\n         55         if e.code() != grpc.StatusCode.DEADLINE_EXCEEDED and e.code() != grpc.StatusCode.UNAVAILABLE:\n\n\n    File ~/miniconda3/envs/haystack/lib/python3.9/site-packages/pymilvus/client/grpc_handler.py:472, in GrpcHandler.search(self, collection_name, data, anns_field, param, limit, expression, partition_names, output_fields, round_decimal, timeout, schema, **kwargs)\n        467 requests = Prepare.search_requests_with_expr(collection_name, data, anns_field, param, limit, schema,\n        468                                              expression, partition_names, output_fields, round_decimal,\n        469                                              **kwargs)\n        471 auto_id = schema[\"auto_id\"]\n    --> 472 return self._execute_search_requests(requests, timeout, round_decimal=round_decimal, auto_id=auto_id, **kwargs)\n\n\n    File ~/miniconda3/envs/haystack/lib/python3.9/site-packages/pymilvus/client/grpc_handler.py:441, in GrpcHandler._execute_search_requests(self, requests, timeout, **kwargs)\n        439 if kwargs.get(\"_async\", False):\n        440     return SearchFuture(None, None, True, pre_err)\n    --> 441 raise pre_err"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 066c7299-a04a-4b4f-9a00-e190fdb3d33d
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Getting_started_with_Milvus_and_OpenAI.ipynb", "title": "Getting Started with Milvus and OpenAI", "tokens": 11649, "retrieve_doc": false, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"066c7299-a04a-4b4f-9a00-e190fdb3d33d\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Getting_started_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Getting Started with Milvus and OpenAI\", \"tokens\": 11649, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"7f3966ec-be9b-4c81-9cc2-3d3f3d4b532a\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Getting_started_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Getting Started with Milvus and OpenAI\", \"tokens\": 11649, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"08c6a77c234553e2b0977ce8ec8638a156b231ccbdf1ea631386a5119a9268d4\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"44b9b5e3-0c40-45c5-b238-d33a9b59c61a\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Getting_started_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Getting Started with Milvus and OpenAI\", \"tokens\": 11649, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"067b55775ce39e9624222edb20fdb3e26584abb1ce5cc5a0fcc56213e6d21ad5\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 38921, \"end_char_idx\": 40606, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "7f3966ec-be9b-4c81-9cc2-3d3f3d4b532a", "doc_id": "7f3966ec-be9b-4c81-9cc2-3d3f3d4b532a", "ref_doc_id": "7f3966ec-be9b-4c81-9cc2-3d3f3d4b532a", "chroma:document": "File ~/miniconda3/envs/haystack/lib/python3.9/site-packages/pymilvus/client/grpc_handler.py:472, in GrpcHandler.search(self, collection_name, data, anns_field, param, limit, expression, partition_names, output_fields, round_decimal, timeout, schema, **kwargs)\n        467 requests = Prepare.search_requests_with_expr(collection_name, data, anns_field, param, limit, schema,\n        468                                              expression, partition_names, output_fields, round_decimal,\n        469                                              **kwargs)\n        471 auto_id = schema[\"auto_id\"]\n    --> 472 return self._execute_search_requests(requests, timeout, round_decimal=round_decimal, auto_id=auto_id, **kwargs)\n\n\n    File ~/miniconda3/envs/haystack/lib/python3.9/site-packages/pymilvus/client/grpc_handler.py:441, in GrpcHandler._execute_search_requests(self, requests, timeout, **kwargs)\n        439 if kwargs.get(\"_async\", False):\n        440     return SearchFuture(None, None, True, pre_err)\n    --> 441 raise pre_err\n\n\n    File ~/miniconda3/envs/haystack/lib/python3.9/site-packages/pymilvus/client/grpc_handler.py:432, in GrpcHandler._execute_search_requests(self, requests, timeout, **kwargs)\n        429     response = self._stub.Search(request, timeout=timeout)\n        431     if response.status.error_code != 0:\n    --> 432         raise MilvusException(response.status.error_code, response.status.reason)\n        434     raws.append(response)\n        435 round_decimal = kwargs.get(\"round_decimal\", -1)\n\n\n    MilvusException: <MilvusException: (code=1, message=code: UnexpectedError, reason: code: CollectionNotExists, reason: can't find collection: book_search)>"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 1782b7fa-8859-4b43-af51-e883ba1c90fb
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Filtered_search_with_Milvus_and_OpenAI.ipynb", "title": "Filtered Search with Milvus and OpenAI", "tokens": 4573, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"1782b7fa-8859-4b43-af51-e883ba1c90fb\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Filtered_search_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Filtered Search with Milvus and OpenAI\", \"tokens\": 4573, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"056f7cdd-2c42-4c80-a90e-2e070d777fea\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Filtered_search_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Filtered Search with Milvus and OpenAI\", \"tokens\": 4573, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"b1fa81ddbfee65f19b82c729d479c7525a55e4d249536b13a4536660d026db49\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"d12aefcd-866b-4fdd-9883-10d2b54661d6\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"86516a7d5b93f7a6e9d67edcf6290f226b59183d833778e2ded412058337ffba\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 0, \"end_char_idx\": 2678, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "056f7cdd-2c42-4c80-a90e-2e070d777fea", "doc_id": "056f7cdd-2c42-4c80-a90e-2e070d777fea", "ref_doc_id": "056f7cdd-2c42-4c80-a90e-2e070d777fea", "chroma:document": "# Filtered Search with Milvus and OpenAI\n### Finding your next movie\n\nIn this notebook we will be going over generating embeddings of movie descriptions with OpenAI and using those embeddings within Milvus to find relevant movies. To narrow our search results and try something new, we are going to be using filtering to do metadata searches. The dataset in this example is sourced from HuggingFace datasets, and contains a little over 8 thousand movie entries.\n\nLets begin by first downloading the required libraries for this notebook:\n- `openai` is used for communicating with the OpenAI embedding service\n- `pymilvus` is used for communicating with the Milvus server\n- `datasets` is used for downloading the dataset\n- `tqdm` is used for the progress bars\n\n\n\n```python\n! pip install openai pymilvus datasets tqdm\n```\n\nWith the required packages installed we can get started. Lets begin by launching the Milvus service. The file being run is the `docker-compose.yaml` found in the folder of this file. This command launches a Milvus standalone instance which we will use for this test.  \n\n\n```python\n! docker compose up -d\n```\n\n    E0317 14:06:38.344884000 140704629352640 fork_posix.cc:76]             Other threads are currently calling into gRPC, skipping fork() handlers\n\n\n    \u001b[1A\u001b[1B\u001b[0G\u001b[?25l[+] Running 1/0\n    \u001b[34m \u283f Network milvus          Created                                         0.1s\n    \u001b[0m\u001b[37m \u280b Container milvus-etcd   Creating                                        0.0s\n    \u001b[0m\u001b[37m \u280b Container milvus-minio  Creating                                        0.0s\n    \u001b[0m\u001b[?25h\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[0G\u001b[?25l[+] Running 1/3\n    \u001b[34m \u283f Network milvus          Created                                         0.1s\n    \u001b[0m\u001b[37m \u2819 Container milvus-etcd   Creating                                        0.1s\n    \u001b[0m\u001b[37m \u2819 Container milvus-minio  Creating                                        0.1s\n    \u001b[0m\u001b[?25h\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[0G\u001b[?25l[+] Running 2/3\n    \u001b[34m \u283f Network milvus               Created                                    0.1s\n    \u001b[0m\u001b[37m \u283f Container milvus-etcd        Starting                                   0.2s\n    \u001b[0m\u001b[37m \u283f Container milvus-minio       Starting                                   0.2s\n    \u001b[0m\u001b[34m \u283f Container milvus-standalone  Created                                    0.1s\n    \u001b[0m\u001b[?25h\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[0G\u001b[?25l[+] Running 2/4\n    \u001b[34m \u283f Network milvus               Created                                    0.1s\n    \u001b[0m\u001b[37m \u283f Container milvus-etcd        Starting                                   0.3s\n    \u001b[0m\u001b[37m \u283f Container milvus-minio       Starting                                   0."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: d12aefcd-866b-4fdd-9883-10d2b54661d6
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Filtered_search_with_Milvus_and_OpenAI.ipynb", "title": "Filtered Search with Milvus and OpenAI", "tokens": 4573, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"d12aefcd-866b-4fdd-9883-10d2b54661d6\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Filtered_search_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Filtered Search with Milvus and OpenAI\", \"tokens\": 4573, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"056f7cdd-2c42-4c80-a90e-2e070d777fea\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Filtered_search_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Filtered Search with Milvus and OpenAI\", \"tokens\": 4573, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"b1fa81ddbfee65f19b82c729d479c7525a55e4d249536b13a4536660d026db49\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"1782b7fa-8859-4b43-af51-e883ba1c90fb\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Filtered_search_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Filtered Search with Milvus and OpenAI\", \"tokens\": 4573, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"88860f81230f09977a640970b35c10ea662969cbcf964f7eeba9bf036c8b396c\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"c10690ee-62fe-42b2-bb8f-5f61bfee7875\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"6ee8822d128cd4f0cc801be5c4b0c23187981e9cc50572db695d408933e7e6ec\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 1495, \"end_char_idx\": 3776, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "056f7cdd-2c42-4c80-a90e-2e070d777fea", "doc_id": "056f7cdd-2c42-4c80-a90e-2e070d777fea", "ref_doc_id": "056f7cdd-2c42-4c80-a90e-2e070d777fea", "chroma:document": "0s\n    \u001b[0m\u001b[37m \u280b Container milvus-minio  Creating                                        0.0s\n    \u001b[0m\u001b[?25h\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[0G\u001b[?25l[+] Running 1/3\n    \u001b[34m \u283f Network milvus          Created                                         0.1s\n    \u001b[0m\u001b[37m \u2819 Container milvus-etcd   Creating                                        0.1s\n    \u001b[0m\u001b[37m \u2819 Container milvus-minio  Creating                                        0.1s\n    \u001b[0m\u001b[?25h\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[0G\u001b[?25l[+] Running 2/3\n    \u001b[34m \u283f Network milvus               Created                                    0.1s\n    \u001b[0m\u001b[37m \u283f Container milvus-etcd        Starting                                   0.2s\n    \u001b[0m\u001b[37m \u283f Container milvus-minio       Starting                                   0.2s\n    \u001b[0m\u001b[34m \u283f Container milvus-standalone  Created                                    0.1s\n    \u001b[0m\u001b[?25h\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[0G\u001b[?25l[+] Running 2/4\n    \u001b[34m \u283f Network milvus               Created                                    0.1s\n    \u001b[0m\u001b[37m \u283f Container milvus-etcd        Starting                                   0.3s\n    \u001b[0m\u001b[37m \u283f Container milvus-minio       Starting                                   0.3s\n    \u001b[0m\u001b[34m \u283f Container milvus-standalone  Created                                    0.1s\n    \u001b[0m\u001b[?25h\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[0G\u001b[?25l[+] Running 2/4\n    \u001b[34m \u283f Network milvus               Created                                    0.1s\n    \u001b[0m\u001b[37m \u283f Container milvus-etcd        Starting                                   0.4s\n    \u001b[0m\u001b[37m \u283f Container milvus-minio       Starting                                   0.4s\n    \u001b[0m\u001b[34m \u283f Container milvus-standalone  Created                                    0.1s\n    \u001b[0m\u001b[?25h\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[0G\u001b[?25l[+] Running 2/4\n    \u001b[34m \u283f Network milvus               Created                                    0.1s\n    \u001b[0m\u001b[37m \u283f Container milvus-etcd        Starting                                   0.5s\n    \u001b[0m\u001b[37m \u283f Container milvus-minio       Starting                                   0.5s\n    \u001b[0m\u001b[34m \u283f Container milvus-standalone  Created                                    0.1s\n    \u001b[0m\u001b[?25h\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[0G\u001b[?25l[+] Running 2/4\n    \u001b[34m \u283f Network milvus               Created                                    0."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: c10690ee-62fe-42b2-bb8f-5f61bfee7875
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Filtered_search_with_Milvus_and_OpenAI.ipynb", "title": "Filtered Search with Milvus and OpenAI", "tokens": 4573, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"c10690ee-62fe-42b2-bb8f-5f61bfee7875\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Filtered_search_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Filtered Search with Milvus and OpenAI\", \"tokens\": 4573, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"056f7cdd-2c42-4c80-a90e-2e070d777fea\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Filtered_search_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Filtered Search with Milvus and OpenAI\", \"tokens\": 4573, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"b1fa81ddbfee65f19b82c729d479c7525a55e4d249536b13a4536660d026db49\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"d12aefcd-866b-4fdd-9883-10d2b54661d6\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Filtered_search_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Filtered Search with Milvus and OpenAI\", \"tokens\": 4573, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"e55f29224e6ebacba563fe36eaaf9f7631af269ef3c6463a47cda997e7491bef\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"2fd0c561-3396-4786-a06a-d4d1665dfd01\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"666e14a0e55239bb9929a0cf095e07f7bd8bd9021f598f3f27ea8b745eb8d2e8\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 2585, \"end_char_idx\": 4911, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "056f7cdd-2c42-4c80-a90e-2e070d777fea", "doc_id": "056f7cdd-2c42-4c80-a90e-2e070d777fea", "ref_doc_id": "056f7cdd-2c42-4c80-a90e-2e070d777fea", "chroma:document": "3s\n    \u001b[0m\u001b[37m \u283f Container milvus-minio       Starting                                   0.3s\n    \u001b[0m\u001b[34m \u283f Container milvus-standalone  Created                                    0.1s\n    \u001b[0m\u001b[?25h\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[0G\u001b[?25l[+] Running 2/4\n    \u001b[34m \u283f Network milvus               Created                                    0.1s\n    \u001b[0m\u001b[37m \u283f Container milvus-etcd        Starting                                   0.4s\n    \u001b[0m\u001b[37m \u283f Container milvus-minio       Starting                                   0.4s\n    \u001b[0m\u001b[34m \u283f Container milvus-standalone  Created                                    0.1s\n    \u001b[0m\u001b[?25h\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[0G\u001b[?25l[+] Running 2/4\n    \u001b[34m \u283f Network milvus               Created                                    0.1s\n    \u001b[0m\u001b[37m \u283f Container milvus-etcd        Starting                                   0.5s\n    \u001b[0m\u001b[37m \u283f Container milvus-minio       Starting                                   0.5s\n    \u001b[0m\u001b[34m \u283f Container milvus-standalone  Created                                    0.1s\n    \u001b[0m\u001b[?25h\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[0G\u001b[?25l[+] Running 2/4\n    \u001b[34m \u283f Network milvus               Created                                    0.1s\n    \u001b[0m\u001b[37m \u283f Container milvus-etcd        Starting                                   0.6s\n    \u001b[0m\u001b[37m \u283f Container milvus-minio       Starting                                   0.6s\n    \u001b[0m\u001b[34m \u283f Container milvus-standalone  Created                                    0.1s\n    \u001b[0m\u001b[?25h\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[0G\u001b[?25l[+] Running 2/4\n    \u001b[34m \u283f Network milvus               Created                                    0.1s\n    \u001b[0m\u001b[37m \u283f Container milvus-etcd        Starting                                   0.7s\n    \u001b[0m\u001b[37m \u283f Container milvus-minio       Starting                                   0.7s\n    \u001b[0m\u001b[34m \u283f Container milvus-standalone  Created                                    0.1s\n    \u001b[0m\u001b[?25h\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[0G\u001b[?25l[+] Running 2/4\n    \u001b[34m \u283f Network milvus               Created                                    0.1s\n    \u001b[0m\u001b[37m \u283f Container milvus-etcd        Starting                                   0.8s\n    \u001b[0m\u001b[37m \u283f Container milvus-minio       Starting                                   0.8s\n    \u001b[0m\u001b[34m \u283f Container milvus-standalone  Created                                    0."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 2fd0c561-3396-4786-a06a-d4d1665dfd01
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Filtered_search_with_Milvus_and_OpenAI.ipynb", "title": "Filtered Search with Milvus and OpenAI", "tokens": 4573, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"2fd0c561-3396-4786-a06a-d4d1665dfd01\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Filtered_search_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Filtered Search with Milvus and OpenAI\", \"tokens\": 4573, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"056f7cdd-2c42-4c80-a90e-2e070d777fea\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Filtered_search_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Filtered Search with Milvus and OpenAI\", \"tokens\": 4573, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"b1fa81ddbfee65f19b82c729d479c7525a55e4d249536b13a4536660d026db49\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"c10690ee-62fe-42b2-bb8f-5f61bfee7875\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Filtered_search_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Filtered Search with Milvus and OpenAI\", \"tokens\": 4573, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"0bbca253c1dacc281888ea5ca2358144c33ee6842b9a82c0f6a0b2d4086c2fce\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"9cd74544-75b0-4a3f-a35b-7a2765dd5b0c\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"b8e9ac503c15690ba2dea275b76df8011e547e3f506bf86ee41d022e9af46c11\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 3776, \"end_char_idx\": 6102, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "056f7cdd-2c42-4c80-a90e-2e070d777fea", "doc_id": "056f7cdd-2c42-4c80-a90e-2e070d777fea", "ref_doc_id": "056f7cdd-2c42-4c80-a90e-2e070d777fea", "chroma:document": "1s\n    \u001b[0m\u001b[37m \u283f Container milvus-etcd        Starting                                   0.6s\n    \u001b[0m\u001b[37m \u283f Container milvus-minio       Starting                                   0.6s\n    \u001b[0m\u001b[34m \u283f Container milvus-standalone  Created                                    0.1s\n    \u001b[0m\u001b[?25h\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[0G\u001b[?25l[+] Running 2/4\n    \u001b[34m \u283f Network milvus               Created                                    0.1s\n    \u001b[0m\u001b[37m \u283f Container milvus-etcd        Starting                                   0.7s\n    \u001b[0m\u001b[37m \u283f Container milvus-minio       Starting                                   0.7s\n    \u001b[0m\u001b[34m \u283f Container milvus-standalone  Created                                    0.1s\n    \u001b[0m\u001b[?25h\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[0G\u001b[?25l[+] Running 2/4\n    \u001b[34m \u283f Network milvus               Created                                    0.1s\n    \u001b[0m\u001b[37m \u283f Container milvus-etcd        Starting                                   0.8s\n    \u001b[0m\u001b[37m \u283f Container milvus-minio       Starting                                   0.8s\n    \u001b[0m\u001b[34m \u283f Container milvus-standalone  Created                                    0.1s\n    \u001b[0m\u001b[?25h\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[0G\u001b[?25l[+] Running 2/4\n    \u001b[34m \u283f Network milvus               Created                                    0.1s\n    \u001b[0m\u001b[37m \u283f Container milvus-etcd        Starting                                   0.9s\n    \u001b[0m\u001b[37m \u283f Container milvus-minio       Starting                                   0.9s\n    \u001b[0m\u001b[34m \u283f Container milvus-standalone  Created                                    0.1s\n    \u001b[0m\u001b[?25h\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[0G\u001b[?25l[+] Running 3/4\n    \u001b[34m \u283f Network milvus               Created                                    0.1s\n    \u001b[0m\u001b[34m \u283f Container milvus-etcd        Started                                    0.9s\n    \u001b[0m\u001b[37m \u283f Container milvus-minio       Starting                                   1.0s\n    \u001b[0m\u001b[34m \u283f Container milvus-standalone  Created                                    0.1s\n    \u001b[0m\u001b[?25h\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[0G\u001b[?25l[+] Running 3/4\n    \u001b[34m \u283f Network milvus               Created                                    0.1s\n    \u001b[0m\u001b[34m \u283f Container milvus-etcd        Started                                    0.9s\n    \u001b[0m\u001b[34m \u283f Container milvus-minio       Started                                    1."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 9cd74544-75b0-4a3f-a35b-7a2765dd5b0c
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Filtered_search_with_Milvus_and_OpenAI.ipynb", "title": "Filtered Search with Milvus and OpenAI", "tokens": 4573, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"9cd74544-75b0-4a3f-a35b-7a2765dd5b0c\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Filtered_search_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Filtered Search with Milvus and OpenAI\", \"tokens\": 4573, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"056f7cdd-2c42-4c80-a90e-2e070d777fea\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Filtered_search_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Filtered Search with Milvus and OpenAI\", \"tokens\": 4573, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"b1fa81ddbfee65f19b82c729d479c7525a55e4d249536b13a4536660d026db49\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"2fd0c561-3396-4786-a06a-d4d1665dfd01\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Filtered_search_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Filtered Search with Milvus and OpenAI\", \"tokens\": 4573, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"d8e77e96763068d63d101e90cd29428e2605862b481fa478df634938252540f8\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"4180aff4-2ef8-4b4a-be1c-ca00ff5f2206\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"190267ab6f073e9a34ea5fa89b907f83beddaa4bb4d6f9aca735d37d1c71e6a9\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 4911, \"end_char_idx\": 7200, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "056f7cdd-2c42-4c80-a90e-2e070d777fea", "doc_id": "056f7cdd-2c42-4c80-a90e-2e070d777fea", "ref_doc_id": "056f7cdd-2c42-4c80-a90e-2e070d777fea", "chroma:document": "1s\n    \u001b[0m\u001b[?25h\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[0G\u001b[?25l[+] Running 2/4\n    \u001b[34m \u283f Network milvus               Created                                    0.1s\n    \u001b[0m\u001b[37m \u283f Container milvus-etcd        Starting                                   0.9s\n    \u001b[0m\u001b[37m \u283f Container milvus-minio       Starting                                   0.9s\n    \u001b[0m\u001b[34m \u283f Container milvus-standalone  Created                                    0.1s\n    \u001b[0m\u001b[?25h\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[0G\u001b[?25l[+] Running 3/4\n    \u001b[34m \u283f Network milvus               Created                                    0.1s\n    \u001b[0m\u001b[34m \u283f Container milvus-etcd        Started                                    0.9s\n    \u001b[0m\u001b[37m \u283f Container milvus-minio       Starting                                   1.0s\n    \u001b[0m\u001b[34m \u283f Container milvus-standalone  Created                                    0.1s\n    \u001b[0m\u001b[?25h\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[0G\u001b[?25l[+] Running 3/4\n    \u001b[34m \u283f Network milvus               Created                                    0.1s\n    \u001b[0m\u001b[34m \u283f Container milvus-etcd        Started                                    0.9s\n    \u001b[0m\u001b[34m \u283f Container milvus-minio       Started                                    1.0s\n    \u001b[0m\u001b[37m \u283f Container milvus-standalone  Starting                                   1.0s\n    \u001b[0m\u001b[?25h\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[0G\u001b[?25l[+] Running 3/4\n    \u001b[34m \u283f Network milvus               Created                                    0.1s\n    \u001b[0m\u001b[34m \u283f Container milvus-etcd        Started                                    0.9s\n    \u001b[0m\u001b[34m \u283f Container milvus-minio       Started                                    1.0s\n    \u001b[0m\u001b[37m \u283f Container milvus-standalone  Starting                                   1.1s\n    \u001b[0m\u001b[?25h\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[0G\u001b[?25l[+] Running 3/4\n    \u001b[34m \u283f Network milvus               Created                                    0.1s\n    \u001b[0m\u001b[34m \u283f Container milvus-etcd        Started                                    0.9s\n    \u001b[0m\u001b[34m \u283f Container milvus-minio       Started                                    1.0s\n    \u001b[0m\u001b[37m \u283f Container milvus-standalone  Starting                                   1.2s\n    \u001b[0m\u001b[?25h\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[0G\u001b[?25l[+] Running 3/4\n    \u001b[34m \u283f Network milvus               Created                                    0."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 4180aff4-2ef8-4b4a-be1c-ca00ff5f2206
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Filtered_search_with_Milvus_and_OpenAI.ipynb", "title": "Filtered Search with Milvus and OpenAI", "tokens": 4573, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"4180aff4-2ef8-4b4a-be1c-ca00ff5f2206\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Filtered_search_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Filtered Search with Milvus and OpenAI\", \"tokens\": 4573, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"056f7cdd-2c42-4c80-a90e-2e070d777fea\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Filtered_search_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Filtered Search with Milvus and OpenAI\", \"tokens\": 4573, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"b1fa81ddbfee65f19b82c729d479c7525a55e4d249536b13a4536660d026db49\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"9cd74544-75b0-4a3f-a35b-7a2765dd5b0c\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Filtered_search_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Filtered Search with Milvus and OpenAI\", \"tokens\": 4573, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"3dfe5d77b391cc79acf3bc35f90c2bcd27ec4ef0d046b9be4448154b747a636a\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"b23de2d1-7bb7-4669-82a4-c27ca3b022e6\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"fdcdd1e85c5a400cad6b40a7ec9dc0d90b1289f13a2bc1894b38681ea73374a3\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 6009, \"end_char_idx\": 8335, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "056f7cdd-2c42-4c80-a90e-2e070d777fea", "doc_id": "056f7cdd-2c42-4c80-a90e-2e070d777fea", "ref_doc_id": "056f7cdd-2c42-4c80-a90e-2e070d777fea", "chroma:document": "9s\n    \u001b[0m\u001b[34m \u283f Container milvus-minio       Started                                    1.0s\n    \u001b[0m\u001b[37m \u283f Container milvus-standalone  Starting                                   1.0s\n    \u001b[0m\u001b[?25h\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[0G\u001b[?25l[+] Running 3/4\n    \u001b[34m \u283f Network milvus               Created                                    0.1s\n    \u001b[0m\u001b[34m \u283f Container milvus-etcd        Started                                    0.9s\n    \u001b[0m\u001b[34m \u283f Container milvus-minio       Started                                    1.0s\n    \u001b[0m\u001b[37m \u283f Container milvus-standalone  Starting                                   1.1s\n    \u001b[0m\u001b[?25h\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[0G\u001b[?25l[+] Running 3/4\n    \u001b[34m \u283f Network milvus               Created                                    0.1s\n    \u001b[0m\u001b[34m \u283f Container milvus-etcd        Started                                    0.9s\n    \u001b[0m\u001b[34m \u283f Container milvus-minio       Started                                    1.0s\n    \u001b[0m\u001b[37m \u283f Container milvus-standalone  Starting                                   1.2s\n    \u001b[0m\u001b[?25h\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[0G\u001b[?25l[+] Running 3/4\n    \u001b[34m \u283f Network milvus               Created                                    0.1s\n    \u001b[0m\u001b[34m \u283f Container milvus-etcd        Started                                    0.9s\n    \u001b[0m\u001b[34m \u283f Container milvus-minio       Started                                    1.0s\n    \u001b[0m\u001b[37m \u283f Container milvus-standalone  Starting                                   1.3s\n    \u001b[0m\u001b[?25h\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[0G\u001b[?25l[+] Running 3/4\n    \u001b[34m \u283f Network milvus               Created                                    0.1s\n    \u001b[0m\u001b[34m \u283f Container milvus-etcd        Started                                    0.9s\n    \u001b[0m\u001b[34m \u283f Container milvus-minio       Started                                    1.0s\n    \u001b[0m\u001b[37m \u283f Container milvus-standalone  Starting                                   1.4s\n    \u001b[0m\u001b[?25h\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[0G\u001b[?25l[+] Running 3/4\n    \u001b[34m \u283f Network milvus               Created                                    0.1s\n    \u001b[0m\u001b[34m \u283f Container milvus-etcd        Started                                    0.9s\n    \u001b[0m\u001b[34m \u283f Container milvus-minio       Started                                    1.0s\n    \u001b[0m\u001b[37m \u283f Container milvus-standalone  Starting                                   1."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: b23de2d1-7bb7-4669-82a4-c27ca3b022e6
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Filtered_search_with_Milvus_and_OpenAI.ipynb", "title": "Filtered Search with Milvus and OpenAI", "tokens": 4573, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"b23de2d1-7bb7-4669-82a4-c27ca3b022e6\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Filtered_search_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Filtered Search with Milvus and OpenAI\", \"tokens\": 4573, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"056f7cdd-2c42-4c80-a90e-2e070d777fea\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Filtered_search_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Filtered Search with Milvus and OpenAI\", \"tokens\": 4573, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"b1fa81ddbfee65f19b82c729d479c7525a55e4d249536b13a4536660d026db49\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"4180aff4-2ef8-4b4a-be1c-ca00ff5f2206\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Filtered_search_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Filtered Search with Milvus and OpenAI\", \"tokens\": 4573, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"8ab9d5bc3af04eca8fbc3e80066bcb6a3e6b3bda074d91eca8e5b620e952c3bb\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"46ece4ac-2535-4481-9454-ac29b19893d2\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"7ac28e738edfe6461edc29d6ce5a536fd152346765ef84965227172bb262b600\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 7200, \"end_char_idx\": 9650, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "056f7cdd-2c42-4c80-a90e-2e070d777fea", "doc_id": "056f7cdd-2c42-4c80-a90e-2e070d777fea", "ref_doc_id": "056f7cdd-2c42-4c80-a90e-2e070d777fea", "chroma:document": "1s\n    \u001b[0m\u001b[34m \u283f Container milvus-etcd        Started                                    0.9s\n    \u001b[0m\u001b[34m \u283f Container milvus-minio       Started                                    1.0s\n    \u001b[0m\u001b[37m \u283f Container milvus-standalone  Starting                                   1.3s\n    \u001b[0m\u001b[?25h\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[0G\u001b[?25l[+] Running 3/4\n    \u001b[34m \u283f Network milvus               Created                                    0.1s\n    \u001b[0m\u001b[34m \u283f Container milvus-etcd        Started                                    0.9s\n    \u001b[0m\u001b[34m \u283f Container milvus-minio       Started                                    1.0s\n    \u001b[0m\u001b[37m \u283f Container milvus-standalone  Starting                                   1.4s\n    \u001b[0m\u001b[?25h\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[0G\u001b[?25l[+] Running 3/4\n    \u001b[34m \u283f Network milvus               Created                                    0.1s\n    \u001b[0m\u001b[34m \u283f Container milvus-etcd        Started                                    0.9s\n    \u001b[0m\u001b[34m \u283f Container milvus-minio       Started                                    1.0s\n    \u001b[0m\u001b[37m \u283f Container milvus-standalone  Starting                                   1.5s\n    \u001b[0m\u001b[?25h\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[1A\u001b[0G\u001b[?25l\u001b[34m[+] Running 4/4\u001b[0m\n    \u001b[34m \u283f Network milvus               Created                                    0.1s\n    \u001b[0m\u001b[34m \u283f Container milvus-etcd        Started                                    0.9s\n    \u001b[0m\u001b[34m \u283f Container milvus-minio       Started                                    1.0s\n    \u001b[0m\u001b[34m \u283f Container milvus-standalone  Started                                    1.6s\n    \u001b[0m\u001b[?25h\n\nWith Milvus running we can setup our global variables:\n- HOST: The Milvus host address\n- PORT: The Milvus port number\n- COLLECTION_NAME: What to name the collection within Milvus\n- DIMENSION: The dimension of the embeddings\n- OPENAI_ENGINE: Which embedding model to use\n- openai.api_key: Your OpenAI account key\n- INDEX_PARAM: The index settings to use for the collection\n- QUERY_PARAM: The search parameters to use\n- BATCH_SIZE: How many movies to embed and insert at once\n\n\n```python\nimport openai\n\nHOST = 'localhost'\nPORT = 19530\nCOLLECTION_NAME = 'movie_search'\nDIMENSION = 1536\nOPENAI_ENGINE = 'text-embedding-3-small'\nopenai.api_key = 'sk-your_key'\n\nINDEX_PARAM = {\n    'metric_type':'L2',\n    'index_type':\"HNSW\",\n    'params':{'M': 8, 'efConstruction': 64}\n}\n\nQUERY_PARAM = {\n    \"metric_type\": \"L2\",\n    \"params\": {\"ef\": 64},\n}\n\nBATCH_SIZE = 1000\n```"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 46ece4ac-2535-4481-9454-ac29b19893d2
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Filtered_search_with_Milvus_and_OpenAI.ipynb", "title": "Filtered Search with Milvus and OpenAI", "tokens": 4573, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"46ece4ac-2535-4481-9454-ac29b19893d2\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Filtered_search_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Filtered Search with Milvus and OpenAI\", \"tokens\": 4573, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"056f7cdd-2c42-4c80-a90e-2e070d777fea\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Filtered_search_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Filtered Search with Milvus and OpenAI\", \"tokens\": 4573, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"b1fa81ddbfee65f19b82c729d479c7525a55e4d249536b13a4536660d026db49\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"b23de2d1-7bb7-4669-82a4-c27ca3b022e6\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Filtered_search_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Filtered Search with Milvus and OpenAI\", \"tokens\": 4573, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"f5e049390835c4a144a26d597a79b0fafe367028f950129e56496f4d85cdd9b7\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"36dc0e90-55c9-42fd-8a95-c2e18974c71d\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"a02b78b0677e812ae3ac35b8fe93c96739b309b54ff95eb10161b74fb3d74ab2\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 8493, \"end_char_idx\": 11269, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "056f7cdd-2c42-4c80-a90e-2e070d777fea", "doc_id": "056f7cdd-2c42-4c80-a90e-2e070d777fea", "ref_doc_id": "056f7cdd-2c42-4c80-a90e-2e070d777fea", "chroma:document": "1s\n    \u001b[0m\u001b[34m \u283f Container milvus-etcd        Started                                    0.9s\n    \u001b[0m\u001b[34m \u283f Container milvus-minio       Started                                    1.0s\n    \u001b[0m\u001b[34m \u283f Container milvus-standalone  Started                                    1.6s\n    \u001b[0m\u001b[?25h\n\nWith Milvus running we can setup our global variables:\n- HOST: The Milvus host address\n- PORT: The Milvus port number\n- COLLECTION_NAME: What to name the collection within Milvus\n- DIMENSION: The dimension of the embeddings\n- OPENAI_ENGINE: Which embedding model to use\n- openai.api_key: Your OpenAI account key\n- INDEX_PARAM: The index settings to use for the collection\n- QUERY_PARAM: The search parameters to use\n- BATCH_SIZE: How many movies to embed and insert at once\n\n\n```python\nimport openai\n\nHOST = 'localhost'\nPORT = 19530\nCOLLECTION_NAME = 'movie_search'\nDIMENSION = 1536\nOPENAI_ENGINE = 'text-embedding-3-small'\nopenai.api_key = 'sk-your_key'\n\nINDEX_PARAM = {\n    'metric_type':'L2',\n    'index_type':\"HNSW\",\n    'params':{'M': 8, 'efConstruction': 64}\n}\n\nQUERY_PARAM = {\n    \"metric_type\": \"L2\",\n    \"params\": {\"ef\": 64},\n}\n\nBATCH_SIZE = 1000\n```\n\n\n```python\nfrom pymilvus import connections, utility, FieldSchema, Collection, CollectionSchema, DataType\n\n# Connect to Milvus Database\nconnections.connect(host=HOST, port=PORT)\n```\n\n\n```python\n# Remove collection if it already exists\nif utility.has_collection(COLLECTION_NAME):\n    utility.drop_collection(COLLECTION_NAME)\n```\n\n\n```python\n# Create collection which includes the id, title, and embedding.\nfields = [\n    FieldSchema(name='id', dtype=DataType.INT64, is_primary=True, auto_id=True),\n    FieldSchema(name='title', dtype=DataType.VARCHAR, max_length=64000),\n    FieldSchema(name='type', dtype=DataType.VARCHAR, max_length=64000),\n    FieldSchema(name='release_year', dtype=DataType.INT64),\n    FieldSchema(name='rating', dtype=DataType.VARCHAR, max_length=64000),\n    FieldSchema(name='description', dtype=DataType.VARCHAR, max_length=64000),\n    FieldSchema(name='embedding', dtype=DataType.FLOAT_VECTOR, dim=DIMENSION)\n]\nschema = CollectionSchema(fields=fields)\ncollection = Collection(name=COLLECTION_NAME, schema=schema)\n```\n\n\n```python\n# Create the index on the collection and load it.\ncollection.create_index(field_name=\"embedding\", index_params=INDEX_PARAM)\ncollection.load()\n```\n\n## Dataset\nWith Milvus up and running we can begin grabbing our data. Hugging Face Datasets is a hub that holds many different user datasets, and for this example we are using HuggingLearners's netflix-shows dataset. This dataset contains movies and their metadata pairs for over 8 thousand movies. We are going to embed each description and store it within Milvus along with its title, type, release_year and rating."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 36dc0e90-55c9-42fd-8a95-c2e18974c71d
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Filtered_search_with_Milvus_and_OpenAI.ipynb", "title": "Filtered Search with Milvus and OpenAI", "tokens": 4573, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"36dc0e90-55c9-42fd-8a95-c2e18974c71d\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Filtered_search_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Filtered Search with Milvus and OpenAI\", \"tokens\": 4573, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"056f7cdd-2c42-4c80-a90e-2e070d777fea\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Filtered_search_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Filtered Search with Milvus and OpenAI\", \"tokens\": 4573, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"b1fa81ddbfee65f19b82c729d479c7525a55e4d249536b13a4536660d026db49\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"46ece4ac-2535-4481-9454-ac29b19893d2\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Filtered_search_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Filtered Search with Milvus and OpenAI\", \"tokens\": 4573, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"779ef2c79d3c521ff9188d3e77245fa62c2bf5d3bf41eec9c8571aa9e98fbdae\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"27449da9-1c18-4682-b39d-9686dff215c2\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"5fe12854d2246871beed11de7581b95fabcd2c042a86d6c481ebf9d15adb9815\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 9653, \"end_char_idx\": 12290, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "056f7cdd-2c42-4c80-a90e-2e070d777fea", "doc_id": "056f7cdd-2c42-4c80-a90e-2e070d777fea", "ref_doc_id": "056f7cdd-2c42-4c80-a90e-2e070d777fea", "chroma:document": "```python\nfrom pymilvus import connections, utility, FieldSchema, Collection, CollectionSchema, DataType\n\n# Connect to Milvus Database\nconnections.connect(host=HOST, port=PORT)\n```\n\n\n```python\n# Remove collection if it already exists\nif utility.has_collection(COLLECTION_NAME):\n    utility.drop_collection(COLLECTION_NAME)\n```\n\n\n```python\n# Create collection which includes the id, title, and embedding.\nfields = [\n    FieldSchema(name='id', dtype=DataType.INT64, is_primary=True, auto_id=True),\n    FieldSchema(name='title', dtype=DataType.VARCHAR, max_length=64000),\n    FieldSchema(name='type', dtype=DataType.VARCHAR, max_length=64000),\n    FieldSchema(name='release_year', dtype=DataType.INT64),\n    FieldSchema(name='rating', dtype=DataType.VARCHAR, max_length=64000),\n    FieldSchema(name='description', dtype=DataType.VARCHAR, max_length=64000),\n    FieldSchema(name='embedding', dtype=DataType.FLOAT_VECTOR, dim=DIMENSION)\n]\nschema = CollectionSchema(fields=fields)\ncollection = Collection(name=COLLECTION_NAME, schema=schema)\n```\n\n\n```python\n# Create the index on the collection and load it.\ncollection.create_index(field_name=\"embedding\", index_params=INDEX_PARAM)\ncollection.load()\n```\n\n## Dataset\nWith Milvus up and running we can begin grabbing our data. Hugging Face Datasets is a hub that holds many different user datasets, and for this example we are using HuggingLearners's netflix-shows dataset. This dataset contains movies and their metadata pairs for over 8 thousand movies. We are going to embed each description and store it within Milvus along with its title, type, release_year and rating.\n\n\n```python\nimport datasets\n\n# Download the dataset \ndataset = datasets.load_dataset('hugginglearners/netflix-shows', split='train')\n```\n\n    Found cached dataset csv (/Users/filiphaltmayer/.cache/huggingface/datasets/hugginglearners___csv/hugginglearners--netflix-shows-03475319fc65a05a/0.0.0/6b34fb8fcf56f7c8ba51dc895bfa2bfbe43546f190a60fcf74bb5e8afdcc2317)\n\n\n## Insert the Data\nNow that we have our data on our machine we can begin embedding it and inserting it into Milvus. The embedding function takes in text and returns the embeddings in a list format. \n\n\n```python\n# Simple function that converts the texts to embeddings\ndef embed(texts):\n    embeddings = openai.Embedding.create(\n        input=texts,\n        engine=OPENAI_ENGINE\n    )\n    return [x['embedding'] for x in embeddings['data']]\n\n```\n\nThis next step does the actual inserting. We iterate through all the entries and create batches that we insert once we hit our set batch size. After the loop is over we insert the last remaning batch if it exists."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 27449da9-1c18-4682-b39d-9686dff215c2
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Filtered_search_with_Milvus_and_OpenAI.ipynb", "title": "Filtered Search with Milvus and OpenAI", "tokens": 4573, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"27449da9-1c18-4682-b39d-9686dff215c2\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Filtered_search_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Filtered Search with Milvus and OpenAI\", \"tokens\": 4573, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"056f7cdd-2c42-4c80-a90e-2e070d777fea\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Filtered_search_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Filtered Search with Milvus and OpenAI\", \"tokens\": 4573, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"b1fa81ddbfee65f19b82c729d479c7525a55e4d249536b13a4536660d026db49\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"36dc0e90-55c9-42fd-8a95-c2e18974c71d\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Filtered_search_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Filtered Search with Milvus and OpenAI\", \"tokens\": 4573, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"549f3f14f7aa114435e7d69953d58a951c523588f09605aefdcff8bee89533fb\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"e9c76286-6c32-415c-98fd-4d01d51b215b\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"23ef84f74f416ff28903e29cfd7209278c0bfef0ecb7cfd45011253b66cae88f\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 10695, \"end_char_idx\": 13550, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "056f7cdd-2c42-4c80-a90e-2e070d777fea", "doc_id": "056f7cdd-2c42-4c80-a90e-2e070d777fea", "ref_doc_id": "056f7cdd-2c42-4c80-a90e-2e070d777fea", "chroma:document": "```python\n# Create the index on the collection and load it.\ncollection.create_index(field_name=\"embedding\", index_params=INDEX_PARAM)\ncollection.load()\n```\n\n## Dataset\nWith Milvus up and running we can begin grabbing our data. Hugging Face Datasets is a hub that holds many different user datasets, and for this example we are using HuggingLearners's netflix-shows dataset. This dataset contains movies and their metadata pairs for over 8 thousand movies. We are going to embed each description and store it within Milvus along with its title, type, release_year and rating.\n\n\n```python\nimport datasets\n\n# Download the dataset \ndataset = datasets.load_dataset('hugginglearners/netflix-shows', split='train')\n```\n\n    Found cached dataset csv (/Users/filiphaltmayer/.cache/huggingface/datasets/hugginglearners___csv/hugginglearners--netflix-shows-03475319fc65a05a/0.0.0/6b34fb8fcf56f7c8ba51dc895bfa2bfbe43546f190a60fcf74bb5e8afdcc2317)\n\n\n## Insert the Data\nNow that we have our data on our machine we can begin embedding it and inserting it into Milvus. The embedding function takes in text and returns the embeddings in a list format. \n\n\n```python\n# Simple function that converts the texts to embeddings\ndef embed(texts):\n    embeddings = openai.Embedding.create(\n        input=texts,\n        engine=OPENAI_ENGINE\n    )\n    return [x['embedding'] for x in embeddings['data']]\n\n```\n\nThis next step does the actual inserting. We iterate through all the entries and create batches that we insert once we hit our set batch size. After the loop is over we insert the last remaning batch if it exists. \n\n\n```python\nfrom tqdm import tqdm\n\ndata = [\n    [], # title\n    [], # type\n    [], # release_year\n    [], # rating\n    [], # description\n]\n\n# Embed and insert in batches\nfor i in tqdm(range(0, len(dataset))):\n    data[0].append(dataset[i]['title'] or '')\n    data[1].append(dataset[i]['type'] or '')\n    data[2].append(dataset[i]['release_year'] or -1)\n    data[3].append(dataset[i]['rating'] or '')\n    data[4].append(dataset[i]['description'] or '')\n    if len(data[0]) % BATCH_SIZE == 0:\n        data.append(embed(data[4]))\n        collection.insert(data)\n        data = [[],[],[],[],[]]\n\n# Embed and insert the remainder \nif len(data[0]) != 0:\n    data.append(embed(data[4]))\n    collection.insert(data)\n    data = [[],[],[],[],[]]\n\n```\n\n    100%|\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588| 8807/8807 [00:31<00:00, 276.82it/s]\n\n\n## Query the Database\nWith our data safely inserted in Milvus, we can now perform a query. The query takes in a tuple of the movie description you are searching for an the filter to use. More info about the filter can be found [here](https://milvus.io/docs/boolean.md). The search first prints out your description and filter expression. After that for each result we print the score, title, type, release year, rating, and description of the result movies."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: e9c76286-6c32-415c-98fd-4d01d51b215b
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Filtered_search_with_Milvus_and_OpenAI.ipynb", "title": "Filtered Search with Milvus and OpenAI", "tokens": 4573, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"e9c76286-6c32-415c-98fd-4d01d51b215b\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Filtered_search_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Filtered Search with Milvus and OpenAI\", \"tokens\": 4573, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"056f7cdd-2c42-4c80-a90e-2e070d777fea\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Filtered_search_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Filtered Search with Milvus and OpenAI\", \"tokens\": 4573, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"b1fa81ddbfee65f19b82c729d479c7525a55e4d249536b13a4536660d026db49\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"27449da9-1c18-4682-b39d-9686dff215c2\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/milvus/Filtered_search_with_Milvus_and_OpenAI.ipynb\", \"title\": \"Filtered Search with Milvus and OpenAI\", \"tokens\": 4573, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"588d152d2157aa18f6c28bd6b13dcf59e63852d58ebfc48becdfbdb0a3906e0d\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 12294, \"end_char_idx\": 15877, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "056f7cdd-2c42-4c80-a90e-2e070d777fea", "doc_id": "056f7cdd-2c42-4c80-a90e-2e070d777fea", "ref_doc_id": "056f7cdd-2c42-4c80-a90e-2e070d777fea", "chroma:document": "```python\nfrom tqdm import tqdm\n\ndata = [\n    [], # title\n    [], # type\n    [], # release_year\n    [], # rating\n    [], # description\n]\n\n# Embed and insert in batches\nfor i in tqdm(range(0, len(dataset))):\n    data[0].append(dataset[i]['title'] or '')\n    data[1].append(dataset[i]['type'] or '')\n    data[2].append(dataset[i]['release_year'] or -1)\n    data[3].append(dataset[i]['rating'] or '')\n    data[4].append(dataset[i]['description'] or '')\n    if len(data[0]) % BATCH_SIZE == 0:\n        data.append(embed(data[4]))\n        collection.insert(data)\n        data = [[],[],[],[],[]]\n\n# Embed and insert the remainder \nif len(data[0]) != 0:\n    data.append(embed(data[4]))\n    collection.insert(data)\n    data = [[],[],[],[],[]]\n\n```\n\n    100%|\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588| 8807/8807 [00:31<00:00, 276.82it/s]\n\n\n## Query the Database\nWith our data safely inserted in Milvus, we can now perform a query. The query takes in a tuple of the movie description you are searching for an the filter to use. More info about the filter can be found [here](https://milvus.io/docs/boolean.md). The search first prints out your description and filter expression. After that for each result we print the score, title, type, release year, rating, and description of the result movies. \n\n\n```python\nimport textwrap\n\ndef query(query, top_k = 5):\n    text, expr = query\n    res = collection.search(embed(text), anns_field='embedding', expr = expr, param=QUERY_PARAM, limit = top_k, output_fields=['title', 'type', 'release_year', 'rating', 'description'])\n    for i, hit in enumerate(res):\n        print('Description:', text, 'Expression:', expr)\n        print('Results:')\n        for ii, hits in enumerate(hit):\n            print('\\t' + 'Rank:', ii + 1, 'Score:', hits.score, 'Title:', hits.entity.get('title'))\n            print('\\t\\t' + 'Type:', hits.entity.get('type'), 'Release Year:', hits.entity.get('release_year'), 'Rating:', hits.entity.get('rating'))\n            print(textwrap.fill(hits.entity.get('description'), 88))\n            print()\n\nmy_query = ('movie about a fluffly animal', 'release_year < 2019 and rating like \\\"PG%\\\"')\n\nquery(my_query)\n```\n\n    Description: movie about a fluffly animal Expression: release_year < 2019 and rating like \"PG%\"\n    Results:\n    \tRank: 1 Score: 0.30083978176116943 Title: The Lamb\n    \t\tType: Movie Release Year: 2017 Rating: PG\n    A big-dreaming donkey escapes his menial existence and befriends some free-spirited\n    animal pals in this imaginative retelling of the Nativity Story.\n    \n    \tRank: 2 Score: 0.33528298139572144 Title: Puss in Boots\n    \t\tType: Movie Release Year: 2011 Rating: PG\n    The fabled feline heads to the Land of Giants with friends Humpty Dumpty and Kitty\n    Softpaws on a quest to nab its greatest treasure: the Golden Goose.\n    \n    \tRank: 3 Score: 0.33528298139572144 Title: Puss in Boots\n    \t\tType: Movie Release Year: 2011 Rating: PG\n    The fabled feline heads to the Land of Giants with friends Humpty Dumpty and Kitty\n    Softpaws on a quest to nab its greatest treasure: the Golden Goose.\n    \n    \tRank: 4 Score: 0.3414868116378784 Title: Show Dogs\n    \t\tType: Movie Release Year: 2018 Rating: PG\n    A rough and tough police dog must go undercover with an FBI agent as a prim and proper\n    pet at a dog show to save a baby panda from an illegal sale.\n    \n    \tRank: 5 Score: 0.3414868116378784 Title: Show Dogs\n    \t\tType: Movie Release Year: 2018 Rating: PG\n    A rough and tough police dog must go undercover with an FBI agent as a prim and proper\n    pet at a dog show to save a baby panda from an illegal sale."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 0f8bca00-0899-479b-9c69-b0b2df7f4c78
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/Getting_started_with_AnalyticDB_and_OpenAI.ipynb", "title": "Using AnalyticDB as a vector database for OpenAI embeddings", "tokens": 2780, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"0f8bca00-0899-479b-9c69-b0b2df7f4c78\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/Getting_started_with_AnalyticDB_and_OpenAI.ipynb\", \"title\": \"Using AnalyticDB as a vector database for OpenAI embeddings\", \"tokens\": 2780, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"403de4ce-58aa-4e7f-9cee-9d74f3ccf644\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/Getting_started_with_AnalyticDB_and_OpenAI.ipynb\", \"title\": \"Using AnalyticDB as a vector database for OpenAI embeddings\", \"tokens\": 2780, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"436edb368979905aebf7d00f3f021a82934ad92a7e8acc7b5ffdec37c46878ca\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"13d1d528-d981-4e36-b104-5eb8871373de\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"e0fc29ee1885346a43a6a917cf0c0b00f9f7df9a4569475e34de187648c9fc37\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 0, \"end_char_idx\": 3242, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "403de4ce-58aa-4e7f-9cee-9d74f3ccf644", "doc_id": "403de4ce-58aa-4e7f-9cee-9d74f3ccf644", "ref_doc_id": "403de4ce-58aa-4e7f-9cee-9d74f3ccf644", "chroma:document": "# Using AnalyticDB as a vector database for OpenAI embeddings\n\nThis notebook guides you step by step on using AnalyticDB as a vector database for OpenAI embeddings.\n\nThis notebook presents an end-to-end process of:\n1. Using precomputed embeddings created by OpenAI API.\n2. Storing the embeddings in a cloud instance of AnalyticDB.\n3. Converting raw text query to an embedding with OpenAI API.\n4. Using AnalyticDB to perform the nearest neighbour search in the created collection.\n\n### What is AnalyticDB\n\n[AnalyticDB](https://www.alibabacloud.com/help/en/analyticdb-for-postgresql/latest/product-introduction-overview) is a high-performance distributed vector database. Fully compatible with PostgreSQL syntax, you can effortlessly utilize it. AnalyticDB is Alibaba Cloud managed cloud-native database with strong-performed vector compute engine. Absolute out-of-box experience allow to scale into billions of data vectors processing with rich features including indexing algorithms, structured & non-structured data features, realtime update, distance metrics, scalar filtering, time travel searches etc. Also equipped with full OLAP database functionality and SLA commitment for production usage promise;\n\n### Deployment options\n\n- Using [AnalyticDB Cloud Vector Database](https://www.alibabacloud.com/help/zh/analyticdb-for-postgresql/latest/overview-2). [Click here](https://www.alibabacloud.com/product/hybriddb-postgresql) to fast deploy it.\n\n\n## Prerequisites\n\nFor the purposes of this exercise we need to prepare a couple of things:\n\n1. AnalyticDB cloud server instance.\n2. The 'psycopg2' library to interact with the vector database. Any other postgresql client library is ok.\n3. An [OpenAI API key](https://beta.openai.com/account/api-keys).\n\n\n\nWe might validate if the server was launched successfully by running a simple curl command:\n\n\n### Install requirements\n\nThis notebook obviously requires the `openai` and `psycopg2` packages, but there are also some other additional libraries we will use. The following command installs them all:\n\n\n\n```python\n! pip install openai psycopg2 pandas wget\n```\n\n### Prepare your OpenAI API key\n\nThe OpenAI API key is used for vectorization of the documents and queries.\n\nIf you don't have an OpenAI API key, you can get one from [https://beta.openai.com/account/api-keys](https://beta.openai.com/account/api-keys).\n\nOnce you get your key, please add it to your environment variables as `OPENAI_API_KEY`.\n\n\n```python\n# Test that your OpenAI API key is correctly set as an environment variable\n# Note. if you run this notebook locally, you will need to reload your terminal and the notebook for the env variables to be live.\nimport os\n\n# Note. alternatively you can set a temporary env variable like this:\n# os.environ[\"OPENAI_API_KEY\"] = \"sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\"\n\nif os.getenv(\"OPENAI_API_KEY\") is not None:\n    print(\"OPENAI_API_KEY is ready\")\nelse:\n    print(\"OPENAI_API_KEY environment variable not found\")\n```\n\n    OPENAI_API_KEY is ready\n\n\n## Connect to AnalyticDB\nFirst add it to your environment variables. or you can just change the \"psycopg2.connect\" parameters below\n\nConnecting to a running instance of AnalyticDB server is easy with the official Python library:"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 13d1d528-d981-4e36-b104-5eb8871373de
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/Getting_started_with_AnalyticDB_and_OpenAI.ipynb", "title": "Using AnalyticDB as a vector database for OpenAI embeddings", "tokens": 2780, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"13d1d528-d981-4e36-b104-5eb8871373de\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/Getting_started_with_AnalyticDB_and_OpenAI.ipynb\", \"title\": \"Using AnalyticDB as a vector database for OpenAI embeddings\", \"tokens\": 2780, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"403de4ce-58aa-4e7f-9cee-9d74f3ccf644\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/Getting_started_with_AnalyticDB_and_OpenAI.ipynb\", \"title\": \"Using AnalyticDB as a vector database for OpenAI embeddings\", \"tokens\": 2780, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"436edb368979905aebf7d00f3f021a82934ad92a7e8acc7b5ffdec37c46878ca\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"0f8bca00-0899-479b-9c69-b0b2df7f4c78\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/Getting_started_with_AnalyticDB_and_OpenAI.ipynb\", \"title\": \"Using AnalyticDB as a vector database for OpenAI embeddings\", \"tokens\": 2780, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"1c9ea2a49d50eb3868f2b090fc3a9f46c1341732ca7fff60619de469b862b08a\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"0305ddf1-8a8c-4fce-a239-e2835db3656c\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"3570b5a49d48e59a70f6615599e5691f6ce91bf0c05055c5336890b4508759a5\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 1755, \"end_char_idx\": 4986, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "403de4ce-58aa-4e7f-9cee-9d74f3ccf644", "doc_id": "403de4ce-58aa-4e7f-9cee-9d74f3ccf644", "ref_doc_id": "403de4ce-58aa-4e7f-9cee-9d74f3ccf644", "chroma:document": "We might validate if the server was launched successfully by running a simple curl command:\n\n\n### Install requirements\n\nThis notebook obviously requires the `openai` and `psycopg2` packages, but there are also some other additional libraries we will use. The following command installs them all:\n\n\n\n```python\n! pip install openai psycopg2 pandas wget\n```\n\n### Prepare your OpenAI API key\n\nThe OpenAI API key is used for vectorization of the documents and queries.\n\nIf you don't have an OpenAI API key, you can get one from [https://beta.openai.com/account/api-keys](https://beta.openai.com/account/api-keys).\n\nOnce you get your key, please add it to your environment variables as `OPENAI_API_KEY`.\n\n\n```python\n# Test that your OpenAI API key is correctly set as an environment variable\n# Note. if you run this notebook locally, you will need to reload your terminal and the notebook for the env variables to be live.\nimport os\n\n# Note. alternatively you can set a temporary env variable like this:\n# os.environ[\"OPENAI_API_KEY\"] = \"sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\"\n\nif os.getenv(\"OPENAI_API_KEY\") is not None:\n    print(\"OPENAI_API_KEY is ready\")\nelse:\n    print(\"OPENAI_API_KEY environment variable not found\")\n```\n\n    OPENAI_API_KEY is ready\n\n\n## Connect to AnalyticDB\nFirst add it to your environment variables. or you can just change the \"psycopg2.connect\" parameters below\n\nConnecting to a running instance of AnalyticDB server is easy with the official Python library:\n\n\n```python\nimport os\nimport psycopg2\n\n# Note. alternatively you can set a temporary env variable like this:\n# os.environ[\"PGHOST\"] = \"your_host\"\n# os.environ[\"PGPORT\"] \"5432\"),\n# os.environ[\"PGDATABASE\"] \"postgres\"),\n# os.environ[\"PGUSER\"] \"user\"),\n# os.environ[\"PGPASSWORD\"] \"password\"),\n\nconnection = psycopg2.connect(\n    host=os.environ.get(\"PGHOST\", \"localhost\"),\n    port=os.environ.get(\"PGPORT\", \"5432\"),\n    database=os.environ.get(\"PGDATABASE\", \"postgres\"),\n    user=os.environ.get(\"PGUSER\", \"user\"),\n    password=os.environ.get(\"PGPASSWORD\", \"password\")\n)\n\n# Create a new cursor object\ncursor = connection.cursor()\n```\n\nWe can test the connection by running any available method:\n\n\n```python\n\n# Execute a simple query to test the connection\ncursor.execute(\"SELECT 1;\")\nresult = cursor.fetchone()\n\n# Check the query result\nif result == (1,):\n    print(\"Connection successful!\")\nelse:\n    print(\"Connection failed.\")\n```\n\n    Connection successful!\n\n\n\n```python\nimport wget\n\nembeddings_url = \"https://cdn.openai.com/API/examples/data/vector_database_wikipedia_articles_embedded.zip\"\n\n# The file is ~700 MB so this will take some time\nwget.download(embeddings_url)\n```\n\n    100% [......................................................................] 698933052 / 698933052\n\n\n\n\n    'vector_database_wikipedia_articles_embedded.zip'\n\n\n\nThe downloaded file has to be then extracted:\n\n\n```python\nimport zipfile\nimport os\nimport re\nimport tempfile\n\ncurrent_directory = os.getcwd()\nzip_file_path = os.path.join(current_directory, \"vector_database_wikipedia_articles_embedded.zip\")\noutput_directory = os.path.join(current_directory, \"../../data\")\n\nwith zipfile.ZipFile(zip_file_path, \"r\") as zip_ref:\n    zip_ref.extractall(output_directory)"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 0305ddf1-8a8c-4fce-a239-e2835db3656c
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/Getting_started_with_AnalyticDB_and_OpenAI.ipynb", "title": "Using AnalyticDB as a vector database for OpenAI embeddings", "tokens": 2780, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"0305ddf1-8a8c-4fce-a239-e2835db3656c\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/Getting_started_with_AnalyticDB_and_OpenAI.ipynb\", \"title\": \"Using AnalyticDB as a vector database for OpenAI embeddings\", \"tokens\": 2780, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"403de4ce-58aa-4e7f-9cee-9d74f3ccf644\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/Getting_started_with_AnalyticDB_and_OpenAI.ipynb\", \"title\": \"Using AnalyticDB as a vector database for OpenAI embeddings\", \"tokens\": 2780, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"436edb368979905aebf7d00f3f021a82934ad92a7e8acc7b5ffdec37c46878ca\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"13d1d528-d981-4e36-b104-5eb8871373de\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/Getting_started_with_AnalyticDB_and_OpenAI.ipynb\", \"title\": \"Using AnalyticDB as a vector database for OpenAI embeddings\", \"tokens\": 2780, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"867eddc618c2249b0c2d5f21d65708ca32b6b662cd8652fe30e651174d0546d3\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"a8918869-e54f-4e98-93ef-07cb093ebd32\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"3e7d0d8e04992c4faaf2983ec85155b21b9c5c22e831931e647af48cfbd79534\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 3245, \"end_char_idx\": 5855, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "403de4ce-58aa-4e7f-9cee-9d74f3ccf644", "doc_id": "403de4ce-58aa-4e7f-9cee-9d74f3ccf644", "ref_doc_id": "403de4ce-58aa-4e7f-9cee-9d74f3ccf644", "chroma:document": "```python\nimport os\nimport psycopg2\n\n# Note. alternatively you can set a temporary env variable like this:\n# os.environ[\"PGHOST\"] = \"your_host\"\n# os.environ[\"PGPORT\"] \"5432\"),\n# os.environ[\"PGDATABASE\"] \"postgres\"),\n# os.environ[\"PGUSER\"] \"user\"),\n# os.environ[\"PGPASSWORD\"] \"password\"),\n\nconnection = psycopg2.connect(\n    host=os.environ.get(\"PGHOST\", \"localhost\"),\n    port=os.environ.get(\"PGPORT\", \"5432\"),\n    database=os.environ.get(\"PGDATABASE\", \"postgres\"),\n    user=os.environ.get(\"PGUSER\", \"user\"),\n    password=os.environ.get(\"PGPASSWORD\", \"password\")\n)\n\n# Create a new cursor object\ncursor = connection.cursor()\n```\n\nWe can test the connection by running any available method:\n\n\n```python\n\n# Execute a simple query to test the connection\ncursor.execute(\"SELECT 1;\")\nresult = cursor.fetchone()\n\n# Check the query result\nif result == (1,):\n    print(\"Connection successful!\")\nelse:\n    print(\"Connection failed.\")\n```\n\n    Connection successful!\n\n\n\n```python\nimport wget\n\nembeddings_url = \"https://cdn.openai.com/API/examples/data/vector_database_wikipedia_articles_embedded.zip\"\n\n# The file is ~700 MB so this will take some time\nwget.download(embeddings_url)\n```\n\n    100% [......................................................................] 698933052 / 698933052\n\n\n\n\n    'vector_database_wikipedia_articles_embedded.zip'\n\n\n\nThe downloaded file has to be then extracted:\n\n\n```python\nimport zipfile\nimport os\nimport re\nimport tempfile\n\ncurrent_directory = os.getcwd()\nzip_file_path = os.path.join(current_directory, \"vector_database_wikipedia_articles_embedded.zip\")\noutput_directory = os.path.join(current_directory, \"../../data\")\n\nwith zipfile.ZipFile(zip_file_path, \"r\") as zip_ref:\n    zip_ref.extractall(output_directory)\n\n\n# check the csv file exist\nfile_name = \"vector_database_wikipedia_articles_embedded.csv\"\ndata_directory = os.path.join(current_directory, \"../../data\")\nfile_path = os.path.join(data_directory, file_name)\n\n\nif os.path.exists(file_path):\n    print(f\"The file {file_name} exists in the data directory.\")\nelse:\n    print(f\"The file {file_name} does not exist in the data directory.\")\n\n```\n\n    The file vector_database_wikipedia_articles_embedded.csv exists in the data directory.\n\n\n## Index data\n\nAnalyticDB stores data in __relation__ where each object is described by at least one vector. Our relation will be called **articles** and each object will be described by both **title** and **content** vectors. \\\n\nWe will start with creating a relation and create a vector index on both **title** and **content**, and then we will fill it with our precomputed embeddings."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: a8918869-e54f-4e98-93ef-07cb093ebd32
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/Getting_started_with_AnalyticDB_and_OpenAI.ipynb", "title": "Using AnalyticDB as a vector database for OpenAI embeddings", "tokens": 2780, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"a8918869-e54f-4e98-93ef-07cb093ebd32\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/Getting_started_with_AnalyticDB_and_OpenAI.ipynb\", \"title\": \"Using AnalyticDB as a vector database for OpenAI embeddings\", \"tokens\": 2780, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"403de4ce-58aa-4e7f-9cee-9d74f3ccf644\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/Getting_started_with_AnalyticDB_and_OpenAI.ipynb\", \"title\": \"Using AnalyticDB as a vector database for OpenAI embeddings\", \"tokens\": 2780, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"436edb368979905aebf7d00f3f021a82934ad92a7e8acc7b5ffdec37c46878ca\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"0305ddf1-8a8c-4fce-a239-e2835db3656c\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/Getting_started_with_AnalyticDB_and_OpenAI.ipynb\", \"title\": \"Using AnalyticDB as a vector database for OpenAI embeddings\", \"tokens\": 2780, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"bef73a651edee0cbaa52454ce2d6913aa735fc07ecd30e9883dd591b64e89f81\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"bfdfe09b-8f6b-4696-9c0e-bbfeb001310e\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"4f7cf2e1128bcc8126b3749e93e7c6695b7934ba520280c8022905333f3dc75a\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 4204, \"end_char_idx\": 6855, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "403de4ce-58aa-4e7f-9cee-9d74f3ccf644", "doc_id": "403de4ce-58aa-4e7f-9cee-9d74f3ccf644", "ref_doc_id": "403de4ce-58aa-4e7f-9cee-9d74f3ccf644", "chroma:document": "```python\nimport wget\n\nembeddings_url = \"https://cdn.openai.com/API/examples/data/vector_database_wikipedia_articles_embedded.zip\"\n\n# The file is ~700 MB so this will take some time\nwget.download(embeddings_url)\n```\n\n    100% [......................................................................] 698933052 / 698933052\n\n\n\n\n    'vector_database_wikipedia_articles_embedded.zip'\n\n\n\nThe downloaded file has to be then extracted:\n\n\n```python\nimport zipfile\nimport os\nimport re\nimport tempfile\n\ncurrent_directory = os.getcwd()\nzip_file_path = os.path.join(current_directory, \"vector_database_wikipedia_articles_embedded.zip\")\noutput_directory = os.path.join(current_directory, \"../../data\")\n\nwith zipfile.ZipFile(zip_file_path, \"r\") as zip_ref:\n    zip_ref.extractall(output_directory)\n\n\n# check the csv file exist\nfile_name = \"vector_database_wikipedia_articles_embedded.csv\"\ndata_directory = os.path.join(current_directory, \"../../data\")\nfile_path = os.path.join(data_directory, file_name)\n\n\nif os.path.exists(file_path):\n    print(f\"The file {file_name} exists in the data directory.\")\nelse:\n    print(f\"The file {file_name} does not exist in the data directory.\")\n\n```\n\n    The file vector_database_wikipedia_articles_embedded.csv exists in the data directory.\n\n\n## Index data\n\nAnalyticDB stores data in __relation__ where each object is described by at least one vector. Our relation will be called **articles** and each object will be described by both **title** and **content** vectors. \\\n\nWe will start with creating a relation and create a vector index on both **title** and **content**, and then we will fill it with our precomputed embeddings.\n\n\n```python\ncreate_table_sql = '''\nCREATE TABLE IF NOT EXISTS public.articles (\n    id INTEGER NOT NULL,\n    url TEXT,\n    title TEXT,\n    content TEXT,\n    title_vector REAL[],\n    content_vector REAL[],\n    vector_id INTEGER\n);\n\nALTER TABLE public.articles ADD PRIMARY KEY (id);\n'''\n\n# SQL statement for creating indexes\ncreate_indexes_sql = '''\nCREATE INDEX ON public.articles USING ann (content_vector) WITH (distancemeasure = l2, dim = '1536', pq_segments = '64', hnsw_m = '100', pq_centers = '2048');\n\nCREATE INDEX ON public.articles USING ann (title_vector) WITH (distancemeasure = l2, dim = '1536', pq_segments = '64', hnsw_m = '100', pq_centers = '2048');\n'''\n\n# Execute the SQL statements\ncursor.execute(create_table_sql)\ncursor.execute(create_indexes_sql)\n\n# Commit the changes\nconnection.commit()\n```\n\n## Load data\n\nIn this section we are going to load the data prepared previous to this session, so you don't have to recompute the embeddings of Wikipedia articles with your own credits."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: bfdfe09b-8f6b-4696-9c0e-bbfeb001310e
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/Getting_started_with_AnalyticDB_and_OpenAI.ipynb", "title": "Using AnalyticDB as a vector database for OpenAI embeddings", "tokens": 2780, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"bfdfe09b-8f6b-4696-9c0e-bbfeb001310e\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/Getting_started_with_AnalyticDB_and_OpenAI.ipynb\", \"title\": \"Using AnalyticDB as a vector database for OpenAI embeddings\", \"tokens\": 2780, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"403de4ce-58aa-4e7f-9cee-9d74f3ccf644\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/Getting_started_with_AnalyticDB_and_OpenAI.ipynb\", \"title\": \"Using AnalyticDB as a vector database for OpenAI embeddings\", \"tokens\": 2780, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"436edb368979905aebf7d00f3f021a82934ad92a7e8acc7b5ffdec37c46878ca\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"a8918869-e54f-4e98-93ef-07cb093ebd32\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/Getting_started_with_AnalyticDB_and_OpenAI.ipynb\", \"title\": \"Using AnalyticDB as a vector database for OpenAI embeddings\", \"tokens\": 2780, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"dcdc5b4e8ebc30adf5f76a67448f62a878cb86a0755c49df215b6fd13a68f85f\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"9bfed376-64d7-4407-908d-6f5f163303c9\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"380abebc31013c6f9ccb12dbb7852bfee634f461c2e211ca9b03e43e3db116ea\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 5195, \"end_char_idx\": 8384, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "403de4ce-58aa-4e7f-9cee-9d74f3ccf644", "doc_id": "403de4ce-58aa-4e7f-9cee-9d74f3ccf644", "ref_doc_id": "403de4ce-58aa-4e7f-9cee-9d74f3ccf644", "chroma:document": "if os.path.exists(file_path):\n    print(f\"The file {file_name} exists in the data directory.\")\nelse:\n    print(f\"The file {file_name} does not exist in the data directory.\")\n\n```\n\n    The file vector_database_wikipedia_articles_embedded.csv exists in the data directory.\n\n\n## Index data\n\nAnalyticDB stores data in __relation__ where each object is described by at least one vector. Our relation will be called **articles** and each object will be described by both **title** and **content** vectors. \\\n\nWe will start with creating a relation and create a vector index on both **title** and **content**, and then we will fill it with our precomputed embeddings.\n\n\n```python\ncreate_table_sql = '''\nCREATE TABLE IF NOT EXISTS public.articles (\n    id INTEGER NOT NULL,\n    url TEXT,\n    title TEXT,\n    content TEXT,\n    title_vector REAL[],\n    content_vector REAL[],\n    vector_id INTEGER\n);\n\nALTER TABLE public.articles ADD PRIMARY KEY (id);\n'''\n\n# SQL statement for creating indexes\ncreate_indexes_sql = '''\nCREATE INDEX ON public.articles USING ann (content_vector) WITH (distancemeasure = l2, dim = '1536', pq_segments = '64', hnsw_m = '100', pq_centers = '2048');\n\nCREATE INDEX ON public.articles USING ann (title_vector) WITH (distancemeasure = l2, dim = '1536', pq_segments = '64', hnsw_m = '100', pq_centers = '2048');\n'''\n\n# Execute the SQL statements\ncursor.execute(create_table_sql)\ncursor.execute(create_indexes_sql)\n\n# Commit the changes\nconnection.commit()\n```\n\n## Load data\n\nIn this section we are going to load the data prepared previous to this session, so you don't have to recompute the embeddings of Wikipedia articles with your own credits.\n\n\n```python\nimport io\n\n# Path to your local CSV file\ncsv_file_path = '../../data/vector_database_wikipedia_articles_embedded.csv'\n\n# Define a generator function to process the file line by line\ndef process_file(file_path):\n    with open(file_path, 'r') as file:\n        for line in file:\n            # Replace '[' with '{' and ']' with '}'\n            modified_line = line.replace('[', '{').replace(']', '}')\n            yield modified_line\n\n# Create a StringIO object to store the modified lines\nmodified_lines = io.StringIO(''.join(list(process_file(csv_file_path))))\n\n# Create the COPY command for the copy_expert method\ncopy_command = '''\nCOPY public.articles (id, url, title, content, title_vector, content_vector, vector_id)\nFROM STDIN WITH (FORMAT CSV, HEADER true, DELIMITER ',');\n'''\n\n# Execute the COPY command using the copy_expert method\ncursor.copy_expert(copy_command, modified_lines)\n\n# Commit the changes\nconnection.commit()\n```\n\n\n```python\n# Check the collection size to make sure all the points have been stored\ncount_sql = \"\"\"select count(*) from public.articles;\"\"\"\ncursor.execute(count_sql)\nresult = cursor.fetchone()\nprint(f\"Count:{result[0]}\")\n\n```\n\n    Count:25000\n\n\n## Search data\n\nOnce the data is put into Qdrant we will start querying the collection for the closest vectors. We may provide an additional parameter `vector_name` to switch from title to content based search. Since the precomputed embeddings were created with `text-embedding-3-small` OpenAI model we also have to use it during search."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 9bfed376-64d7-4407-908d-6f5f163303c9
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/Getting_started_with_AnalyticDB_and_OpenAI.ipynb", "title": "Using AnalyticDB as a vector database for OpenAI embeddings", "tokens": 2780, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"9bfed376-64d7-4407-908d-6f5f163303c9\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/Getting_started_with_AnalyticDB_and_OpenAI.ipynb\", \"title\": \"Using AnalyticDB as a vector database for OpenAI embeddings\", \"tokens\": 2780, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"403de4ce-58aa-4e7f-9cee-9d74f3ccf644\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/Getting_started_with_AnalyticDB_and_OpenAI.ipynb\", \"title\": \"Using AnalyticDB as a vector database for OpenAI embeddings\", \"tokens\": 2780, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"436edb368979905aebf7d00f3f021a82934ad92a7e8acc7b5ffdec37c46878ca\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"bfdfe09b-8f6b-4696-9c0e-bbfeb001310e\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/Getting_started_with_AnalyticDB_and_OpenAI.ipynb\", \"title\": \"Using AnalyticDB as a vector database for OpenAI embeddings\", \"tokens\": 2780, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"b59250c6fc6801120e4a34b6473a5197ce00f8bb35f98e106f921231e7175d5e\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"79b14f65-855f-4c01-b963-9a6b20d0500a\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"d0a8ce63266db8f9fc793f11e091932a91b1a815c450471c0aedc04a8d1e4806\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 6858, \"end_char_idx\": 9171, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "403de4ce-58aa-4e7f-9cee-9d74f3ccf644", "doc_id": "403de4ce-58aa-4e7f-9cee-9d74f3ccf644", "ref_doc_id": "403de4ce-58aa-4e7f-9cee-9d74f3ccf644", "chroma:document": "```python\nimport io\n\n# Path to your local CSV file\ncsv_file_path = '../../data/vector_database_wikipedia_articles_embedded.csv'\n\n# Define a generator function to process the file line by line\ndef process_file(file_path):\n    with open(file_path, 'r') as file:\n        for line in file:\n            # Replace '[' with '{' and ']' with '}'\n            modified_line = line.replace('[', '{').replace(']', '}')\n            yield modified_line\n\n# Create a StringIO object to store the modified lines\nmodified_lines = io.StringIO(''.join(list(process_file(csv_file_path))))\n\n# Create the COPY command for the copy_expert method\ncopy_command = '''\nCOPY public.articles (id, url, title, content, title_vector, content_vector, vector_id)\nFROM STDIN WITH (FORMAT CSV, HEADER true, DELIMITER ',');\n'''\n\n# Execute the COPY command using the copy_expert method\ncursor.copy_expert(copy_command, modified_lines)\n\n# Commit the changes\nconnection.commit()\n```\n\n\n```python\n# Check the collection size to make sure all the points have been stored\ncount_sql = \"\"\"select count(*) from public.articles;\"\"\"\ncursor.execute(count_sql)\nresult = cursor.fetchone()\nprint(f\"Count:{result[0]}\")\n\n```\n\n    Count:25000\n\n\n## Search data\n\nOnce the data is put into Qdrant we will start querying the collection for the closest vectors. We may provide an additional parameter `vector_name` to switch from title to content based search. Since the precomputed embeddings were created with `text-embedding-3-small` OpenAI model we also have to use it during search.\n\n\n\n```python\ndef query_analyticdb(query, collection_name, vector_name=\"title_vector\", top_k=20):\n\n    # Creates embedding vector from user query\n    embedded_query = openai.Embedding.create(\n        input=query,\n        model=\"text-embedding-3-small\",\n    )[\"data\"][0][\"embedding\"]\n\n    # Convert the embedded_query to PostgreSQL compatible format\n    embedded_query_pg = \"{\" + \",\".join(map(str, embedded_query)) + \"}\"\n\n    # Create SQL query\n    query_sql = f\"\"\"\n    SELECT id, url, title, l2_distance({vector_name},'{embedded_query_pg}'::real[]) AS similarity\n    FROM {collection_name}\n    ORDER BY {vector_name} <-> '{embedded_query_pg}'::real[]\n    LIMIT {top_k};\n    \"\"\"\n    # Execute the query\n    cursor.execute(query_sql)\n    results = cursor.fetchall()\n\n    return results\n```"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 79b14f65-855f-4c01-b963-9a6b20d0500a
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/Getting_started_with_AnalyticDB_and_OpenAI.ipynb", "title": "Using AnalyticDB as a vector database for OpenAI embeddings", "tokens": 2780, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"79b14f65-855f-4c01-b963-9a6b20d0500a\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/Getting_started_with_AnalyticDB_and_OpenAI.ipynb\", \"title\": \"Using AnalyticDB as a vector database for OpenAI embeddings\", \"tokens\": 2780, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"403de4ce-58aa-4e7f-9cee-9d74f3ccf644\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/Getting_started_with_AnalyticDB_and_OpenAI.ipynb\", \"title\": \"Using AnalyticDB as a vector database for OpenAI embeddings\", \"tokens\": 2780, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"436edb368979905aebf7d00f3f021a82934ad92a7e8acc7b5ffdec37c46878ca\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"9bfed376-64d7-4407-908d-6f5f163303c9\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/Getting_started_with_AnalyticDB_and_OpenAI.ipynb\", \"title\": \"Using AnalyticDB as a vector database for OpenAI embeddings\", \"tokens\": 2780, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"5cd93a053b4c02b41ae81df608517224ff88ebce86fa3807356a92fcbc774769\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"04df7647-f31a-4853-aa43-43a0ea68e4d0\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"6ce52553ba68fd60408533b222c6b341632b7e2e06b15225e5616ccedf8b775a\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 7803, \"end_char_idx\": 10087, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "403de4ce-58aa-4e7f-9cee-9d74f3ccf644", "doc_id": "403de4ce-58aa-4e7f-9cee-9d74f3ccf644", "ref_doc_id": "403de4ce-58aa-4e7f-9cee-9d74f3ccf644", "chroma:document": "```python\n# Check the collection size to make sure all the points have been stored\ncount_sql = \"\"\"select count(*) from public.articles;\"\"\"\ncursor.execute(count_sql)\nresult = cursor.fetchone()\nprint(f\"Count:{result[0]}\")\n\n```\n\n    Count:25000\n\n\n## Search data\n\nOnce the data is put into Qdrant we will start querying the collection for the closest vectors. We may provide an additional parameter `vector_name` to switch from title to content based search. Since the precomputed embeddings were created with `text-embedding-3-small` OpenAI model we also have to use it during search.\n\n\n\n```python\ndef query_analyticdb(query, collection_name, vector_name=\"title_vector\", top_k=20):\n\n    # Creates embedding vector from user query\n    embedded_query = openai.Embedding.create(\n        input=query,\n        model=\"text-embedding-3-small\",\n    )[\"data\"][0][\"embedding\"]\n\n    # Convert the embedded_query to PostgreSQL compatible format\n    embedded_query_pg = \"{\" + \",\".join(map(str, embedded_query)) + \"}\"\n\n    # Create SQL query\n    query_sql = f\"\"\"\n    SELECT id, url, title, l2_distance({vector_name},'{embedded_query_pg}'::real[]) AS similarity\n    FROM {collection_name}\n    ORDER BY {vector_name} <-> '{embedded_query_pg}'::real[]\n    LIMIT {top_k};\n    \"\"\"\n    # Execute the query\n    cursor.execute(query_sql)\n    results = cursor.fetchall()\n\n    return results\n```\n\n\n```python\nimport openai\n\nquery_results = query_analyticdb(\"modern art in Europe\", \"Articles\")\nfor i, result in enumerate(query_results):\n    print(f\"{i + 1}. {result[2]} (Score: {round(1 - result[3], 3)})\")\n```\n\n    1. Museum of Modern Art (Score: 0.75)\n    2. Western Europe (Score: 0.735)\n    3. Renaissance art (Score: 0.728)\n    4. Pop art (Score: 0.721)\n    5. Northern Europe (Score: 0.71)\n    6. Hellenistic art (Score: 0.706)\n    7. Modernist literature (Score: 0.694)\n    8. Art film (Score: 0.687)\n    9. Central Europe (Score: 0.685)\n    10. European (Score: 0.683)\n    11. Art (Score: 0.683)\n    12. Byzantine art (Score: 0.682)\n    13. Postmodernism (Score: 0.68)\n    14. Eastern Europe (Score: 0.679)\n    15. Europe (Score: 0.678)\n    16. Cubism (Score: 0.678)\n    17. Impressionism (Score: 0.677)\n    18. Bauhaus (Score: 0.676)\n    19. Surrealism (Score: 0.674)\n    20. Expressionism (Score: 0.674)"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 04df7647-f31a-4853-aa43-43a0ea68e4d0
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/Getting_started_with_AnalyticDB_and_OpenAI.ipynb", "title": "Using AnalyticDB as a vector database for OpenAI embeddings", "tokens": 2780, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"04df7647-f31a-4853-aa43-43a0ea68e4d0\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/Getting_started_with_AnalyticDB_and_OpenAI.ipynb\", \"title\": \"Using AnalyticDB as a vector database for OpenAI embeddings\", \"tokens\": 2780, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"403de4ce-58aa-4e7f-9cee-9d74f3ccf644\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/Getting_started_with_AnalyticDB_and_OpenAI.ipynb\", \"title\": \"Using AnalyticDB as a vector database for OpenAI embeddings\", \"tokens\": 2780, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"436edb368979905aebf7d00f3f021a82934ad92a7e8acc7b5ffdec37c46878ca\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"79b14f65-855f-4c01-b963-9a6b20d0500a\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/Getting_started_with_AnalyticDB_and_OpenAI.ipynb\", \"title\": \"Using AnalyticDB as a vector database for OpenAI embeddings\", \"tokens\": 2780, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"d67ef0f29174c6bdc9331dc485420a3cf7a7009ed5204e1008d8e6e79828a2e2\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 9174, \"end_char_idx\": 11060, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "403de4ce-58aa-4e7f-9cee-9d74f3ccf644", "doc_id": "403de4ce-58aa-4e7f-9cee-9d74f3ccf644", "ref_doc_id": "403de4ce-58aa-4e7f-9cee-9d74f3ccf644", "chroma:document": "```python\nimport openai\n\nquery_results = query_analyticdb(\"modern art in Europe\", \"Articles\")\nfor i, result in enumerate(query_results):\n    print(f\"{i + 1}. {result[2]} (Score: {round(1 - result[3], 3)})\")\n```\n\n    1. Museum of Modern Art (Score: 0.75)\n    2. Western Europe (Score: 0.735)\n    3. Renaissance art (Score: 0.728)\n    4. Pop art (Score: 0.721)\n    5. Northern Europe (Score: 0.71)\n    6. Hellenistic art (Score: 0.706)\n    7. Modernist literature (Score: 0.694)\n    8. Art film (Score: 0.687)\n    9. Central Europe (Score: 0.685)\n    10. European (Score: 0.683)\n    11. Art (Score: 0.683)\n    12. Byzantine art (Score: 0.682)\n    13. Postmodernism (Score: 0.68)\n    14. Eastern Europe (Score: 0.679)\n    15. Europe (Score: 0.678)\n    16. Cubism (Score: 0.678)\n    17. Impressionism (Score: 0.677)\n    18. Bauhaus (Score: 0.676)\n    19. Surrealism (Score: 0.674)\n    20. Expressionism (Score: 0.674)\n\n\n\n```python\n# This time we'll query using content vector\nquery_results = query_analyticdb(\"Famous battles in Scottish history\", \"Articles\", \"content_vector\")\nfor i, result in enumerate(query_results):\n    print(f\"{i + 1}. {result[2]} (Score: {round(1 - result[3], 3)})\")\n```\n\n    1. Battle of Bannockburn (Score: 0.739)\n    2. Wars of Scottish Independence (Score: 0.723)\n    3. 1651 (Score: 0.705)\n    4. First War of Scottish Independence (Score: 0.699)\n    5. Robert I of Scotland (Score: 0.692)\n    6. 841 (Score: 0.688)\n    7. 1716 (Score: 0.688)\n    8. 1314 (Score: 0.674)\n    9. 1263 (Score: 0.673)\n    10. William Wallace (Score: 0.671)\n    11. Stirling (Score: 0.663)\n    12. 1306 (Score: 0.662)\n    13. 1746 (Score: 0.661)\n    14. 1040s (Score: 0.656)\n    15. 1106 (Score: 0.654)\n    16. 1304 (Score: 0.653)\n    17. David II of Scotland (Score: 0.65)\n    18. Braveheart (Score: 0.649)\n    19. 1124 (Score: 0.648)\n    20. July 27 (Score: 0.646)\n\n\n\n```python\n\n```"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: cb368c1a-c9fd-4b93-adda-b503ff3fd0d4
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/QA_with_Langchain_AnalyticDB_and_OpenAI.ipynb", "title": "Question Answering with Langchain, AnalyticDB and OpenAI", "tokens": 3679, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"cb368c1a-c9fd-4b93-adda-b503ff3fd0d4\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/QA_with_Langchain_AnalyticDB_and_OpenAI.ipynb\", \"title\": \"Question Answering with Langchain, AnalyticDB and OpenAI\", \"tokens\": 3679, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"c32cd4ac-3abc-4016-be01-7ba09b19ee2c\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/QA_with_Langchain_AnalyticDB_and_OpenAI.ipynb\", \"title\": \"Question Answering with Langchain, AnalyticDB and OpenAI\", \"tokens\": 3679, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"8199fc7bc08996c70008990b9b86977ab403c583667423b770ca2dd6a2906b8f\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"bf804f28-fe64-4bd1-9ce7-e18609aae144\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"d7a506978c21fb9b927d19497ba294e0dd3b1522b75af18a64e0397330b37d8d\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 0, \"end_char_idx\": 3195, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "c32cd4ac-3abc-4016-be01-7ba09b19ee2c", "doc_id": "c32cd4ac-3abc-4016-be01-7ba09b19ee2c", "ref_doc_id": "c32cd4ac-3abc-4016-be01-7ba09b19ee2c", "chroma:document": "# Question Answering with Langchain, AnalyticDB and OpenAI\nThis notebook presents how to implement a Question Answering system with Langchain, AnalyticDB as a knowledge based and OpenAI embeddings. If you are not familiar with AnalyticDB, it\u2019s better to check out the [Getting_started_with_AnalyticDB_and_OpenAI.ipynb](Getting_started_with_AnalyticDB_and_OpenAI.ipynb) notebook.\n\nThis notebook presents an end-to-end process of:\n- Calculating the embeddings with OpenAI API.\n- Storing the embeddings in an AnalyticDB instance to build a knowledge base.\n- Converting raw text query to an embedding with OpenAI API.\n- Using AnalyticDB to perform the nearest neighbour search in the created collection to find some context.\n- Asking LLM to find the answer in a given context.\n\nAll the steps will be simplified to calling some corresponding Langchain methods.\n\n## Prerequisites\nFor the purposes of this exercise we need to prepare a couple of things:\n[AnalyticDB cloud instance](https://www.alibabacloud.com/help/en/analyticdb-for-postgresql/latest/product-introduction-overview).\n[Langchain](https://github.com/hwchase17/langchain) as a framework.\nAn OpenAI API key.\n\n### Install requirements\nThis notebook requires the following Python packages: `openai`, `tiktoken`, `langchain` and `psycopg2cffi`.\n- `openai` provides convenient access to the OpenAI API.\n- `tiktoken` is a fast BPE tokeniser for use with OpenAI's models.\n- `langchain` helps us to build applications with LLM more easily.\n- `psycopg2cffi` library is used to interact with the vector database, but any other PostgreSQL client library is also acceptable.\n\n\n```python\n! pip install openai tiktoken langchain psycopg2cffi \n```\n\n\n```python\n! export OPENAI_API_KEY=\"your API key\"\n```\n\n\n```python\n# Test that your OpenAI API key is correctly set as an environment variable\n# Note. if you run this notebook locally, you will need to reload your terminal and the notebook for the env variables to be live.\nimport os\n\n# Note. alternatively you can set a temporary env variable like this:\n# os.environ[\"OPENAI_API_KEY\"] = \"sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\"\n\nif os.getenv(\"OPENAI_API_KEY\") is not None:\n    print(\"OPENAI_API_KEY is ready\")\nelse:\n    print(\"OPENAI_API_KEY environment variable not found\")\n```\n\n    OPENAI_API_KEY is ready\n\n\n### Prepare your OpenAI API key\nThe OpenAI API key is used for vectorization of the documents and queries.\n\nIf you don't have an OpenAI API key, you can get one from [https://platform.openai.com/account/api-keys ).\n\nOnce you get your key, please add it to your environment variables as `OPENAI_API_KEY` by running following command:\n\n### Prepare your AnalyticDB connection string\nTo build the AnalyticDB connection string, you need to have the following parameters: `PG_HOST`, `PG_PORT`, `PG_DATABASE`, `PG_USER`, and `PG_PASSWORD`. You need to export them first to set correct connect string. Then build the connection string.\n\n\n```python\n! export PG_HOST=\"your AnalyticDB host url\"\n! export PG_PORT=5432 # Optional, default value is 5432\n! export PG_DATABASE=postgres # Optional, default value is postgres\n! export PG_USER=\"your username\"\n! export PG_PASSWORD=\"your password\"\n```"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: bf804f28-fe64-4bd1-9ce7-e18609aae144
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/QA_with_Langchain_AnalyticDB_and_OpenAI.ipynb", "title": "Question Answering with Langchain, AnalyticDB and OpenAI", "tokens": 3679, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"bf804f28-fe64-4bd1-9ce7-e18609aae144\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/QA_with_Langchain_AnalyticDB_and_OpenAI.ipynb\", \"title\": \"Question Answering with Langchain, AnalyticDB and OpenAI\", \"tokens\": 3679, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"c32cd4ac-3abc-4016-be01-7ba09b19ee2c\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/QA_with_Langchain_AnalyticDB_and_OpenAI.ipynb\", \"title\": \"Question Answering with Langchain, AnalyticDB and OpenAI\", \"tokens\": 3679, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"8199fc7bc08996c70008990b9b86977ab403c583667423b770ca2dd6a2906b8f\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"cb368c1a-c9fd-4b93-adda-b503ff3fd0d4\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/QA_with_Langchain_AnalyticDB_and_OpenAI.ipynb\", \"title\": \"Question Answering with Langchain, AnalyticDB and OpenAI\", \"tokens\": 3679, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"c93724e2d98d7f06e5f660fb9cb6772be7c92f7becdea467f2802ac98b921844\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"938fade8-1af6-4949-b4df-a235c79fc55f\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"c9617e590c550fe2d103fc3983b663bb57d96470cf03450c6790b7179a3339be\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 1622, \"end_char_idx\": 4641, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "c32cd4ac-3abc-4016-be01-7ba09b19ee2c", "doc_id": "c32cd4ac-3abc-4016-be01-7ba09b19ee2c", "ref_doc_id": "c32cd4ac-3abc-4016-be01-7ba09b19ee2c", "chroma:document": "```python\n! pip install openai tiktoken langchain psycopg2cffi \n```\n\n\n```python\n! export OPENAI_API_KEY=\"your API key\"\n```\n\n\n```python\n# Test that your OpenAI API key is correctly set as an environment variable\n# Note. if you run this notebook locally, you will need to reload your terminal and the notebook for the env variables to be live.\nimport os\n\n# Note. alternatively you can set a temporary env variable like this:\n# os.environ[\"OPENAI_API_KEY\"] = \"sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\"\n\nif os.getenv(\"OPENAI_API_KEY\") is not None:\n    print(\"OPENAI_API_KEY is ready\")\nelse:\n    print(\"OPENAI_API_KEY environment variable not found\")\n```\n\n    OPENAI_API_KEY is ready\n\n\n### Prepare your OpenAI API key\nThe OpenAI API key is used for vectorization of the documents and queries.\n\nIf you don't have an OpenAI API key, you can get one from [https://platform.openai.com/account/api-keys ).\n\nOnce you get your key, please add it to your environment variables as `OPENAI_API_KEY` by running following command:\n\n### Prepare your AnalyticDB connection string\nTo build the AnalyticDB connection string, you need to have the following parameters: `PG_HOST`, `PG_PORT`, `PG_DATABASE`, `PG_USER`, and `PG_PASSWORD`. You need to export them first to set correct connect string. Then build the connection string.\n\n\n```python\n! export PG_HOST=\"your AnalyticDB host url\"\n! export PG_PORT=5432 # Optional, default value is 5432\n! export PG_DATABASE=postgres # Optional, default value is postgres\n! export PG_USER=\"your username\"\n! export PG_PASSWORD=\"your password\"\n```\n\n\n```python\nimport os\nfrom langchain.vectorstores.analyticdb import AnalyticDB\n\nCONNECTION_STRING = AnalyticDB.connection_string_from_db_params(\n    driver=os.environ.get(\"PG_DRIVER\", \"psycopg2cffi\"),\n    host=os.environ.get(\"PG_HOST\", \"localhost\"),\n    port=int(os.environ.get(\"PG_PORT\", \"5432\")),\n    database=os.environ.get(\"PG_DATABASE\", \"postgres\"),\n    user=os.environ.get(\"PG_USER\", \"postgres\"),\n    password=os.environ.get(\"PG_PASSWORD\", \"postgres\"),\n)\n```\n\n\n```python\nimport json\n\nwith open(\"questions.json\", \"r\") as fp:\n    questions = json.load(fp)\n\nwith open(\"answers.json\", \"r\") as fp:\n    answers = json.load(fp)\n```\n\n## Load data\nIn this section we are going to load the data containing some natural questions and answers to them. All the data will be used to create a Langchain application with AnalyticDB being the knowledge base.\n\n\n```python\nprint(questions[0])\n```\n\n    when is the last episode of season 8 of the walking dead\n\n\n\n```python\nimport wget\n\n# All the examples come from https://ai.google.com/research/NaturalQuestions\n# This is a sample of the training set that we download and extract for some\n# further processing.\nwget.download(\"https://storage.googleapis.com/dataset-natural-questions/questions.json\")\nwget.download(\"https://storage.googleapis.com/dataset-natural-questions/answers.json\")\n```\n\n\n```python\nprint(answers[0])\n```\n\n    No . overall No. in season Title Directed by Written by Original air date U.S."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 938fade8-1af6-4949-b4df-a235c79fc55f
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/QA_with_Langchain_AnalyticDB_and_OpenAI.ipynb", "title": "Question Answering with Langchain, AnalyticDB and OpenAI", "tokens": 3679, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"938fade8-1af6-4949-b4df-a235c79fc55f\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/QA_with_Langchain_AnalyticDB_and_OpenAI.ipynb\", \"title\": \"Question Answering with Langchain, AnalyticDB and OpenAI\", \"tokens\": 3679, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"c32cd4ac-3abc-4016-be01-7ba09b19ee2c\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/QA_with_Langchain_AnalyticDB_and_OpenAI.ipynb\", \"title\": \"Question Answering with Langchain, AnalyticDB and OpenAI\", \"tokens\": 3679, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"8199fc7bc08996c70008990b9b86977ab403c583667423b770ca2dd6a2906b8f\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"bf804f28-fe64-4bd1-9ce7-e18609aae144\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/QA_with_Langchain_AnalyticDB_and_OpenAI.ipynb\", \"title\": \"Question Answering with Langchain, AnalyticDB and OpenAI\", \"tokens\": 3679, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"63101a5efe5c17802f11aca690048e664c04e004d6f8444522393d6771bd897a\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"ef651734-9abb-497f-a143-5d0cce6e4061\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"17c202e3bcc232572bf173037fc46d2538d48c0ccdb49247e493b304d12248c2\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 3198, \"end_char_idx\": 6355, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "c32cd4ac-3abc-4016-be01-7ba09b19ee2c", "doc_id": "c32cd4ac-3abc-4016-be01-7ba09b19ee2c", "ref_doc_id": "c32cd4ac-3abc-4016-be01-7ba09b19ee2c", "chroma:document": "```python\nimport os\nfrom langchain.vectorstores.analyticdb import AnalyticDB\n\nCONNECTION_STRING = AnalyticDB.connection_string_from_db_params(\n    driver=os.environ.get(\"PG_DRIVER\", \"psycopg2cffi\"),\n    host=os.environ.get(\"PG_HOST\", \"localhost\"),\n    port=int(os.environ.get(\"PG_PORT\", \"5432\")),\n    database=os.environ.get(\"PG_DATABASE\", \"postgres\"),\n    user=os.environ.get(\"PG_USER\", \"postgres\"),\n    password=os.environ.get(\"PG_PASSWORD\", \"postgres\"),\n)\n```\n\n\n```python\nimport json\n\nwith open(\"questions.json\", \"r\") as fp:\n    questions = json.load(fp)\n\nwith open(\"answers.json\", \"r\") as fp:\n    answers = json.load(fp)\n```\n\n## Load data\nIn this section we are going to load the data containing some natural questions and answers to them. All the data will be used to create a Langchain application with AnalyticDB being the knowledge base.\n\n\n```python\nprint(questions[0])\n```\n\n    when is the last episode of season 8 of the walking dead\n\n\n\n```python\nimport wget\n\n# All the examples come from https://ai.google.com/research/NaturalQuestions\n# This is a sample of the training set that we download and extract for some\n# further processing.\nwget.download(\"https://storage.googleapis.com/dataset-natural-questions/questions.json\")\nwget.download(\"https://storage.googleapis.com/dataset-natural-questions/answers.json\")\n```\n\n\n```python\nprint(answers[0])\n```\n\n    No . overall No. in season Title Directed by Written by Original air date U.S. viewers ( millions ) 100 `` Mercy '' Greg Nicotero Scott M. Gimple October 22 , 2017 ( 2017 - 10 - 22 ) 11.44 Rick , Maggie , and Ezekiel rally their communities together to take down Negan . Gregory attempts to have the Hilltop residents side with Negan , but they all firmly stand behind Maggie . The group attacks the Sanctuary , taking down its fences and flooding the compound with walkers . With the Sanctuary defaced , everyone leaves except Gabriel , who reluctantly stays to save Gregory , but is left behind when Gregory abandons him . Surrounded by walkers , Gabriel hides in a trailer , where he is trapped inside with Negan . 101 `` The Damned '' Rosemary Rodriguez Matthew Negrete & Channing Powell October 29 , 2017 ( 2017 - 10 - 29 ) 8.92 Rick 's forces split into separate parties to attack several of the Saviors ' outposts , during which many members of the group are killed ; Eric is critically injured and rushed away by Aaron . Jesus stops Tara and Morgan from executing a group of surrendered Saviors . While clearing an outpost with Daryl , Rick is confronted and held at gunpoint by Morales , a survivor he met in the initial Atlanta camp , who is now with the Saviors . 102 `` Monsters '' Greg Nicotero Matthew Negrete & Channing Powell November 5 , 2017 ( 2017 - 11 - 05 ) 8.52 Daryl finds Morales threatening Rick and kills him ; the duo then pursue a group of Saviors who are transporting weapons to another outpost . Gregory returns to Hilltop , and after a heated argument , Maggie ultimately allows him back in the community . Eric dies from his injuries , leaving Aaron distraught . Despite Tara and Morgan 's objections , Jesus leads the group of surrendered Saviors to Hilltop ."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: ef651734-9abb-497f-a143-5d0cce6e4061
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/QA_with_Langchain_AnalyticDB_and_OpenAI.ipynb", "title": "Question Answering with Langchain, AnalyticDB and OpenAI", "tokens": 3679, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"ef651734-9abb-497f-a143-5d0cce6e4061\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/QA_with_Langchain_AnalyticDB_and_OpenAI.ipynb\", \"title\": \"Question Answering with Langchain, AnalyticDB and OpenAI\", \"tokens\": 3679, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"c32cd4ac-3abc-4016-be01-7ba09b19ee2c\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/QA_with_Langchain_AnalyticDB_and_OpenAI.ipynb\", \"title\": \"Question Answering with Langchain, AnalyticDB and OpenAI\", \"tokens\": 3679, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"8199fc7bc08996c70008990b9b86977ab403c583667423b770ca2dd6a2906b8f\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"938fade8-1af6-4949-b4df-a235c79fc55f\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/QA_with_Langchain_AnalyticDB_and_OpenAI.ipynb\", \"title\": \"Question Answering with Langchain, AnalyticDB and OpenAI\", \"tokens\": 3679, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"820ba7fd1668911b5209614d0a86b7b5491a5810fc175dc6c6fb98c16bc71d9b\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"36c37c68-eed8-4e6b-b310-964d1200de95\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"73dbbccf7f3338adc8c15bf29974e78704fc37f172cc4fad6cf91b73ca10884e\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 4834, \"end_char_idx\": 8053, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "c32cd4ac-3abc-4016-be01-7ba09b19ee2c", "doc_id": "c32cd4ac-3abc-4016-be01-7ba09b19ee2c", "ref_doc_id": "c32cd4ac-3abc-4016-be01-7ba09b19ee2c", "chroma:document": "Gregory attempts to have the Hilltop residents side with Negan , but they all firmly stand behind Maggie . The group attacks the Sanctuary , taking down its fences and flooding the compound with walkers . With the Sanctuary defaced , everyone leaves except Gabriel , who reluctantly stays to save Gregory , but is left behind when Gregory abandons him . Surrounded by walkers , Gabriel hides in a trailer , where he is trapped inside with Negan . 101 `` The Damned '' Rosemary Rodriguez Matthew Negrete & Channing Powell October 29 , 2017 ( 2017 - 10 - 29 ) 8.92 Rick 's forces split into separate parties to attack several of the Saviors ' outposts , during which many members of the group are killed ; Eric is critically injured and rushed away by Aaron . Jesus stops Tara and Morgan from executing a group of surrendered Saviors . While clearing an outpost with Daryl , Rick is confronted and held at gunpoint by Morales , a survivor he met in the initial Atlanta camp , who is now with the Saviors . 102 `` Monsters '' Greg Nicotero Matthew Negrete & Channing Powell November 5 , 2017 ( 2017 - 11 - 05 ) 8.52 Daryl finds Morales threatening Rick and kills him ; the duo then pursue a group of Saviors who are transporting weapons to another outpost . Gregory returns to Hilltop , and after a heated argument , Maggie ultimately allows him back in the community . Eric dies from his injuries , leaving Aaron distraught . Despite Tara and Morgan 's objections , Jesus leads the group of surrendered Saviors to Hilltop . Ezekiel 's group attacks another Savior compound , during which several Kingdommers are shot while protecting Ezekiel . 103 `` Some Guy '' Dan Liu David Leslie Johnson November 12 , 2017 ( 2017 - 11 - 12 ) 8.69 Ezekiel 's group is overwhelmed by the Saviors , who kill all of them except for Ezekiel himself and Jerry . Carol clears the inside of the compound , killing all but two Saviors , who almost escape but are eventually caught by Rick and Daryl . En route to the Kingdom , Ezekiel , Jerry , and Carol are surrounded by walkers , but Shiva sacrifices herself to save them . The trio returns to the Kingdom , where Ezekiel 's confidence in himself as a leader has diminished . 104 5 `` The Big Scary U '' Michael E. Satrazemis Story by : Scott M. Gimple & David Leslie Johnson & Angela Kang Teleplay by : David Leslie Johnson & Angela Kang November 19 , 2017 ( 2017 - 11 - 19 ) 7.85 After confessing their sins to each other , Gabriel and Negan manage to escape from the trailer . Simon and the other lieutenants grow suspicious of each other , knowing that Rick 's forces must have inside information . The workers in the Sanctuary become increasingly frustrated with their living conditions , and a riot nearly ensues , until Negan returns and restores order . Gabriel is locked in a cell , where Eugene discovers him sick and suffering . Meanwhile , Rick and Daryl argue over how to take out the Saviors , leading Daryl to abandon Rick . 105 6 `` The King , the Widow , and Rick '' John Polson Angela Kang & Corey Reed November 26 , 2017 ( 2017 - 11 - 26 ) 8.28 Rick visits Jadis in hopes of convincing her to turn against Negan ; Jadis refuses , and locks Rick in a shipping container ."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 36c37c68-eed8-4e6b-b310-964d1200de95
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/QA_with_Langchain_AnalyticDB_and_OpenAI.ipynb", "title": "Question Answering with Langchain, AnalyticDB and OpenAI", "tokens": 3679, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"36c37c68-eed8-4e6b-b310-964d1200de95\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/QA_with_Langchain_AnalyticDB_and_OpenAI.ipynb\", \"title\": \"Question Answering with Langchain, AnalyticDB and OpenAI\", \"tokens\": 3679, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"c32cd4ac-3abc-4016-be01-7ba09b19ee2c\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/QA_with_Langchain_AnalyticDB_and_OpenAI.ipynb\", \"title\": \"Question Answering with Langchain, AnalyticDB and OpenAI\", \"tokens\": 3679, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"8199fc7bc08996c70008990b9b86977ab403c583667423b770ca2dd6a2906b8f\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"ef651734-9abb-497f-a143-5d0cce6e4061\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/QA_with_Langchain_AnalyticDB_and_OpenAI.ipynb\", \"title\": \"Question Answering with Langchain, AnalyticDB and OpenAI\", \"tokens\": 3679, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"1fad615f63ad9696368dad579388c8335365d28f0bf84602e1c3e18bc148b89a\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"180f956a-3a1e-4f01-bb22-892d08b39c28\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"cb60107c065b20a505236b4a783526f253147b90402d4c55b8dd05c8edabd56c\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 6476, \"end_char_idx\": 9569, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "c32cd4ac-3abc-4016-be01-7ba09b19ee2c", "doc_id": "c32cd4ac-3abc-4016-be01-7ba09b19ee2c", "ref_doc_id": "c32cd4ac-3abc-4016-be01-7ba09b19ee2c", "chroma:document": "103 `` Some Guy '' Dan Liu David Leslie Johnson November 12 , 2017 ( 2017 - 11 - 12 ) 8.69 Ezekiel 's group is overwhelmed by the Saviors , who kill all of them except for Ezekiel himself and Jerry . Carol clears the inside of the compound , killing all but two Saviors , who almost escape but are eventually caught by Rick and Daryl . En route to the Kingdom , Ezekiel , Jerry , and Carol are surrounded by walkers , but Shiva sacrifices herself to save them . The trio returns to the Kingdom , where Ezekiel 's confidence in himself as a leader has diminished . 104 5 `` The Big Scary U '' Michael E. Satrazemis Story by : Scott M. Gimple & David Leslie Johnson & Angela Kang Teleplay by : David Leslie Johnson & Angela Kang November 19 , 2017 ( 2017 - 11 - 19 ) 7.85 After confessing their sins to each other , Gabriel and Negan manage to escape from the trailer . Simon and the other lieutenants grow suspicious of each other , knowing that Rick 's forces must have inside information . The workers in the Sanctuary become increasingly frustrated with their living conditions , and a riot nearly ensues , until Negan returns and restores order . Gabriel is locked in a cell , where Eugene discovers him sick and suffering . Meanwhile , Rick and Daryl argue over how to take out the Saviors , leading Daryl to abandon Rick . 105 6 `` The King , the Widow , and Rick '' John Polson Angela Kang & Corey Reed November 26 , 2017 ( 2017 - 11 - 26 ) 8.28 Rick visits Jadis in hopes of convincing her to turn against Negan ; Jadis refuses , and locks Rick in a shipping container . Carl encounters Siddiq in the woods and recruits him to Alexandria . Daryl and Tara plot to deviate from Rick 's plans by destroying the Sanctuary . Ezekiel isolates himself at the Kingdom , where Carol tries to encourage him to be the leader his people need . Maggie has the group of captured Saviors placed in a holding area and forces Gregory to join them as punishment for betraying Hilltop . 106 7 `` Time for After '' Larry Teng Matthew Negrete & Corey Reed December 3 , 2017 ( 2017 - 12 - 03 ) 7.47 After learning of Dwight 's association with Rick 's group , Eugene affirms his loyalty to Negan and outlines a plan to get rid of the walkers surrounding the Sanctuary . With help from Morgan and Tara , Daryl drives a truck through the Sanctuary 's walls , flooding its interior with walkers , killing many Saviors . Rick finally convinces Jadis and the Scavengers to align with him , and they plan to force the Saviors to surrender . However , when they arrive at the Sanctuary , Rick is horrified to see the breached walls and no sign of the walker herd . 107 8 `` How It 's Gotta Be '' Michael E. Satrazemis David Leslie Johnson & Angela Kang December 10 , 2017 ( 2017 - 12 - 10 ) 7.89 Eugene 's plan allows the Saviors to escape , and separately , the Saviors waylay the Alexandria , Hilltop , and Kingdom forces . The Scavengers abandon Rick , after which he returns to Alexandria . Ezekiel ensures that the Kingdom residents are able to escape before locking himself in the community with the Saviors ."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 180f956a-3a1e-4f01-bb22-892d08b39c28
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/QA_with_Langchain_AnalyticDB_and_OpenAI.ipynb", "title": "Question Answering with Langchain, AnalyticDB and OpenAI", "tokens": 3679, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"180f956a-3a1e-4f01-bb22-892d08b39c28\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/QA_with_Langchain_AnalyticDB_and_OpenAI.ipynb\", \"title\": \"Question Answering with Langchain, AnalyticDB and OpenAI\", \"tokens\": 3679, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"c32cd4ac-3abc-4016-be01-7ba09b19ee2c\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/QA_with_Langchain_AnalyticDB_and_OpenAI.ipynb\", \"title\": \"Question Answering with Langchain, AnalyticDB and OpenAI\", \"tokens\": 3679, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"8199fc7bc08996c70008990b9b86977ab403c583667423b770ca2dd6a2906b8f\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"36c37c68-eed8-4e6b-b310-964d1200de95\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/QA_with_Langchain_AnalyticDB_and_OpenAI.ipynb\", \"title\": \"Question Answering with Langchain, AnalyticDB and OpenAI\", \"tokens\": 3679, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"93488f260aad9845748b9f93c8e56bd44f926650467251cfdcadecc1a7690fc9\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"d16c0b57-2821-45a3-bb6f-b6669e23db28\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"fb3744ea7d5f5bf0abea2d5e69e6ccfb42772b1baf08b548458e0081534db0d6\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 8054, \"end_char_idx\": 10845, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "c32cd4ac-3abc-4016-be01-7ba09b19ee2c", "doc_id": "c32cd4ac-3abc-4016-be01-7ba09b19ee2c", "ref_doc_id": "c32cd4ac-3abc-4016-be01-7ba09b19ee2c", "chroma:document": "Carl encounters Siddiq in the woods and recruits him to Alexandria . Daryl and Tara plot to deviate from Rick 's plans by destroying the Sanctuary . Ezekiel isolates himself at the Kingdom , where Carol tries to encourage him to be the leader his people need . Maggie has the group of captured Saviors placed in a holding area and forces Gregory to join them as punishment for betraying Hilltop . 106 7 `` Time for After '' Larry Teng Matthew Negrete & Corey Reed December 3 , 2017 ( 2017 - 12 - 03 ) 7.47 After learning of Dwight 's association with Rick 's group , Eugene affirms his loyalty to Negan and outlines a plan to get rid of the walkers surrounding the Sanctuary . With help from Morgan and Tara , Daryl drives a truck through the Sanctuary 's walls , flooding its interior with walkers , killing many Saviors . Rick finally convinces Jadis and the Scavengers to align with him , and they plan to force the Saviors to surrender . However , when they arrive at the Sanctuary , Rick is horrified to see the breached walls and no sign of the walker herd . 107 8 `` How It 's Gotta Be '' Michael E. Satrazemis David Leslie Johnson & Angela Kang December 10 , 2017 ( 2017 - 12 - 10 ) 7.89 Eugene 's plan allows the Saviors to escape , and separately , the Saviors waylay the Alexandria , Hilltop , and Kingdom forces . The Scavengers abandon Rick , after which he returns to Alexandria . Ezekiel ensures that the Kingdom residents are able to escape before locking himself in the community with the Saviors . Eugene aids Gabriel and Doctor Carson in escaping the Sanctuary in order to ease his conscience . Negan attacks Alexandria , but Carl devises a plan to allow the Alexandria residents to escape into the sewers . Carl reveals he was bitten by a walker while escorting Siddiq to Alexandria . 108 9 `` Honor '' Greg Nicotero Matthew Negrete & Channing Powell February 25 , 2018 ( 2018 - 02 - 25 ) 8.28 After the Saviors leave Alexandria , the survivors make for the Hilltop while Rick and Michonne stay behind to say their final goodbyes to a dying Carl , who pleads with Rick to build a better future alongside the Saviors before killing himself . In the Kingdom , Morgan and Carol launch a rescue mission for Ezekiel . Although they are successful and retake the Kingdom , the Saviors ' lieutenant Gavin is killed by Benjamin 's vengeful brother Henry . 109 10 `` The Lost and the Plunderers '' TBA TBA March 4 , 2018 ( 2018 - 03 - 04 ) TBD 110 11 `` Dead or Alive Or '' TBA TBA March 11 , 2018 ( 2018 - 03 - 11 ) TBD 111 12 `` The Key '' TBA TBA March 18 , 2018 ( 2018 - 03 - 18 ) TBD\n\n\n## Chain definition\n\nLangchain is already integrated with AnalyticDB and performs all the indexing for given list of documents. In our case we are going to store the set of answers we have."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: d16c0b57-2821-45a3-bb6f-b6669e23db28
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/QA_with_Langchain_AnalyticDB_and_OpenAI.ipynb", "title": "Question Answering with Langchain, AnalyticDB and OpenAI", "tokens": 3679, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"d16c0b57-2821-45a3-bb6f-b6669e23db28\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/QA_with_Langchain_AnalyticDB_and_OpenAI.ipynb\", \"title\": \"Question Answering with Langchain, AnalyticDB and OpenAI\", \"tokens\": 3679, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"c32cd4ac-3abc-4016-be01-7ba09b19ee2c\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/QA_with_Langchain_AnalyticDB_and_OpenAI.ipynb\", \"title\": \"Question Answering with Langchain, AnalyticDB and OpenAI\", \"tokens\": 3679, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"8199fc7bc08996c70008990b9b86977ab403c583667423b770ca2dd6a2906b8f\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"180f956a-3a1e-4f01-bb22-892d08b39c28\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/QA_with_Langchain_AnalyticDB_and_OpenAI.ipynb\", \"title\": \"Question Answering with Langchain, AnalyticDB and OpenAI\", \"tokens\": 3679, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"efcae00efce3e045032e29a5591c2c602daf65171594bab7fe57e34d35c18b89\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"807b59e9-d516-4824-9b73-535c76c5d263\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"bf4975ede6e495c31704beb202fac9e8b0f102496b5ad3f3340fa0bfc87ea09f\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 9380, \"end_char_idx\": 11953, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "c32cd4ac-3abc-4016-be01-7ba09b19ee2c", "doc_id": "c32cd4ac-3abc-4016-be01-7ba09b19ee2c", "ref_doc_id": "c32cd4ac-3abc-4016-be01-7ba09b19ee2c", "chroma:document": "The Scavengers abandon Rick , after which he returns to Alexandria . Ezekiel ensures that the Kingdom residents are able to escape before locking himself in the community with the Saviors . Eugene aids Gabriel and Doctor Carson in escaping the Sanctuary in order to ease his conscience . Negan attacks Alexandria , but Carl devises a plan to allow the Alexandria residents to escape into the sewers . Carl reveals he was bitten by a walker while escorting Siddiq to Alexandria . 108 9 `` Honor '' Greg Nicotero Matthew Negrete & Channing Powell February 25 , 2018 ( 2018 - 02 - 25 ) 8.28 After the Saviors leave Alexandria , the survivors make for the Hilltop while Rick and Michonne stay behind to say their final goodbyes to a dying Carl , who pleads with Rick to build a better future alongside the Saviors before killing himself . In the Kingdom , Morgan and Carol launch a rescue mission for Ezekiel . Although they are successful and retake the Kingdom , the Saviors ' lieutenant Gavin is killed by Benjamin 's vengeful brother Henry . 109 10 `` The Lost and the Plunderers '' TBA TBA March 4 , 2018 ( 2018 - 03 - 04 ) TBD 110 11 `` Dead or Alive Or '' TBA TBA March 11 , 2018 ( 2018 - 03 - 11 ) TBD 111 12 `` The Key '' TBA TBA March 18 , 2018 ( 2018 - 03 - 18 ) TBD\n\n\n## Chain definition\n\nLangchain is already integrated with AnalyticDB and performs all the indexing for given list of documents. In our case we are going to store the set of answers we have.\n\n\n```python\nfrom langchain.vectorstores import AnalyticDB\nfrom langchain.embeddings import OpenAIEmbeddings\nfrom langchain import VectorDBQA, OpenAI\n\nembeddings = OpenAIEmbeddings()\ndoc_store = AnalyticDB.from_texts(\n    texts=answers, embedding=embeddings, connection_string=CONNECTION_STRING,\n    pre_delete_collection=True,\n)\n```\n\nAt this stage all the possible answers are already stored in  AnalyticDB, so we can define the whole QA chain.\n\n\n```python\nfrom langchain.chains import RetrievalQA\n\nllm = OpenAI()\nqa = VectorDBQA.from_chain_type(\n    llm=llm,\n    chain_type=\"stuff\",\n    vectorstore=doc_store,\n    return_source_documents=False,\n)\n```\n\n## Search data\n\nOnce the data is put into AnalyticDB we can start asking some questions. A question will be automatically vectorized by OpenAI model, and the created vector will be used to find some possibly matching answers in AnalyticDB. Once retrieved, the most similar answers will be incorporated into the prompt sent to OpenAI Large Language Model.\n\n\n\n```python\nimport random\n\nrandom.seed(52)\nselected_questions = random.choices(questions, k=5)\n```"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 807b59e9-d516-4824-9b73-535c76c5d263
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/QA_with_Langchain_AnalyticDB_and_OpenAI.ipynb", "title": "Question Answering with Langchain, AnalyticDB and OpenAI", "tokens": 3679, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"807b59e9-d516-4824-9b73-535c76c5d263\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/QA_with_Langchain_AnalyticDB_and_OpenAI.ipynb\", \"title\": \"Question Answering with Langchain, AnalyticDB and OpenAI\", \"tokens\": 3679, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"c32cd4ac-3abc-4016-be01-7ba09b19ee2c\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/QA_with_Langchain_AnalyticDB_and_OpenAI.ipynb\", \"title\": \"Question Answering with Langchain, AnalyticDB and OpenAI\", \"tokens\": 3679, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"8199fc7bc08996c70008990b9b86977ab403c583667423b770ca2dd6a2906b8f\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"d16c0b57-2821-45a3-bb6f-b6669e23db28\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/QA_with_Langchain_AnalyticDB_and_OpenAI.ipynb\", \"title\": \"Question Answering with Langchain, AnalyticDB and OpenAI\", \"tokens\": 3679, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"20434d0ed3c2f2f3280784ab505598875d9b5fe91e0eb248430d95a196842aa7\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"c140b350-d851-4260-9dbe-f77f0d4f1679\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"aad65fce997a6de8e7b106fe59e4a38d8f6ef9d2503faa1363469b2d4cbe69fa\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 10422, \"end_char_idx\": 13073, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "c32cd4ac-3abc-4016-be01-7ba09b19ee2c", "doc_id": "c32cd4ac-3abc-4016-be01-7ba09b19ee2c", "ref_doc_id": "c32cd4ac-3abc-4016-be01-7ba09b19ee2c", "chroma:document": "109 10 `` The Lost and the Plunderers '' TBA TBA March 4 , 2018 ( 2018 - 03 - 04 ) TBD 110 11 `` Dead or Alive Or '' TBA TBA March 11 , 2018 ( 2018 - 03 - 11 ) TBD 111 12 `` The Key '' TBA TBA March 18 , 2018 ( 2018 - 03 - 18 ) TBD\n\n\n## Chain definition\n\nLangchain is already integrated with AnalyticDB and performs all the indexing for given list of documents. In our case we are going to store the set of answers we have.\n\n\n```python\nfrom langchain.vectorstores import AnalyticDB\nfrom langchain.embeddings import OpenAIEmbeddings\nfrom langchain import VectorDBQA, OpenAI\n\nembeddings = OpenAIEmbeddings()\ndoc_store = AnalyticDB.from_texts(\n    texts=answers, embedding=embeddings, connection_string=CONNECTION_STRING,\n    pre_delete_collection=True,\n)\n```\n\nAt this stage all the possible answers are already stored in  AnalyticDB, so we can define the whole QA chain.\n\n\n```python\nfrom langchain.chains import RetrievalQA\n\nllm = OpenAI()\nqa = VectorDBQA.from_chain_type(\n    llm=llm,\n    chain_type=\"stuff\",\n    vectorstore=doc_store,\n    return_source_documents=False,\n)\n```\n\n## Search data\n\nOnce the data is put into AnalyticDB we can start asking some questions. A question will be automatically vectorized by OpenAI model, and the created vector will be used to find some possibly matching answers in AnalyticDB. Once retrieved, the most similar answers will be incorporated into the prompt sent to OpenAI Large Language Model.\n\n\n\n```python\nimport random\n\nrandom.seed(52)\nselected_questions = random.choices(questions, k=5)\n```\n\n\n```python\nfor question in selected_questions:\n    print(\">\", question)\n    print(qa.run(question), end=\"\\n\\n\")\n```\n\n    > where do frankenstein and the monster first meet\n     Victor retreats into the mountains, and that is where the Creature finds him and pleads for Victor to hear his tale.\n    \n    > who are the actors in fast and furious\n     The main cast of Fast & Furious includes Vin Diesel as Dominic Toretto, Paul Walker as Brian O'Conner, Michelle Rodriguez as Letty Ortiz, Jordana Brewster as Mia Toretto, Tyrese Gibson as Roman Pearce, and Ludacris as Tej Parker.\n    \n    > properties of red black tree in data structure\n     The properties of a red-black tree in data structure are that each node is either red or black, the root is black, all leaves (NIL) are black, and if a node is red, then both its children are black. Additionally, every path from a given node to any of its descendant NIL nodes contains the same number of black nodes.\n    \n    > who designed the national coat of arms of south africa\n     Iaan Bekker\n    \n    > caravaggio's death of the virgin pamela askew\n     I don't know."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: c140b350-d851-4260-9dbe-f77f0d4f1679
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/QA_with_Langchain_AnalyticDB_and_OpenAI.ipynb", "title": "Question Answering with Langchain, AnalyticDB and OpenAI", "tokens": 3679, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"c140b350-d851-4260-9dbe-f77f0d4f1679\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/QA_with_Langchain_AnalyticDB_and_OpenAI.ipynb\", \"title\": \"Question Answering with Langchain, AnalyticDB and OpenAI\", \"tokens\": 3679, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"c32cd4ac-3abc-4016-be01-7ba09b19ee2c\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/QA_with_Langchain_AnalyticDB_and_OpenAI.ipynb\", \"title\": \"Question Answering with Langchain, AnalyticDB and OpenAI\", \"tokens\": 3679, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"8199fc7bc08996c70008990b9b86977ab403c583667423b770ca2dd6a2906b8f\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"807b59e9-d516-4824-9b73-535c76c5d263\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/QA_with_Langchain_AnalyticDB_and_OpenAI.ipynb\", \"title\": \"Question Answering with Langchain, AnalyticDB and OpenAI\", \"tokens\": 3679, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"c1fa656a7a873459a73fdb14eafb48f2d2f286501aec293a9a19a80cfbb219c0\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"10fc5bff-5853-43ae-8572-3993f2ca688e\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"f767bc0fa77f0557356063d5c75229949db86aaa02dee23adda395d428f974d2\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 11857, \"end_char_idx\": 14690, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "c32cd4ac-3abc-4016-be01-7ba09b19ee2c", "doc_id": "c32cd4ac-3abc-4016-be01-7ba09b19ee2c", "ref_doc_id": "c32cd4ac-3abc-4016-be01-7ba09b19ee2c", "chroma:document": "```python\nimport random\n\nrandom.seed(52)\nselected_questions = random.choices(questions, k=5)\n```\n\n\n```python\nfor question in selected_questions:\n    print(\">\", question)\n    print(qa.run(question), end=\"\\n\\n\")\n```\n\n    > where do frankenstein and the monster first meet\n     Victor retreats into the mountains, and that is where the Creature finds him and pleads for Victor to hear his tale.\n    \n    > who are the actors in fast and furious\n     The main cast of Fast & Furious includes Vin Diesel as Dominic Toretto, Paul Walker as Brian O'Conner, Michelle Rodriguez as Letty Ortiz, Jordana Brewster as Mia Toretto, Tyrese Gibson as Roman Pearce, and Ludacris as Tej Parker.\n    \n    > properties of red black tree in data structure\n     The properties of a red-black tree in data structure are that each node is either red or black, the root is black, all leaves (NIL) are black, and if a node is red, then both its children are black. Additionally, every path from a given node to any of its descendant NIL nodes contains the same number of black nodes.\n    \n    > who designed the national coat of arms of south africa\n     Iaan Bekker\n    \n    > caravaggio's death of the virgin pamela askew\n     I don't know.\n    \n\n\n### Custom prompt templates\n\nThe `stuff` chain type in Langchain uses a specific prompt with question and context documents incorporated. This is what the default prompt looks like:\n\n```text\nUse the following pieces of context to answer the question at the end. If you don't know the answer, just say that you don't know, don't try to make up an answer.\n{context}\nQuestion: {question}\nHelpful Answer:\n```\n\nWe can, however, provide our prompt template and change the behaviour of the OpenAI LLM, while still using the `stuff` chain type. It is important to keep `{context}` and `{question}` as placeholders.\n\n#### Experimenting with custom prompts\n\nWe can try using a different prompt template, so the model:\n1. Responds with a single-sentence answer if it knows it.\n2. Suggests a random song title if it doesn't know the answer to our question.\n\n\n```python\nfrom langchain.prompts import PromptTemplate\ncustom_prompt = \"\"\"\nUse the following pieces of context to answer the question at the end. Please provide\na short single-sentence summary answer only. If you don't know the answer or if it's\nnot present in given context, don't try to make up an answer, but suggest me a random\nunrelated song title I could listen to.\nContext: {context}\nQuestion: {question}\nHelpful Answer:\n\"\"\"\n\ncustom_prompt_template = PromptTemplate(\n    template=custom_prompt, input_variables=[\"context\", \"question\"]\n)\n```\n\n\n```python\ncustom_qa = VectorDBQA.from_chain_type(\n    llm=llm,\n    chain_type=\"stuff\",\n    vectorstore=doc_store,\n    return_source_documents=False,\n    chain_type_kwargs={\"prompt\": custom_prompt_template},\n)\n```"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 10fc5bff-5853-43ae-8572-3993f2ca688e
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/QA_with_Langchain_AnalyticDB_and_OpenAI.ipynb", "title": "Question Answering with Langchain, AnalyticDB and OpenAI", "tokens": 3679, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"10fc5bff-5853-43ae-8572-3993f2ca688e\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/QA_with_Langchain_AnalyticDB_and_OpenAI.ipynb\", \"title\": \"Question Answering with Langchain, AnalyticDB and OpenAI\", \"tokens\": 3679, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"c32cd4ac-3abc-4016-be01-7ba09b19ee2c\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/QA_with_Langchain_AnalyticDB_and_OpenAI.ipynb\", \"title\": \"Question Answering with Langchain, AnalyticDB and OpenAI\", \"tokens\": 3679, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"8199fc7bc08996c70008990b9b86977ab403c583667423b770ca2dd6a2906b8f\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"c140b350-d851-4260-9dbe-f77f0d4f1679\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/analyticdb/QA_with_Langchain_AnalyticDB_and_OpenAI.ipynb\", \"title\": \"Question Answering with Langchain, AnalyticDB and OpenAI\", \"tokens\": 3679, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"459fcdae48138f0f3ef53869123152f3bdad65d7f499710fe8f54b7a4c3b9b57\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 13081, \"end_char_idx\": 15674, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "c32cd4ac-3abc-4016-be01-7ba09b19ee2c", "doc_id": "c32cd4ac-3abc-4016-be01-7ba09b19ee2c", "ref_doc_id": "c32cd4ac-3abc-4016-be01-7ba09b19ee2c", "chroma:document": "### Custom prompt templates\n\nThe `stuff` chain type in Langchain uses a specific prompt with question and context documents incorporated. This is what the default prompt looks like:\n\n```text\nUse the following pieces of context to answer the question at the end. If you don't know the answer, just say that you don't know, don't try to make up an answer.\n{context}\nQuestion: {question}\nHelpful Answer:\n```\n\nWe can, however, provide our prompt template and change the behaviour of the OpenAI LLM, while still using the `stuff` chain type. It is important to keep `{context}` and `{question}` as placeholders.\n\n#### Experimenting with custom prompts\n\nWe can try using a different prompt template, so the model:\n1. Responds with a single-sentence answer if it knows it.\n2. Suggests a random song title if it doesn't know the answer to our question.\n\n\n```python\nfrom langchain.prompts import PromptTemplate\ncustom_prompt = \"\"\"\nUse the following pieces of context to answer the question at the end. Please provide\na short single-sentence summary answer only. If you don't know the answer or if it's\nnot present in given context, don't try to make up an answer, but suggest me a random\nunrelated song title I could listen to.\nContext: {context}\nQuestion: {question}\nHelpful Answer:\n\"\"\"\n\ncustom_prompt_template = PromptTemplate(\n    template=custom_prompt, input_variables=[\"context\", \"question\"]\n)\n```\n\n\n```python\ncustom_qa = VectorDBQA.from_chain_type(\n    llm=llm,\n    chain_type=\"stuff\",\n    vectorstore=doc_store,\n    return_source_documents=False,\n    chain_type_kwargs={\"prompt\": custom_prompt_template},\n)\n```\n\n\n```python\nrandom.seed(41)\nfor question in random.choices(questions, k=5):\n    print(\">\", question)\n    print(custom_qa.run(question), end=\"\\n\\n\")\n```\n\n    > what was uncle jesse's original last name on full house\n    Uncle Jesse's original last name on Full House was Cochran.\n    \n    > when did the volcano erupt in indonesia 2018\n    No information about a volcano erupting in Indonesia in 2018 is present in the given context. Suggested song title: \"Volcano\" by U2.\n    \n    > what does a dualist way of thinking mean\n    A dualist way of thinking means believing that humans possess a non-physical mind or soul which is distinct from their physical body.\n    \n    > the first civil service commission in india was set up on the basis of recommendation of\n    The first Civil Service Commission in India was not set up on the basis of a recommendation.\n    \n    > how old do you have to be to get a tattoo in utah\n    In Utah, you must be at least 18 years old to get a tattoo."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 517606e4-9cb0-48ab-a642-4f35c0e2023d
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/SingleStoreDB/README.ipynb", "title": "**[SingleStoreDB](https://singlestore.com)** has first-class support for vector search through our [Vector Functions](https://docs.singlestore.com/managed-service/en/reference/sql-reference/vector-functions.html). Our vector database subsystem, first made available in 2017 and subsequently enhanced, allows extremely fast nearest-neighbor search to find objects that are semantically similar, easily using SQL.", "tokens": 321, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"517606e4-9cb0-48ab-a642-4f35c0e2023d\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/SingleStoreDB/README.ipynb\", \"title\": \"**[SingleStoreDB](https://singlestore.com)** has first-class support for vector search through our [Vector Functions](https://docs.singlestore.com/managed-service/en/reference/sql-reference/vector-functions.html). Our vector database subsystem, first made available in 2017 and subsequently enhanced, allows extremely fast nearest-neighbor search to find objects that are semantically similar, easily using SQL.\", \"tokens\": 321, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"e9c2a863-f156-40c7-8da7-835a543d34a5\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/SingleStoreDB/README.ipynb\", \"title\": \"**[SingleStoreDB](https://singlestore.com)** has first-class support for vector search through our [Vector Functions](https://docs.singlestore.com/managed-service/en/reference/sql-reference/vector-functions.html). Our vector database subsystem, first made available in 2017 and subsequently enhanced, allows extremely fast nearest-neighbor search to find objects that are semantically similar, easily using SQL.\", \"tokens\": 321, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"797b964b1055e3b5396f19fac04f11937dc10c24748dcfd77cfe2df5ae6af153\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 0, \"end_char_idx\": 1587, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "e9c2a863-f156-40c7-8da7-835a543d34a5", "doc_id": "e9c2a863-f156-40c7-8da7-835a543d34a5", "ref_doc_id": "e9c2a863-f156-40c7-8da7-835a543d34a5", "chroma:document": "**[SingleStoreDB](https://singlestore.com)** has first-class support for vector search through our [Vector Functions](https://docs.singlestore.com/managed-service/en/reference/sql-reference/vector-functions.html). Our vector database subsystem, first made available in 2017 and subsequently enhanced, allows extremely fast nearest-neighbor search to find objects that are semantically similar, easily using SQL.\n\nSingleStoreDB supports vectors and vector similarity search using dot_product (for cosine similarity) and euclidean_distance functions. These functions are used by our customers for applications including face recognition, visual product photo search and text-based semantic search. With the explosion of generative AI technology, these capabilities form a firm foundation for text-based AI chatbots.\n\nBut remember, SingleStoreDB is a high-performance, scalable, modern SQL DBMS that supports multiple data models including structured data, semi-structured data based on JSON, time-series, full text, spatial, key-value and of course vector data. Start powering your next intelligent application with SingleStoreDB today!\n\n![SingleStore Open AI](https://user-images.githubusercontent.com/8846480/236985121-48980956-fdc5-49c8-b006-f3a412142676.png)\n\n## Example\n\nThis folder contains examples of using SingleStoreDB and OpenAI together. We will keep adding more scenarios so stay tuned!\n\n| Name | Description |\n| --- | --- |\n| [OpenAI wikipedia semantic search](./OpenAI_wikipedia_semantic_search.ipynb) | Improve ChatGPT accuracy through SingleStoreDB semantic Search in QA |"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 3b64c9bd-fec2-4876-bfe1-b16f97ac5564
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/SingleStoreDB/OpenAI_wikipedia_semantic_search.ipynb", "title": "Intro", "tokens": 2377, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"3b64c9bd-fec2-4876-bfe1-b16f97ac5564\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/SingleStoreDB/OpenAI_wikipedia_semantic_search.ipynb\", \"title\": \"Intro\", \"tokens\": 2377, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"bb1edf13-e5e4-4f10-b763-c9f206ec7a4f\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/SingleStoreDB/OpenAI_wikipedia_semantic_search.ipynb\", \"title\": \"Intro\", \"tokens\": 2377, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"ae4000940ca04e2078675be698d67cc5a38847d7b8dd35179351ed26e8a14b20\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"c3577df9-6943-4489-9454-15fbf2a2d917\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"d5c8f8e718c12d68584c4473cf5f11c3ff3ca39839e8477c72ec58b1c2b6663c\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 0, \"end_char_idx\": 2157, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "bb1edf13-e5e4-4f10-b763-c9f206ec7a4f", "doc_id": "bb1edf13-e5e4-4f10-b763-c9f206ec7a4f", "ref_doc_id": "bb1edf13-e5e4-4f10-b763-c9f206ec7a4f", "chroma:document": "# Intro\nThis notebook is an example on how you can use SingleStoreDB vector storage and functions to build an interactive Q&A application with ChatGPT. If you start a [Trial](https://www.singlestore.com/cloud-trial/) in SingleStoreDB, you can find the same notebook in our sample notebooks with native connection.\n\n## First let's talk directly to ChatGPT and try and get back a response\n\n\n```python\n!pip install openai --quiet\n\n```\n\n    \n    \u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.0.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m23.1.2\u001b[0m\n    \u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpython3.11 -m pip install --upgrade pip\u001b[0m\n\n\n\n```python\nimport openai\n\nEMBEDDING_MODEL = \"text-embedding-3-small\"\nGPT_MODEL = \"gpt-3.5-turbo\"\n\n```\n\n## Let's connect to OpenAI and see the result we get when asking for a date beyond 2021\n\n\n```python\nopenai.api_key = 'OPENAI API KEY'\n\nresponse = openai.ChatCompletion.create(\n  model=GPT_MODEL,\n  messages=[\n        {\"role\": \"system\", \"content\": \"You are a helpful assistant.\"},\n        {\"role\": \"user\", \"content\": \"Who won the gold medal for curling in Olymics 2022?\"},\n    ]\n)\n\nprint(response['choices'][0]['message']['content'])\n\n```\n\n    I'm sorry, I cannot provide information about events that have not occurred yet. The Winter Olympics 2022 will be held in Beijing, China from February 4 to 20, 2022. The curling events will take place during this time and the results will not be known until after the competition has concluded.\n\n\n# Get the data about Winter Olympics and provide the information to ChatGPT as context\n\n## 1. Setup\n\n\n```python\n!pip install matplotlib plotly.express scikit-learn tabulate tiktoken wget --quiet\n\n```\n\n    \n    \u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.0.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m23.1.2\u001b[0m\n    \u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpython3.11 -m pip install --upgrade pip\u001b[0m\n\n\n\n```python\nimport pandas as pd\nimport os\nimport wget\nimport ast\n\n```\n\n## Step 1 - Grab the data from CSV and prepare it"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: c3577df9-6943-4489-9454-15fbf2a2d917
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/SingleStoreDB/OpenAI_wikipedia_semantic_search.ipynb", "title": "Intro", "tokens": 2377, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"c3577df9-6943-4489-9454-15fbf2a2d917\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/SingleStoreDB/OpenAI_wikipedia_semantic_search.ipynb\", \"title\": \"Intro\", \"tokens\": 2377, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"bb1edf13-e5e4-4f10-b763-c9f206ec7a4f\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/SingleStoreDB/OpenAI_wikipedia_semantic_search.ipynb\", \"title\": \"Intro\", \"tokens\": 2377, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"ae4000940ca04e2078675be698d67cc5a38847d7b8dd35179351ed26e8a14b20\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"3b64c9bd-fec2-4876-bfe1-b16f97ac5564\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/SingleStoreDB/OpenAI_wikipedia_semantic_search.ipynb\", \"title\": \"Intro\", \"tokens\": 2377, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"64fba8facf7a831b2e965f02c206e39054f52f6264f8545441689a85066896c4\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"16075a46-a9c4-4d14-b067-73de56a084e5\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"6868e16bae47ee695ce04c5f615a6c3deca324327212a018020fe4a5b5d0be68\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 907, \"end_char_idx\": 3527, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "bb1edf13-e5e4-4f10-b763-c9f206ec7a4f", "doc_id": "bb1edf13-e5e4-4f10-b763-c9f206ec7a4f", "ref_doc_id": "bb1edf13-e5e4-4f10-b763-c9f206ec7a4f", "chroma:document": "```python\nopenai.api_key = 'OPENAI API KEY'\n\nresponse = openai.ChatCompletion.create(\n  model=GPT_MODEL,\n  messages=[\n        {\"role\": \"system\", \"content\": \"You are a helpful assistant.\"},\n        {\"role\": \"user\", \"content\": \"Who won the gold medal for curling in Olymics 2022?\"},\n    ]\n)\n\nprint(response['choices'][0]['message']['content'])\n\n```\n\n    I'm sorry, I cannot provide information about events that have not occurred yet. The Winter Olympics 2022 will be held in Beijing, China from February 4 to 20, 2022. The curling events will take place during this time and the results will not be known until after the competition has concluded.\n\n\n# Get the data about Winter Olympics and provide the information to ChatGPT as context\n\n## 1. Setup\n\n\n```python\n!pip install matplotlib plotly.express scikit-learn tabulate tiktoken wget --quiet\n\n```\n\n    \n    \u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.0.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m23.1.2\u001b[0m\n    \u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpython3.11 -m pip install --upgrade pip\u001b[0m\n\n\n\n```python\nimport pandas as pd\nimport os\nimport wget\nimport ast\n\n```\n\n## Step 1 - Grab the data from CSV and prepare it\n\n\n```python\n# download pre-chunked text and pre-computed embeddings\n# this file is ~200 MB, so may take a minute depending on your connection speed\nembeddings_path = \"https://cdn.openai.com/API/examples/data/winter_olympics_2022.csv\"\nfile_path = \"winter_olympics_2022.csv\"\n\nif not os.path.exists(file_path):\n    wget.download(embeddings_path, file_path)\n    print(\"File downloaded successfully.\")\nelse:\n    print(\"File already exists in the local file system.\")\n\n```\n\n    File downloaded successfully.\n\n\n\n```python\ndf = pd.read_csv(\n    \"winter_olympics_2022.csv\"\n)\n\n# convert embeddings from CSV str type back to list type\ndf['embedding'] = df['embedding'].apply(ast.literal_eval)\n\n```\n\n\n```python\ndf\n\n```\n\n\n```python\ndf.info(show_counts=True)\n\n```\n\n    <class 'pandas.core.frame.DataFrame'>\n    RangeIndex: 6059 entries, 0 to 6058\n    Data columns (total 2 columns):\n     #   Column     Non-Null Count  Dtype \n    ---  ------     --------------  ----- \n     0   text       6059 non-null   object\n     1   embedding  6059 non-null   object\n    dtypes: object(2)\n    memory usage: 94.8+ KB\n\n\n## 2. Set up SingleStore DB\n\n\n```python\nimport singlestoredb as s2\n\nconn = s2.connect(\"<user>:<Password>@<host>:3306/\")\n\ncur = conn.cursor()\n\n```\n\n\n```python\n# Create database\nstmt = \"\"\"\n    CREATE DATABASE IF NOT EXISTS winter_wikipedia2;\n\"\"\"\n\ncur.execute(stmt)\n\n```\n\n\n\n\n    1"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 16075a46-a9c4-4d14-b067-73de56a084e5
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/SingleStoreDB/OpenAI_wikipedia_semantic_search.ipynb", "title": "Intro", "tokens": 2377, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"16075a46-a9c4-4d14-b067-73de56a084e5\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/SingleStoreDB/OpenAI_wikipedia_semantic_search.ipynb\", \"title\": \"Intro\", \"tokens\": 2377, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"bb1edf13-e5e4-4f10-b763-c9f206ec7a4f\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/SingleStoreDB/OpenAI_wikipedia_semantic_search.ipynb\", \"title\": \"Intro\", \"tokens\": 2377, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"ae4000940ca04e2078675be698d67cc5a38847d7b8dd35179351ed26e8a14b20\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"c3577df9-6943-4489-9454-15fbf2a2d917\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/SingleStoreDB/OpenAI_wikipedia_semantic_search.ipynb\", \"title\": \"Intro\", \"tokens\": 2377, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"e290877e2242889184ad99e4c552b9ba7a116a1a527128f6b9cab1ecff58e80e\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"8d247dcc-454c-4d74-8f7a-2f7a44d9cf6e\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"a57a92669caa4650b0c77d82e9aff33c26a3b1a9c4fb0d5218a93768d82e006d\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 2160, \"end_char_idx\": 4670, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "bb1edf13-e5e4-4f10-b763-c9f206ec7a4f", "doc_id": "bb1edf13-e5e4-4f10-b763-c9f206ec7a4f", "ref_doc_id": "bb1edf13-e5e4-4f10-b763-c9f206ec7a4f", "chroma:document": "```python\n# download pre-chunked text and pre-computed embeddings\n# this file is ~200 MB, so may take a minute depending on your connection speed\nembeddings_path = \"https://cdn.openai.com/API/examples/data/winter_olympics_2022.csv\"\nfile_path = \"winter_olympics_2022.csv\"\n\nif not os.path.exists(file_path):\n    wget.download(embeddings_path, file_path)\n    print(\"File downloaded successfully.\")\nelse:\n    print(\"File already exists in the local file system.\")\n\n```\n\n    File downloaded successfully.\n\n\n\n```python\ndf = pd.read_csv(\n    \"winter_olympics_2022.csv\"\n)\n\n# convert embeddings from CSV str type back to list type\ndf['embedding'] = df['embedding'].apply(ast.literal_eval)\n\n```\n\n\n```python\ndf\n\n```\n\n\n```python\ndf.info(show_counts=True)\n\n```\n\n    <class 'pandas.core.frame.DataFrame'>\n    RangeIndex: 6059 entries, 0 to 6058\n    Data columns (total 2 columns):\n     #   Column     Non-Null Count  Dtype \n    ---  ------     --------------  ----- \n     0   text       6059 non-null   object\n     1   embedding  6059 non-null   object\n    dtypes: object(2)\n    memory usage: 94.8+ KB\n\n\n## 2. Set up SingleStore DB\n\n\n```python\nimport singlestoredb as s2\n\nconn = s2.connect(\"<user>:<Password>@<host>:3306/\")\n\ncur = conn.cursor()\n\n```\n\n\n```python\n# Create database\nstmt = \"\"\"\n    CREATE DATABASE IF NOT EXISTS winter_wikipedia2;\n\"\"\"\n\ncur.execute(stmt)\n\n```\n\n\n\n\n    1\n\n\n\n\n```python\n#create table\nstmt = \"\"\"\nCREATE TABLE IF NOT EXISTS winter_wikipedia2.winter_olympics_2022 (\n    id INT PRIMARY KEY,\n    text TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci,\n    embedding BLOB\n);\"\"\"\n\ncur.execute(stmt)\n\n```\n\n\n\n\n    0\n\n\n\n## 3. Populate the Table with our dataframe df and use JSON_ARRAY_PACK to compact it\n\n\n```python\n%%time\n\n# Prepare the statement\nstmt = \"\"\"\n    INSERT INTO winter_wikipedia2.winter_olympics_2022 (\n        id,\n        text,\n        embedding\n    )\n    VALUES (\n        %s,\n        %s,\n        JSON_ARRAY_PACK_F64(%s)\n    )\n\"\"\"\n\n# Convert the DataFrame to a NumPy record array\nrecord_arr = df.to_records(index=True)\n\n# Set the batch size\nbatch_size = 1000\n\n# Iterate over the rows of the record array in batches\nfor i in range(0, len(record_arr), batch_size):\n    batch = record_arr[i:i+batch_size]\n    values = [(row[0], row[1], str(row[2])) for row in batch]\n    cur.executemany(stmt, values)\n\n```\n\n    CPU times: user 8.79 s, sys: 4.63 s, total: 13.4 s\n    Wall time: 11min 4s\n\n\n## 4. Do a semantic search with the same question from above and use the response to send to OpenAI again"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 8d247dcc-454c-4d74-8f7a-2f7a44d9cf6e
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/SingleStoreDB/OpenAI_wikipedia_semantic_search.ipynb", "title": "Intro", "tokens": 2377, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"8d247dcc-454c-4d74-8f7a-2f7a44d9cf6e\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/SingleStoreDB/OpenAI_wikipedia_semantic_search.ipynb\", \"title\": \"Intro\", \"tokens\": 2377, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"bb1edf13-e5e4-4f10-b763-c9f206ec7a4f\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/SingleStoreDB/OpenAI_wikipedia_semantic_search.ipynb\", \"title\": \"Intro\", \"tokens\": 2377, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"ae4000940ca04e2078675be698d67cc5a38847d7b8dd35179351ed26e8a14b20\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"16075a46-a9c4-4d14-b067-73de56a084e5\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/SingleStoreDB/OpenAI_wikipedia_semantic_search.ipynb\", \"title\": \"Intro\", \"tokens\": 2377, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"6c4bd841899b4aeec9122714edccf8bb999d63584c1ec7bcb67b153dd59b37da\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"729d0eba-3702-4969-b2be-5c2e503d425c\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"ff28753621ec3841c246af62822f6e3ba40131e52fe48f564d0a96ec8163e6b1\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 3250, \"end_char_idx\": 6124, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "bb1edf13-e5e4-4f10-b763-c9f206ec7a4f", "doc_id": "bb1edf13-e5e4-4f10-b763-c9f206ec7a4f", "ref_doc_id": "bb1edf13-e5e4-4f10-b763-c9f206ec7a4f", "chroma:document": "## 2. Set up SingleStore DB\n\n\n```python\nimport singlestoredb as s2\n\nconn = s2.connect(\"<user>:<Password>@<host>:3306/\")\n\ncur = conn.cursor()\n\n```\n\n\n```python\n# Create database\nstmt = \"\"\"\n    CREATE DATABASE IF NOT EXISTS winter_wikipedia2;\n\"\"\"\n\ncur.execute(stmt)\n\n```\n\n\n\n\n    1\n\n\n\n\n```python\n#create table\nstmt = \"\"\"\nCREATE TABLE IF NOT EXISTS winter_wikipedia2.winter_olympics_2022 (\n    id INT PRIMARY KEY,\n    text TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci,\n    embedding BLOB\n);\"\"\"\n\ncur.execute(stmt)\n\n```\n\n\n\n\n    0\n\n\n\n## 3. Populate the Table with our dataframe df and use JSON_ARRAY_PACK to compact it\n\n\n```python\n%%time\n\n# Prepare the statement\nstmt = \"\"\"\n    INSERT INTO winter_wikipedia2.winter_olympics_2022 (\n        id,\n        text,\n        embedding\n    )\n    VALUES (\n        %s,\n        %s,\n        JSON_ARRAY_PACK_F64(%s)\n    )\n\"\"\"\n\n# Convert the DataFrame to a NumPy record array\nrecord_arr = df.to_records(index=True)\n\n# Set the batch size\nbatch_size = 1000\n\n# Iterate over the rows of the record array in batches\nfor i in range(0, len(record_arr), batch_size):\n    batch = record_arr[i:i+batch_size]\n    values = [(row[0], row[1], str(row[2])) for row in batch]\n    cur.executemany(stmt, values)\n\n```\n\n    CPU times: user 8.79 s, sys: 4.63 s, total: 13.4 s\n    Wall time: 11min 4s\n\n\n## 4. Do a semantic search with the same question from above and use the response to send to OpenAI again\n\n\n\n```python\nfrom utils.embeddings_utils import get_embedding\n\ndef strings_ranked_by_relatedness(\n    query: str,\n    df: pd.DataFrame,\n    relatedness_fn=lambda x, y: 1 - spatial.distance.cosine(x, y),\n    top_n: int = 100\n) -> tuple:\n    \"\"\"Returns a list of strings and relatednesses, sorted from most related to least.\"\"\"\n\n    # Get the embedding of the query.\n    query_embedding_response = get_embedding(query, EMBEDDING_MODEL)\n\n    # Create the SQL statement.\n    stmt = \"\"\"\n        SELECT\n            text,\n            DOT_PRODUCT_F64(JSON_ARRAY_PACK_F64(%s), embedding) AS score\n        FROM winter_wikipedia2.winter_olympics_2022\n        ORDER BY score DESC\n        LIMIT %s\n    \"\"\"\n\n    # Execute the SQL statement.\n    results = cur.execute(stmt, [str(query_embedding_response), top_n])\n\n    # Fetch the results\n    results = cur.fetchall()\n\n    strings = []\n    relatednesses = []\n\n    for row in results:\n        strings.append(row[0])\n        relatednesses.append(row[1])\n\n    # Return the results.\n    return strings[:top_n], relatednesses[:top_n]\n\n```\n\n\n```python\nfrom tabulate import tabulate\n\nstrings, relatednesses = strings_ranked_by_relatedness(\n    \"curling gold medal\",\n    df,\n    top_n=5\n)\n\nfor string, relatedness in zip(strings, relatednesses):\n    print(f\"{relatedness=:.3f}\")\n    print(tabulate([[string]], headers=['Result'], tablefmt='fancy_grid'))\n\n```\n\n## 5. Send the right context to ChatGPT for a more accurate answer"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 729d0eba-3702-4969-b2be-5c2e503d425c
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/SingleStoreDB/OpenAI_wikipedia_semantic_search.ipynb", "title": "Intro", "tokens": 2377, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"729d0eba-3702-4969-b2be-5c2e503d425c\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/SingleStoreDB/OpenAI_wikipedia_semantic_search.ipynb\", \"title\": \"Intro\", \"tokens\": 2377, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"bb1edf13-e5e4-4f10-b763-c9f206ec7a4f\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/SingleStoreDB/OpenAI_wikipedia_semantic_search.ipynb\", \"title\": \"Intro\", \"tokens\": 2377, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"ae4000940ca04e2078675be698d67cc5a38847d7b8dd35179351ed26e8a14b20\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"8d247dcc-454c-4d74-8f7a-2f7a44d9cf6e\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/SingleStoreDB/OpenAI_wikipedia_semantic_search.ipynb\", \"title\": \"Intro\", \"tokens\": 2377, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"ab297e24f4188d35a8ad6ddd95579808d80f5041599dea68d1dd0dfd97719f3f\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"5c65a4ea-61bc-4725-89bd-7f7080fc7cca\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"bed5d2b8ddc037a43392043dd3772f3118e411cc29019b0382c226efe677b2ce\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 4565, \"end_char_idx\": 7222, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "bb1edf13-e5e4-4f10-b763-c9f206ec7a4f", "doc_id": "bb1edf13-e5e4-4f10-b763-c9f206ec7a4f", "ref_doc_id": "bb1edf13-e5e4-4f10-b763-c9f206ec7a4f", "chroma:document": "## 4. Do a semantic search with the same question from above and use the response to send to OpenAI again\n\n\n\n```python\nfrom utils.embeddings_utils import get_embedding\n\ndef strings_ranked_by_relatedness(\n    query: str,\n    df: pd.DataFrame,\n    relatedness_fn=lambda x, y: 1 - spatial.distance.cosine(x, y),\n    top_n: int = 100\n) -> tuple:\n    \"\"\"Returns a list of strings and relatednesses, sorted from most related to least.\"\"\"\n\n    # Get the embedding of the query.\n    query_embedding_response = get_embedding(query, EMBEDDING_MODEL)\n\n    # Create the SQL statement.\n    stmt = \"\"\"\n        SELECT\n            text,\n            DOT_PRODUCT_F64(JSON_ARRAY_PACK_F64(%s), embedding) AS score\n        FROM winter_wikipedia2.winter_olympics_2022\n        ORDER BY score DESC\n        LIMIT %s\n    \"\"\"\n\n    # Execute the SQL statement.\n    results = cur.execute(stmt, [str(query_embedding_response), top_n])\n\n    # Fetch the results\n    results = cur.fetchall()\n\n    strings = []\n    relatednesses = []\n\n    for row in results:\n        strings.append(row[0])\n        relatednesses.append(row[1])\n\n    # Return the results.\n    return strings[:top_n], relatednesses[:top_n]\n\n```\n\n\n```python\nfrom tabulate import tabulate\n\nstrings, relatednesses = strings_ranked_by_relatedness(\n    \"curling gold medal\",\n    df,\n    top_n=5\n)\n\nfor string, relatedness in zip(strings, relatednesses):\n    print(f\"{relatedness=:.3f}\")\n    print(tabulate([[string]], headers=['Result'], tablefmt='fancy_grid'))\n\n```\n\n## 5. Send the right context to ChatGPT for a more accurate answer\n\n\n```python\nimport tiktoken\n\ndef num_tokens(text: str, model: str = GPT_MODEL) -> int:\n    \"\"\"Return the number of tokens in a string.\"\"\"\n    encoding = tiktoken.encoding_for_model(model)\n    return len(encoding.encode(text))\n\n\ndef query_message(\n    query: str,\n    df: pd.DataFrame,\n    model: str,\n    token_budget: int\n) -> str:\n    \"\"\"Return a message for GPT, with relevant source texts pulled from SingleStoreDB.\"\"\"\n    strings, relatednesses = strings_ranked_by_relatedness(query, df, \"winter_olympics_2022\")\n    introduction = 'Use the below articles on the 2022 Winter Olympics to answer the subsequent question. If the answer cannot be found in the articles, write \"I could not find an answer.\"'\n    question = f\"\\n\\nQuestion: {query}\"\n    message = introduction\n    for string in strings:\n        next_article = f'\\n\\nWikipedia article section:\\n\"\"\"\\n{string}\\n\"\"\"'\n        if (\n            num_tokens(message + next_article + question, model=model)\n            > token_budget\n        ):\n            break\n        else:\n            message += next_article\n    return message + question"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 5c65a4ea-61bc-4725-89bd-7f7080fc7cca
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/SingleStoreDB/OpenAI_wikipedia_semantic_search.ipynb", "title": "Intro", "tokens": 2377, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"5c65a4ea-61bc-4725-89bd-7f7080fc7cca\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/SingleStoreDB/OpenAI_wikipedia_semantic_search.ipynb\", \"title\": \"Intro\", \"tokens\": 2377, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"bb1edf13-e5e4-4f10-b763-c9f206ec7a4f\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/SingleStoreDB/OpenAI_wikipedia_semantic_search.ipynb\", \"title\": \"Intro\", \"tokens\": 2377, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"ae4000940ca04e2078675be698d67cc5a38847d7b8dd35179351ed26e8a14b20\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"729d0eba-3702-4969-b2be-5c2e503d425c\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/SingleStoreDB/OpenAI_wikipedia_semantic_search.ipynb\", \"title\": \"Intro\", \"tokens\": 2377, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"b688a4c1beeddef8f81120afdf0f7c5f033c354019c64bffad0a1014a6c71b95\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 5742, \"end_char_idx\": 8615, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "bb1edf13-e5e4-4f10-b763-c9f206ec7a4f", "doc_id": "bb1edf13-e5e4-4f10-b763-c9f206ec7a4f", "ref_doc_id": "bb1edf13-e5e4-4f10-b763-c9f206ec7a4f", "chroma:document": "```python\nfrom tabulate import tabulate\n\nstrings, relatednesses = strings_ranked_by_relatedness(\n    \"curling gold medal\",\n    df,\n    top_n=5\n)\n\nfor string, relatedness in zip(strings, relatednesses):\n    print(f\"{relatedness=:.3f}\")\n    print(tabulate([[string]], headers=['Result'], tablefmt='fancy_grid'))\n\n```\n\n## 5. Send the right context to ChatGPT for a more accurate answer\n\n\n```python\nimport tiktoken\n\ndef num_tokens(text: str, model: str = GPT_MODEL) -> int:\n    \"\"\"Return the number of tokens in a string.\"\"\"\n    encoding = tiktoken.encoding_for_model(model)\n    return len(encoding.encode(text))\n\n\ndef query_message(\n    query: str,\n    df: pd.DataFrame,\n    model: str,\n    token_budget: int\n) -> str:\n    \"\"\"Return a message for GPT, with relevant source texts pulled from SingleStoreDB.\"\"\"\n    strings, relatednesses = strings_ranked_by_relatedness(query, df, \"winter_olympics_2022\")\n    introduction = 'Use the below articles on the 2022 Winter Olympics to answer the subsequent question. If the answer cannot be found in the articles, write \"I could not find an answer.\"'\n    question = f\"\\n\\nQuestion: {query}\"\n    message = introduction\n    for string in strings:\n        next_article = f'\\n\\nWikipedia article section:\\n\"\"\"\\n{string}\\n\"\"\"'\n        if (\n            num_tokens(message + next_article + question, model=model)\n            > token_budget\n        ):\n            break\n        else:\n            message += next_article\n    return message + question\n\n\ndef ask(\n    query: str,\n    df: pd.DataFrame = df,\n    model: str = GPT_MODEL,\n    token_budget: int = 4096 - 500,\n    print_message: bool = False,\n) -> str:\n    \"\"\"Answers a query using GPT and a table of relevant texts and embeddings in SingleStoreDB.\"\"\"\n    message = query_message(query, df, model=model, token_budget=token_budget)\n    if print_message:\n        print(message)\n    messages = [\n        {\"role\": \"system\", \"content\": \"You answer questions about the 2022 Winter Olympics.\"},\n        {\"role\": \"user\", \"content\": message},\n    ]\n    response = openai.ChatCompletion.create(\n        model=model,\n        messages=messages,\n        temperature=0\n    )\n    response_message = response[\"choices\"][0][\"message\"][\"content\"]\n    return response_message\n\n```\n\n## 6. Get an answer from Chat GPT\n\n\n```python\nfrom pprint import pprint\n\nanswer = ask('Who won the gold medal for curling in Olymics 2022?')\n\npprint(answer)\n\n```\n\n    (\"There were three curling events at the 2022 Winter Olympics: men's, women's, \"\n     'and mixed doubles. The gold medalists for each event are:\\n'\n     '\\n'\n     \"- Men's: Sweden (Niklas Edin, Oskar Eriksson, Rasmus Wran\u00e5, Christoffer \"\n     'Sundgren, Daniel Magnusson)\\n'\n     \"- Women's: Great Britain (Eve Muirhead, Vicky Wright, Jennifer Dodds, Hailey \"\n     'Duff, Mili Smith)\\n'\n     '- Mixed doubles: Italy (Stefania Constantini, Amos Mosaner)')"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: cb96f34c-5039-4b0a-8470-9bffe3accc99
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/azure/whisper.ipynb", "title": "Azure audio whisper (preview) example", "tokens": 982, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"cb96f34c-5039-4b0a-8470-9bffe3accc99\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/whisper.ipynb\", \"title\": \"Azure audio whisper (preview) example\", \"tokens\": 982, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"6c61e5c8-4dc7-48b7-929c-bcd625736ab4\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/whisper.ipynb\", \"title\": \"Azure audio whisper (preview) example\", \"tokens\": 982, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"8e4b8a90618bfb977e7d32aa91d1d8392f1789e25f3df872233dcb8c3f0889fd\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"ca0c8849-f881-4efe-8f5b-bf8aacb1260d\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"57bc55f44a6a25af369c7278bf71eb19b27eaa309b97169e4cb41e7e670ec786\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 0, \"end_char_idx\": 3342, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "6c61e5c8-4dc7-48b7-929c-bcd625736ab4", "doc_id": "6c61e5c8-4dc7-48b7-929c-bcd625736ab4", "ref_doc_id": "6c61e5c8-4dc7-48b7-929c-bcd625736ab4", "chroma:document": "# Azure audio whisper (preview) example\n\nThe example shows how to use the Azure OpenAI Whisper model to transcribe audio files.\n\n\n## Setup\n\nFirst, we install the necessary dependencies and import the libraries we will be using.\n\n\n```python\n! pip install \"openai>=1.0.0,<2.0.0\"\n! pip install python-dotenv\n```\n\n\n```python\nimport os\nimport openai\nimport dotenv\n\ndotenv.load_dotenv()\n```\n\n### Authentication\n\nThe Azure OpenAI service supports multiple authentication mechanisms that include API keys and Azure Active Directory token credentials.\n\n\n```python\nuse_azure_active_directory = False  # Set this flag to True if you are using Azure Active Directory\n```\n\n#### Authentication using API key\n\nTo set up the OpenAI SDK to use an *Azure API Key*, we need to set `api_key` to a key associated with your endpoint (you can find this key in *\"Keys and Endpoints\"* under *\"Resource Management\"* in the [Azure Portal](https://portal.azure.com)). You'll also find the endpoint for your resource here.\n\n\n```python\nif not use_azure_active_directory:\n    endpoint = os.environ[\"AZURE_OPENAI_ENDPOINT\"]\n    api_key = os.environ[\"AZURE_OPENAI_API_KEY\"]\n\n    client = openai.AzureOpenAI(\n        azure_endpoint=endpoint,\n        api_key=api_key,\n        api_version=\"2023-09-01-preview\"\n    )\n```\n\n#### Authentication using Azure Active Directory\nLet's now see how we can autheticate via Azure Active Directory. We'll start by installing the `azure-identity` library. This library will provide the token credentials we need to authenticate and help us build a token credential provider through the `get_bearer_token_provider` helper function. It's recommended to use `get_bearer_token_provider` over providing a static token to `AzureOpenAI` because this API will automatically cache and refresh tokens for you. \n\nFor more information on how to set up Azure Active Directory authentication with Azure OpenAI, see the [documentation](https://learn.microsoft.com/azure/ai-services/openai/how-to/managed-identity).\n\n\n```python\n! pip install \"azure-identity>=1.15.0\"\n```\n\n\n```python\nfrom azure.identity import DefaultAzureCredential, get_bearer_token_provider\n\nif use_azure_active_directory:\n    endpoint = os.environ[\"AZURE_OPENAI_ENDPOINT\"]\n    api_key = os.environ[\"AZURE_OPENAI_API_KEY\"]\n\n    client = openai.AzureOpenAI(\n        azure_endpoint=endpoint,\n        azure_ad_token_provider=get_bearer_token_provider(DefaultAzureCredential(), \"https://cognitiveservices.azure.com/.default\"),\n        api_version=\"2023-09-01-preview\"\n    )\n```\n\n> Note: the AzureOpenAI infers the following arguments from their corresponding environment variables if they are not provided:\n\n- `api_key` from `AZURE_OPENAI_API_KEY`\n- `azure_ad_token` from `AZURE_OPENAI_AD_TOKEN`\n- `api_version` from `OPENAI_API_VERSION`\n- `azure_endpoint` from `AZURE_OPENAI_ENDPOINT`\n\n\n## Deployments\n\nIn this section we are going to create a deployment using the `whisper-1` model to transcribe audio files.\n\n### Deployments: Create in the Azure OpenAI Studio\nLet's deploy a model to use with whisper. Go to https://portal.azure.com, find your Azure OpenAI resource, and then navigate to the Azure OpenAI Studio. Click on the \"Deployments\" tab and then create a deployment for the model you want to use for whisper. The deployment name that you give the model will be used in the code below."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: ca0c8849-f881-4efe-8f5b-bf8aacb1260d
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/azure/whisper.ipynb", "title": "Azure audio whisper (preview) example", "tokens": 982, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"ca0c8849-f881-4efe-8f5b-bf8aacb1260d\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/whisper.ipynb\", \"title\": \"Azure audio whisper (preview) example\", \"tokens\": 982, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"6c61e5c8-4dc7-48b7-929c-bcd625736ab4\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/whisper.ipynb\", \"title\": \"Azure audio whisper (preview) example\", \"tokens\": 982, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"8e4b8a90618bfb977e7d32aa91d1d8392f1789e25f3df872233dcb8c3f0889fd\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"cb96f34c-5039-4b0a-8470-9bffe3accc99\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/whisper.ipynb\", \"title\": \"Azure audio whisper (preview) example\", \"tokens\": 982, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"045d747a7f03b2f72c6355c0fadba4140a7c8ffb5594176153e3ea73b8cdc9ab\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 2001, \"end_char_idx\": 4311, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "6c61e5c8-4dc7-48b7-929c-bcd625736ab4", "doc_id": "6c61e5c8-4dc7-48b7-929c-bcd625736ab4", "ref_doc_id": "6c61e5c8-4dc7-48b7-929c-bcd625736ab4", "chroma:document": "```python\n! pip install \"azure-identity>=1.15.0\"\n```\n\n\n```python\nfrom azure.identity import DefaultAzureCredential, get_bearer_token_provider\n\nif use_azure_active_directory:\n    endpoint = os.environ[\"AZURE_OPENAI_ENDPOINT\"]\n    api_key = os.environ[\"AZURE_OPENAI_API_KEY\"]\n\n    client = openai.AzureOpenAI(\n        azure_endpoint=endpoint,\n        azure_ad_token_provider=get_bearer_token_provider(DefaultAzureCredential(), \"https://cognitiveservices.azure.com/.default\"),\n        api_version=\"2023-09-01-preview\"\n    )\n```\n\n> Note: the AzureOpenAI infers the following arguments from their corresponding environment variables if they are not provided:\n\n- `api_key` from `AZURE_OPENAI_API_KEY`\n- `azure_ad_token` from `AZURE_OPENAI_AD_TOKEN`\n- `api_version` from `OPENAI_API_VERSION`\n- `azure_endpoint` from `AZURE_OPENAI_ENDPOINT`\n\n\n## Deployments\n\nIn this section we are going to create a deployment using the `whisper-1` model to transcribe audio files.\n\n### Deployments: Create in the Azure OpenAI Studio\nLet's deploy a model to use with whisper. Go to https://portal.azure.com, find your Azure OpenAI resource, and then navigate to the Azure OpenAI Studio. Click on the \"Deployments\" tab and then create a deployment for the model you want to use for whisper. The deployment name that you give the model will be used in the code below.\n\n\n```python\ndeployment = \"whisper-deployment\" # Fill in the deployment name from the portal here\n```\n\n## Audio transcription\n\nAudio transcription, or speech-to-text, is the process of converting spoken words into text. Use the `openai.Audio.transcribe` method to transcribe an audio file stream to text.\n\nYou can get sample audio files from the [Azure AI Speech SDK repository at GitHub](https://github.com/Azure-Samples/cognitive-services-speech-sdk/tree/master/sampledata/audiofiles).\n\n\n```python\n# download sample audio file\nimport requests\n\nsample_audio_url = \"https://github.com/Azure-Samples/cognitive-services-speech-sdk/raw/master/sampledata/audiofiles/wikipediaOcelot.wav\"\naudio_file = requests.get(sample_audio_url)\nwith open(\"wikipediaOcelot.wav\", \"wb\") as f:\n    f.write(audio_file.content)\n```\n\n\n```python\ntranscription = client.audio.transcriptions.create(\n    file=open(\"wikipediaOcelot.wav\", \"rb\"),\n    model=deployment,\n)\nprint(transcription.text)\n```"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 53f401d6-5b5d-4c4b-94f9-4abd0bb92143
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/azure/chat.ipynb", "title": "Azure chat completions example", "tokens": 1590, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"53f401d6-5b5d-4c4b-94f9-4abd0bb92143\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/chat.ipynb\", \"title\": \"Azure chat completions example\", \"tokens\": 1590, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"efaf5675-75c7-4d63-8604-a16e46f38fa3\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/chat.ipynb\", \"title\": \"Azure chat completions example\", \"tokens\": 1590, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"086cf0d64bdf19aa254495b517b9c8b4694b72751a67ae2416b85edd8aba1b1d\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"a8899f2a-3cd0-49a0-b659-166265e1ab5c\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"9509a12086c57c95c51bd6dfd8acc8f2b51ac55339e8e69854136c2f7c8a1dc0\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 0, \"end_char_idx\": 3344, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "efaf5675-75c7-4d63-8604-a16e46f38fa3", "doc_id": "efaf5675-75c7-4d63-8604-a16e46f38fa3", "ref_doc_id": "efaf5675-75c7-4d63-8604-a16e46f38fa3", "chroma:document": "# Azure chat completions example\n\nThis example will cover chat completions using the Azure OpenAI service. It also includes information on content filtering.\n\n## Setup\n\nFirst, we install the necessary dependencies and import the libraries we will be using.\n\n\n```python\n! pip install \"openai>=1.0.0,<2.0.0\"\n! pip install python-dotenv\n```\n\n\n```python\nimport os\nimport openai\nimport dotenv\n\ndotenv.load_dotenv()\n```\n\n### Authentication\n\nThe Azure OpenAI service supports multiple authentication mechanisms that include API keys and Azure Active Directory token credentials.\n\n\n```python\nuse_azure_active_directory = False  # Set this flag to True if you are using Azure Active Directory\n```\n\n#### Authentication using API key\n\nTo set up the OpenAI SDK to use an *Azure API Key*, we need to set `api_key` to a key associated with your endpoint (you can find this key in *\"Keys and Endpoints\"* under *\"Resource Management\"* in the [Azure Portal](https://portal.azure.com)). You'll also find the endpoint for your resource here.\n\n\n```python\nif not use_azure_active_directory:\n    endpoint = os.environ[\"AZURE_OPENAI_ENDPOINT\"]\n    api_key = os.environ[\"AZURE_OPENAI_API_KEY\"]\n\n    client = openai.AzureOpenAI(\n        azure_endpoint=endpoint,\n        api_key=api_key,\n        api_version=\"2023-09-01-preview\"\n    )\n```\n\n#### Authentication using Azure Active Directory\nLet's now see how we can autheticate via Azure Active Directory. We'll start by installing the `azure-identity` library. This library will provide the token credentials we need to authenticate and help us build a token credential provider through the `get_bearer_token_provider` helper function. It's recommended to use `get_bearer_token_provider` over providing a static token to `AzureOpenAI` because this API will automatically cache and refresh tokens for you. \n\nFor more information on how to set up Azure Active Directory authentication with Azure OpenAI, see the [documentation](https://learn.microsoft.com/azure/ai-services/openai/how-to/managed-identity).\n\n\n```python\n! pip install \"azure-identity>=1.15.0\"\n```\n\n\n```python\nfrom azure.identity import DefaultAzureCredential, get_bearer_token_provider\n\nif use_azure_active_directory:\n    endpoint = os.environ[\"AZURE_OPENAI_ENDPOINT\"]\n\n    client = openai.AzureOpenAI(\n        azure_endpoint=endpoint,\n        azure_ad_token_provider=get_bearer_token_provider(DefaultAzureCredential(), \"https://cognitiveservices.azure.com/.default\"),\n        api_version=\"2023-09-01-preview\"\n    )\n```\n\n> Note: the AzureOpenAI infers the following arguments from their corresponding environment variables if they are not provided:\n\n- `api_key` from `AZURE_OPENAI_API_KEY`\n- `azure_ad_token` from `AZURE_OPENAI_AD_TOKEN`\n- `api_version` from `OPENAI_API_VERSION`\n- `azure_endpoint` from `AZURE_OPENAI_ENDPOINT`\n\n\n## Deployments\n\nIn this section we are going to create a deployment of a GPT model that we can use to create chat completions.\n\n### Deployments: Create in the Azure OpenAI Studio\nLet's deploy a model to use with chat completions. Go to https://portal.azure.com, find your Azure OpenAI resource, and then navigate to the Azure OpenAI Studio. Click on the \"Deployments\" tab and then create a deployment for the model you want to use for chat completions. The deployment name that you give the model will be used in the code below."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: a8899f2a-3cd0-49a0-b659-166265e1ab5c
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/azure/chat.ipynb", "title": "Azure chat completions example", "tokens": 1590, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"a8899f2a-3cd0-49a0-b659-166265e1ab5c\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/chat.ipynb\", \"title\": \"Azure chat completions example\", \"tokens\": 1590, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"efaf5675-75c7-4d63-8604-a16e46f38fa3\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/chat.ipynb\", \"title\": \"Azure chat completions example\", \"tokens\": 1590, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"086cf0d64bdf19aa254495b517b9c8b4694b72751a67ae2416b85edd8aba1b1d\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"53f401d6-5b5d-4c4b-94f9-4abd0bb92143\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/chat.ipynb\", \"title\": \"Azure chat completions example\", \"tokens\": 1590, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"b63a3d6c3ae0b56cd3b6afe5ff435c27c6e7542d89f4bff82d331d3833bdd8d3\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"729a5d5d-1bdf-46cd-98c4-9b8c09f666f4\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"540d3b88d334816fb891daa3d65776d1a0a5bc04a1a550a47a3392d845854c05\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 2030, \"end_char_idx\": 5375, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "efaf5675-75c7-4d63-8604-a16e46f38fa3", "doc_id": "efaf5675-75c7-4d63-8604-a16e46f38fa3", "ref_doc_id": "efaf5675-75c7-4d63-8604-a16e46f38fa3", "chroma:document": "```python\n! pip install \"azure-identity>=1.15.0\"\n```\n\n\n```python\nfrom azure.identity import DefaultAzureCredential, get_bearer_token_provider\n\nif use_azure_active_directory:\n    endpoint = os.environ[\"AZURE_OPENAI_ENDPOINT\"]\n\n    client = openai.AzureOpenAI(\n        azure_endpoint=endpoint,\n        azure_ad_token_provider=get_bearer_token_provider(DefaultAzureCredential(), \"https://cognitiveservices.azure.com/.default\"),\n        api_version=\"2023-09-01-preview\"\n    )\n```\n\n> Note: the AzureOpenAI infers the following arguments from their corresponding environment variables if they are not provided:\n\n- `api_key` from `AZURE_OPENAI_API_KEY`\n- `azure_ad_token` from `AZURE_OPENAI_AD_TOKEN`\n- `api_version` from `OPENAI_API_VERSION`\n- `azure_endpoint` from `AZURE_OPENAI_ENDPOINT`\n\n\n## Deployments\n\nIn this section we are going to create a deployment of a GPT model that we can use to create chat completions.\n\n### Deployments: Create in the Azure OpenAI Studio\nLet's deploy a model to use with chat completions. Go to https://portal.azure.com, find your Azure OpenAI resource, and then navigate to the Azure OpenAI Studio. Click on the \"Deployments\" tab and then create a deployment for the model you want to use for chat completions. The deployment name that you give the model will be used in the code below.\n\n\n```python\ndeployment = \"\" # Fill in the deployment name from the portal here\n```\n\n## Create chat completions\n\nNow let's create a chat completion using the client we built.\n\n\n```python\n# For all possible arguments see https://platform.openai.com/docs/api-reference/chat-completions/create\nresponse = client.chat.completions.create(\n    model=deployment,\n    messages=[\n        {\"role\": \"system\", \"content\": \"You are a helpful assistant.\"},\n        {\"role\": \"user\", \"content\": \"Knock knock.\"},\n        {\"role\": \"assistant\", \"content\": \"Who's there?\"},\n        {\"role\": \"user\", \"content\": \"Orange.\"},\n    ],\n    temperature=0,\n)\n\nprint(f\"{response.choices[0].message.role}: {response.choices[0].message.content}\")\n```\n\n### Create a streaming chat completion\n\nWe can also stream the response.\n\n\n```python\nresponse = client.chat.completions.create(\n    model=deployment,\n    messages=[\n        {\"role\": \"system\", \"content\": \"You are a helpful assistant.\"},\n        {\"role\": \"user\", \"content\": \"Knock knock.\"},\n        {\"role\": \"assistant\", \"content\": \"Who's there?\"},\n        {\"role\": \"user\", \"content\": \"Orange.\"},\n    ],\n    temperature=0,\n    stream=True\n)\n\nfor chunk in response:\n    if len(chunk.choices) > 0:\n        delta = chunk.choices[0].delta\n\n        if delta.role:\n            print(delta.role + \": \", end=\"\", flush=True)\n        if delta.content:\n            print(delta.content, end=\"\", flush=True)\n```\n\n### Content filtering\n\nAzure OpenAI service includes content filtering of prompts and completion responses. You can learn more about content filtering and how to configure it [here](https://learn.microsoft.com/azure/ai-services/openai/concepts/content-filter).\n\nIf the prompt is flagged by the content filter, the library will raise a `BadRequestError` exception with a `content_filter` error code. Otherwise, you can access the `prompt_filter_results` and `content_filter_results` on the response to see the results of the content filtering and what categories were flagged.\n\n#### Prompt flagged by content filter"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 729a5d5d-1bdf-46cd-98c4-9b8c09f666f4
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/azure/chat.ipynb", "title": "Azure chat completions example", "tokens": 1590, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"729a5d5d-1bdf-46cd-98c4-9b8c09f666f4\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/chat.ipynb\", \"title\": \"Azure chat completions example\", \"tokens\": 1590, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"efaf5675-75c7-4d63-8604-a16e46f38fa3\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/chat.ipynb\", \"title\": \"Azure chat completions example\", \"tokens\": 1590, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"086cf0d64bdf19aa254495b517b9c8b4694b72751a67ae2416b85edd8aba1b1d\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"a8899f2a-3cd0-49a0-b659-166265e1ab5c\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/chat.ipynb\", \"title\": \"Azure chat completions example\", \"tokens\": 1590, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"77a0f4e1b3e0955b2913cb563a789beeb19fd6652c4c85b23cdabb6fe31a4b95\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 4138, \"end_char_idx\": 7123, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "efaf5675-75c7-4d63-8604-a16e46f38fa3", "doc_id": "efaf5675-75c7-4d63-8604-a16e46f38fa3", "ref_doc_id": "efaf5675-75c7-4d63-8604-a16e46f38fa3", "chroma:document": "```python\nresponse = client.chat.completions.create(\n    model=deployment,\n    messages=[\n        {\"role\": \"system\", \"content\": \"You are a helpful assistant.\"},\n        {\"role\": \"user\", \"content\": \"Knock knock.\"},\n        {\"role\": \"assistant\", \"content\": \"Who's there?\"},\n        {\"role\": \"user\", \"content\": \"Orange.\"},\n    ],\n    temperature=0,\n    stream=True\n)\n\nfor chunk in response:\n    if len(chunk.choices) > 0:\n        delta = chunk.choices[0].delta\n\n        if delta.role:\n            print(delta.role + \": \", end=\"\", flush=True)\n        if delta.content:\n            print(delta.content, end=\"\", flush=True)\n```\n\n### Content filtering\n\nAzure OpenAI service includes content filtering of prompts and completion responses. You can learn more about content filtering and how to configure it [here](https://learn.microsoft.com/azure/ai-services/openai/concepts/content-filter).\n\nIf the prompt is flagged by the content filter, the library will raise a `BadRequestError` exception with a `content_filter` error code. Otherwise, you can access the `prompt_filter_results` and `content_filter_results` on the response to see the results of the content filtering and what categories were flagged.\n\n#### Prompt flagged by content filter\n\n\n```python\nimport json\n\nmessages = [\n    {\"role\": \"system\", \"content\": \"You are a helpful assistant.\"},\n    {\"role\": \"user\", \"content\": \"<text violating the content policy>\"}\n]\n\ntry:\n    completion = client.chat.completions.create(\n        messages=messages,\n        model=deployment,\n    )\nexcept openai.BadRequestError as e:\n    err = json.loads(e.response.text)\n    if err[\"error\"][\"code\"] == \"content_filter\":\n        print(\"Content filter triggered!\")\n        content_filter_result = err[\"error\"][\"innererror\"][\"content_filter_result\"]\n        for category, details in content_filter_result.items():\n            print(f\"{category}:\\n filtered={details['filtered']}\\n severity={details['severity']}\")\n```\n\n### Checking the result of the content filter\n\n\n```python\nmessages = [\n    {\"role\": \"system\", \"content\": \"You are a helpful assistant.\"},\n    {\"role\": \"user\", \"content\": \"What's the biggest city in Washington?\"}\n]\n\ncompletion = client.chat.completions.create(\n    messages=messages,\n    model=deployment,\n)\nprint(f\"Answer: {completion.choices[0].message.content}\")\n\n# prompt content filter result in \"model_extra\" for azure\nprompt_filter_result = completion.model_extra[\"prompt_filter_results\"][0][\"content_filter_results\"]\nprint(\"\\nPrompt content filter results:\")\nfor category, details in prompt_filter_result.items():\n    print(f\"{category}:\\n filtered={details['filtered']}\\n severity={details['severity']}\")\n\n# completion content filter result\nprint(\"\\nCompletion content filter results:\")\ncompletion_filter_result = completion.choices[0].model_extra[\"content_filter_results\"]\nfor category, details in completion_filter_result.items():\n    print(f\"{category}:\\n filtered={details['filtered']}\\n severity={details['severity']}\")\n```"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: b6a71ea3-8d6d-4815-a103-a29d503f9bae
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/azure/embeddings.ipynb", "title": "Azure embeddings example", "tokens": 816, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"b6a71ea3-8d6d-4815-a103-a29d503f9bae\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/embeddings.ipynb\", \"title\": \"Azure embeddings example\", \"tokens\": 816, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"ab2e8823-4f72-4cfb-b753-9dd465e1cbd9\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/embeddings.ipynb\", \"title\": \"Azure embeddings example\", \"tokens\": 816, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"7fe0a7c5a5a05e3f4dcf45a0cb7b6ca5891e8066acbdd6132b75ddb500394eea\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"44bbc22b-901c-41e2-9c43-6bf6c41fc727\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"fbd8f45a5a3061b55914161907a16ca286419e6595edc7dc7554805c507e8925\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 0, \"end_char_idx\": 3308, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "ab2e8823-4f72-4cfb-b753-9dd465e1cbd9", "doc_id": "ab2e8823-4f72-4cfb-b753-9dd465e1cbd9", "ref_doc_id": "ab2e8823-4f72-4cfb-b753-9dd465e1cbd9", "chroma:document": "# Azure embeddings example\n\nThis example will cover embeddings using the Azure OpenAI service.\n\n## Setup\n\nFirst, we install the necessary dependencies and import the libraries we will be using.\n\n\n```python\n! pip install \"openai>=1.0.0,<2.0.0\"\n! pip install python-dotenv\n```\n\n\n```python\nimport os\nimport openai\nimport dotenv\n\ndotenv.load_dotenv()\n```\n\n### Authentication\n\nThe Azure OpenAI service supports multiple authentication mechanisms that include API keys and Azure Active Directory token credentials.\n\n\n```python\nuse_azure_active_directory = False  # Set this flag to True if you are using Azure Active Directory\n```\n\n#### Authentication using API key\n\nTo set up the OpenAI SDK to use an *Azure API Key*, we need to set `api_key` to a key associated with your endpoint (you can find this key in *\"Keys and Endpoints\"* under *\"Resource Management\"* in the [Azure Portal](https://portal.azure.com)). You'll also find the endpoint for your resource here.\n\n\n```python\nif not use_azure_active_directory:\n    endpoint = os.environ[\"AZURE_OPENAI_ENDPOINT\"]\n    api_key = os.environ[\"AZURE_OPENAI_API_KEY\"]\n\n    client = openai.AzureOpenAI(\n        azure_endpoint=endpoint,\n        api_key=api_key,\n        api_version=\"2023-09-01-preview\"\n    )\n```\n\n#### Authentication using Azure Active Directory\nLet's now see how we can autheticate via Azure Active Directory. We'll start by installing the `azure-identity` library. This library will provide the token credentials we need to authenticate and help us build a token credential provider through the `get_bearer_token_provider` helper function. It's recommended to use `get_bearer_token_provider` over providing a static token to `AzureOpenAI` because this API will automatically cache and refresh tokens for you. \n\nFor more information on how to set up Azure Active Directory authentication with Azure OpenAI, see the [documentation](https://learn.microsoft.com/azure/ai-services/openai/how-to/managed-identity).\n\n\n```python\n! pip install \"azure-identity>=1.15.0\"\n```\n\n\n```python\nfrom azure.identity import DefaultAzureCredential, get_bearer_token_provider\n\nif use_azure_active_directory:\n    endpoint = os.environ[\"AZURE_OPENAI_ENDPOINT\"]\n    api_key = os.environ[\"AZURE_OPENAI_API_KEY\"]\n\n    client = openai.AzureOpenAI(\n        azure_endpoint=endpoint,\n        azure_ad_token_provider=get_bearer_token_provider(DefaultAzureCredential(), \"https://cognitiveservices.azure.com/.default\"),\n        api_version=\"2023-09-01-preview\"\n    )\n```\n\n> Note: the AzureOpenAI infers the following arguments from their corresponding environment variables if they are not provided:\n\n- `api_key` from `AZURE_OPENAI_API_KEY`\n- `azure_ad_token` from `AZURE_OPENAI_AD_TOKEN`\n- `api_version` from `OPENAI_API_VERSION`\n- `azure_endpoint` from `AZURE_OPENAI_ENDPOINT`\n\n\n## Deployments\n\nIn this section we are going to create a deployment of a model that we can use to create embeddings.\n\n### Deployments: Create in the Azure OpenAI Studio\nLet's deploy a model to use with embeddings. Go to https://portal.azure.com, find your Azure OpenAI resource, and then navigate to the Azure OpenAI Studio. Click on the \"Deployments\" tab and then create a deployment for the model you want to use for embeddings. The deployment name that you give the model will be used in the code below."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 44bbc22b-901c-41e2-9c43-6bf6c41fc727
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/azure/embeddings.ipynb", "title": "Azure embeddings example", "tokens": 816, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"44bbc22b-901c-41e2-9c43-6bf6c41fc727\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/embeddings.ipynb\", \"title\": \"Azure embeddings example\", \"tokens\": 816, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"ab2e8823-4f72-4cfb-b753-9dd465e1cbd9\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/embeddings.ipynb\", \"title\": \"Azure embeddings example\", \"tokens\": 816, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"7fe0a7c5a5a05e3f4dcf45a0cb7b6ca5891e8066acbdd6132b75ddb500394eea\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"b6a71ea3-8d6d-4815-a103-a29d503f9bae\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/embeddings.ipynb\", \"title\": \"Azure embeddings example\", \"tokens\": 816, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"9e88bed39f8c866b1163d02e8114e3bf8ef7e20a98529ebc2e7fbfc7f0acc071\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 1967, \"end_char_idx\": 3645, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "ab2e8823-4f72-4cfb-b753-9dd465e1cbd9", "doc_id": "ab2e8823-4f72-4cfb-b753-9dd465e1cbd9", "ref_doc_id": "ab2e8823-4f72-4cfb-b753-9dd465e1cbd9", "chroma:document": "```python\n! pip install \"azure-identity>=1.15.0\"\n```\n\n\n```python\nfrom azure.identity import DefaultAzureCredential, get_bearer_token_provider\n\nif use_azure_active_directory:\n    endpoint = os.environ[\"AZURE_OPENAI_ENDPOINT\"]\n    api_key = os.environ[\"AZURE_OPENAI_API_KEY\"]\n\n    client = openai.AzureOpenAI(\n        azure_endpoint=endpoint,\n        azure_ad_token_provider=get_bearer_token_provider(DefaultAzureCredential(), \"https://cognitiveservices.azure.com/.default\"),\n        api_version=\"2023-09-01-preview\"\n    )\n```\n\n> Note: the AzureOpenAI infers the following arguments from their corresponding environment variables if they are not provided:\n\n- `api_key` from `AZURE_OPENAI_API_KEY`\n- `azure_ad_token` from `AZURE_OPENAI_AD_TOKEN`\n- `api_version` from `OPENAI_API_VERSION`\n- `azure_endpoint` from `AZURE_OPENAI_ENDPOINT`\n\n\n## Deployments\n\nIn this section we are going to create a deployment of a model that we can use to create embeddings.\n\n### Deployments: Create in the Azure OpenAI Studio\nLet's deploy a model to use with embeddings. Go to https://portal.azure.com, find your Azure OpenAI resource, and then navigate to the Azure OpenAI Studio. Click on the \"Deployments\" tab and then create a deployment for the model you want to use for embeddings. The deployment name that you give the model will be used in the code below.\n\n\n```python\ndeployment = \"\" # Fill in the deployment name from the portal here\n```\n\n## Embeddings\n\nNow let's create embeddings using the client we built.\n\n\n```python\nembeddings = client.embeddings.create(\n    model=deployment,\n    input=\"The food was delicious and the waiter...\"\n)\n                                \nprint(embeddings)\n```"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 0943daff-65d2-4ea1-9dcc-f81a5b292d41
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/azure/functions.ipynb", "title": "Azure functions example", "tokens": 1653, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"0943daff-65d2-4ea1-9dcc-f81a5b292d41\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/functions.ipynb\", \"title\": \"Azure functions example\", \"tokens\": 1653, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"dffac5dc-d703-40a7-b91e-4b6095529f47\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/functions.ipynb\", \"title\": \"Azure functions example\", \"tokens\": 1653, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"d0de622efed18c3134dc1bb74fd204f24f1823f6c027a442308bf7a6d2b7b14b\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"1925cbed-340d-4a1d-a21b-9c2ddfe90e6f\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"7f3fdbc7c63dcbb05852019f307d7636a7ebaf33392c485545571f75670347c4\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 0, \"end_char_idx\": 3264, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "dffac5dc-d703-40a7-b91e-4b6095529f47", "doc_id": "dffac5dc-d703-40a7-b91e-4b6095529f47", "ref_doc_id": "dffac5dc-d703-40a7-b91e-4b6095529f47", "chroma:document": "# Azure functions example\n\nThis notebook shows how to use the function calling capability with the Azure OpenAI service. Functions allow a caller of chat completions to define capabilities that the model can use to extend its\nfunctionality into external tools and data sources.\n\nYou can read more about chat functions on OpenAI's blog: https://openai.com/blog/function-calling-and-other-api-updates\n\n**NOTE**: Chat functions require model versions beginning with gpt-4 and gpt-35-turbo's `-0613` labels. They are not supported by older versions of the models.\n\n## Setup\n\nFirst, we install the necessary dependencies and import the libraries we will be using.\n\n\n```python\n! pip install \"openai>=1.0.0,<2.0.0\"\n! pip install python-dotenv\n```\n\n\n```python\nimport os\nimport openai\nimport dotenv\n\ndotenv.load_dotenv()\n```\n\n### Authentication\n\nThe Azure OpenAI service supports multiple authentication mechanisms that include API keys and Azure Active Directory token credentials.\n\n\n```python\nuse_azure_active_directory = False  # Set this flag to True if you are using Azure Active Directory\n```\n\n#### Authentication using API key\n\nTo set up the OpenAI SDK to use an *Azure API Key*, we need to set `api_key` to a key associated with your endpoint (you can find this key in *\"Keys and Endpoints\"* under *\"Resource Management\"* in the [Azure Portal](https://portal.azure.com)). You'll also find the endpoint for your resource here.\n\n\n```python\nif not use_azure_active_directory:\n    endpoint = os.environ[\"AZURE_OPENAI_ENDPOINT\"]\n    api_key = os.environ[\"AZURE_OPENAI_API_KEY\"]\n\n    client = openai.AzureOpenAI(\n        azure_endpoint=endpoint,\n        api_key=api_key,\n        api_version=\"2023-09-01-preview\"\n    )\n```\n\n#### Authentication using Azure Active Directory\nLet's now see how we can autheticate via Azure Active Directory. We'll start by installing the `azure-identity` library. This library will provide the token credentials we need to authenticate and help us build a token credential provider through the `get_bearer_token_provider` helper function. It's recommended to use `get_bearer_token_provider` over providing a static token to `AzureOpenAI` because this API will automatically cache and refresh tokens for you. \n\nFor more information on how to set up Azure Active Directory authentication with Azure OpenAI, see the [documentation](https://learn.microsoft.com/azure/ai-services/openai/how-to/managed-identity).\n\n\n```python\n! pip install \"azure-identity>=1.15.0\"\n```\n\n\n```python\nfrom azure.identity import DefaultAzureCredential, get_bearer_token_provider\n\nif use_azure_active_directory:\n    endpoint = os.environ[\"AZURE_OPENAI_ENDPOINT\"]\n    api_key = os.environ[\"AZURE_OPENAI_API_KEY\"]\n\n    client = openai.AzureOpenAI(\n        azure_endpoint=endpoint,\n        azure_ad_token_provider=get_bearer_token_provider(DefaultAzureCredential(), \"https://cognitiveservices.azure.com/.default\"),\n        api_version=\"2023-09-01-preview\"\n    )\n```\n\n> Note: the AzureOpenAI infers the following arguments from their corresponding environment variables if they are not provided:\n\n- `api_key` from `AZURE_OPENAI_API_KEY`\n- `azure_ad_token` from `AZURE_OPENAI_AD_TOKEN`\n- `api_version` from `OPENAI_API_VERSION`\n- `azure_endpoint` from `AZURE_OPENAI_ENDPOINT`"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 1925cbed-340d-4a1d-a21b-9c2ddfe90e6f
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/azure/functions.ipynb", "title": "Azure functions example", "tokens": 1653, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"1925cbed-340d-4a1d-a21b-9c2ddfe90e6f\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/functions.ipynb\", \"title\": \"Azure functions example\", \"tokens\": 1653, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"dffac5dc-d703-40a7-b91e-4b6095529f47\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/functions.ipynb\", \"title\": \"Azure functions example\", \"tokens\": 1653, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"d0de622efed18c3134dc1bb74fd204f24f1823f6c027a442308bf7a6d2b7b14b\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"0943daff-65d2-4ea1-9dcc-f81a5b292d41\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/functions.ipynb\", \"title\": \"Azure functions example\", \"tokens\": 1653, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"d6b041abbc08a853f560a9e0a452681f0299b4f542918a608ba6807b01a7bb5b\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"5be9604f-0ed3-4a67-b860-5fde7d6e0c6b\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"aca4adeab92c6a47a3a9f517693ef4ccee787d6a4ba39d21fa2aed5f016ddf13\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 2432, \"end_char_idx\": 5725, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "dffac5dc-d703-40a7-b91e-4b6095529f47", "doc_id": "dffac5dc-d703-40a7-b91e-4b6095529f47", "ref_doc_id": "dffac5dc-d703-40a7-b91e-4b6095529f47", "chroma:document": "```python\n! pip install \"azure-identity>=1.15.0\"\n```\n\n\n```python\nfrom azure.identity import DefaultAzureCredential, get_bearer_token_provider\n\nif use_azure_active_directory:\n    endpoint = os.environ[\"AZURE_OPENAI_ENDPOINT\"]\n    api_key = os.environ[\"AZURE_OPENAI_API_KEY\"]\n\n    client = openai.AzureOpenAI(\n        azure_endpoint=endpoint,\n        azure_ad_token_provider=get_bearer_token_provider(DefaultAzureCredential(), \"https://cognitiveservices.azure.com/.default\"),\n        api_version=\"2023-09-01-preview\"\n    )\n```\n\n> Note: the AzureOpenAI infers the following arguments from their corresponding environment variables if they are not provided:\n\n- `api_key` from `AZURE_OPENAI_API_KEY`\n- `azure_ad_token` from `AZURE_OPENAI_AD_TOKEN`\n- `api_version` from `OPENAI_API_VERSION`\n- `azure_endpoint` from `AZURE_OPENAI_ENDPOINT`\n\n\n## Deployments\n\nIn this section we are going to create a deployment of a GPT model that we can use to call functions.\n\n### Deployments: Create in the Azure OpenAI Studio\nLet's deploy a model to use with chat completions. Go to https://portal.azure.com, find your Azure OpenAI resource, and then navigate to the Azure OpenAI Studio. Click on the \"Deployments\" tab and then create a deployment for the model you want to use for chat completions. The deployment name that you give the model will be used in the code below.\n\n\n```python\ndeployment = \"\" # Fill in the deployment name from the portal here\n```\n\n## Functions\n\nWith setup and authentication complete, you can now use functions with the Azure OpenAI service. This will be split into a few steps:\n\n1. Define the function(s)\n2. Pass function definition(s) into chat completions API\n3. Call function with arguments from the response\n4. Feed function response back into chat completions API\n\n#### 1. Define the function(s)\n\nA list of functions can be defined, each containing the name of the function, an optional description, and the parameters the function accepts (described as a JSON schema).\n\n\n```python\nfunctions = [\n    {\n        \"name\": \"get_current_weather\",\n        \"description\": \"Get the current weather\",\n        \"parameters\": {\n            \"type\": \"object\",\n            \"properties\": {\n                \"location\": {\n                    \"type\": \"string\",\n                    \"description\": \"The city and state, e.g. San Francisco, CA\",\n                },\n                \"format\": {\n                    \"type\": \"string\",\n                    \"enum\": [\"celsius\", \"fahrenheit\"],\n                    \"description\": \"The temperature unit to use. Infer this from the users location.\",\n                },\n            },\n            \"required\": [\"location\"],\n        },\n    }\n]\n```\n\n#### 2. Pass function definition(s) into chat completions API\n\nNow we can pass the function into the chat completions API. If the model determines it should call the function, a `finish_reason` of \"tool_calls\" will be populated on the choice and the details of which function to call and its arguments will be present in the `message`. Optionally, you can set the `tool_choice` keyword argument to force the model to call a particular function (e.g. `{\"type\": \"function\", \"function\": {\"name\": get_current_weather}}`). By default, this is set to `auto`, allowing the model to choose whether to call the function or not."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 5be9604f-0ed3-4a67-b860-5fde7d6e0c6b
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/azure/functions.ipynb", "title": "Azure functions example", "tokens": 1653, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"5be9604f-0ed3-4a67-b860-5fde7d6e0c6b\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/functions.ipynb\", \"title\": \"Azure functions example\", \"tokens\": 1653, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"dffac5dc-d703-40a7-b91e-4b6095529f47\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/functions.ipynb\", \"title\": \"Azure functions example\", \"tokens\": 1653, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"d0de622efed18c3134dc1bb74fd204f24f1823f6c027a442308bf7a6d2b7b14b\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"1925cbed-340d-4a1d-a21b-9c2ddfe90e6f\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/functions.ipynb\", \"title\": \"Azure functions example\", \"tokens\": 1653, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"7118d8c34a95c44be8919d00f9ec978312c9da69e01e776ae3f6550bead40c98\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 4418, \"end_char_idx\": 7562, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "dffac5dc-d703-40a7-b91e-4b6095529f47", "doc_id": "dffac5dc-d703-40a7-b91e-4b6095529f47", "ref_doc_id": "dffac5dc-d703-40a7-b91e-4b6095529f47", "chroma:document": "```python\nfunctions = [\n    {\n        \"name\": \"get_current_weather\",\n        \"description\": \"Get the current weather\",\n        \"parameters\": {\n            \"type\": \"object\",\n            \"properties\": {\n                \"location\": {\n                    \"type\": \"string\",\n                    \"description\": \"The city and state, e.g. San Francisco, CA\",\n                },\n                \"format\": {\n                    \"type\": \"string\",\n                    \"enum\": [\"celsius\", \"fahrenheit\"],\n                    \"description\": \"The temperature unit to use. Infer this from the users location.\",\n                },\n            },\n            \"required\": [\"location\"],\n        },\n    }\n]\n```\n\n#### 2. Pass function definition(s) into chat completions API\n\nNow we can pass the function into the chat completions API. If the model determines it should call the function, a `finish_reason` of \"tool_calls\" will be populated on the choice and the details of which function to call and its arguments will be present in the `message`. Optionally, you can set the `tool_choice` keyword argument to force the model to call a particular function (e.g. `{\"type\": \"function\", \"function\": {\"name\": get_current_weather}}`). By default, this is set to `auto`, allowing the model to choose whether to call the function or not. \n\n\n```python\nmessages = [\n    {\"role\": \"system\", \"content\": \"Don't make assumptions about what values to plug into functions. Ask for clarification if a user request is ambiguous.\"},\n    {\"role\": \"user\", \"content\": \"What's the weather like today in Seattle?\"}\n]\n\nchat_completion = client.chat.completions.create(\n    model=deployment,\n    messages=messages,\n    tools=functions,\n)\nprint(chat_completion)\n```\n\n#### 3. Call function with arguments from the response\n\nThe name of the function call will be one that was provided initially and the arguments will include JSON matching the schema included in the function definition.\n\n\n```python\nimport json\n\ndef get_current_weather(request):\n    \"\"\"\n    This function is for illustrative purposes.\n    The location and unit should be used to determine weather\n    instead of returning a hardcoded response.\n    \"\"\"\n    location = request.get(\"location\")\n    unit = request.get(\"unit\")\n    return {\"temperature\": \"22\", \"unit\": \"celsius\", \"description\": \"Sunny\"}\n\nfunction_call = chat_completion.choices[0].message.tool_calls[0].function\nprint(function_call.name)\nprint(function_call.arguments)\n\nif function_call.name == \"get_current_weather\":\n    response = get_current_weather(json.loads(function_call.arguments))\n```\n\n#### 4. Feed function response back into chat completions API\n\nThe response from the function should be serialized into a new message with the role set to \"function\". Now the model will use the response data to formulate its answer.\n\n\n```python\nmessages.append(\n    {\n        \"role\": \"function\",\n        \"name\": \"get_current_weather\",\n        \"content\": json.dumps(response)\n    }\n)\n\nfunction_completion = client.chat.completions.create(\n    model=deployment,\n    messages=messages,\n    tools=functions,\n)\n\nprint(function_completion.choices[0].message.content.strip())\n```"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: cb710e8d-e50d-4089-93f8-f89f14e59fe2
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/azure/chat_with_your_own_data.ipynb", "title": "Azure chat completion models with your own data (preview)", "tokens": 2205, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"cb710e8d-e50d-4089-93f8-f89f14e59fe2\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/chat_with_your_own_data.ipynb\", \"title\": \"Azure chat completion models with your own data (preview)\", \"tokens\": 2205, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"0c03f8ed-9c1b-4625-add6-ca17f2d0176c\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/chat_with_your_own_data.ipynb\", \"title\": \"Azure chat completion models with your own data (preview)\", \"tokens\": 2205, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"4ec30e7d81fd63c5649ef3e786352185e9512594ae626d36f61e5d4fed8d7782\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"299d2503-00df-4848-a924-0266a1f92a0a\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"c4fa17786a418259288dfdebf63475528419c324e41bdab2fea2918b1f23da29\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 0, \"end_char_idx\": 3192, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "0c03f8ed-9c1b-4625-add6-ca17f2d0176c", "doc_id": "0c03f8ed-9c1b-4625-add6-ca17f2d0176c", "ref_doc_id": "0c03f8ed-9c1b-4625-add6-ca17f2d0176c", "chroma:document": "# Azure chat completion models with your own data (preview)\nThis example shows how to use Azure OpenAI service models with your own data. The feature is currently in preview. \n\nAzure OpenAI on your data enables you to run supported chat models such as GPT-3.5-Turbo and GPT-4 on your data without needing to train or fine-tune models. Running models on your data enables you to chat on top of, and analyze your data with greater accuracy and speed. One of the key benefits of Azure OpenAI on your data is its ability to tailor the content of conversational AI. Because the model has access to, and can reference specific sources to support its responses, answers are not only based on its pretrained knowledge but also on the latest information available in the designated data source. This grounding data also helps the model avoid generating responses based on outdated or incorrect information.\n\nAzure OpenAI on your own data with Azure AI Search (f.k.a. Azure Cognitive Search) provides a customizable, pre-built solution for knowledge retrieval, from which a conversational AI application can be built. To see alternative methods for knowledge retrieval and semantic search, check out the cookbook examples for [vector databases](https://github.com/openai/openai-cookbook/tree/main/examples/vector_databases).\n\n## How it works\n\n[Azure OpenAI on your own data](https://learn.microsoft.com/azure/ai-services/openai/concepts/use-your-data) connects the model with your data, giving it the ability to retrieve and utilize data in a way that enhances the model's output. Together with Azure AI Search, data is retrieved from designated data sources based on the user input and provided conversation history. The data is then augmented and resubmitted as a prompt to the model, giving the model contextual information it can use to generate a response.\n\nSee the [Data, privacy, and security for Azure OpenAI Service](https://learn.microsoft.com/legal/cognitive-services/openai/data-privacy?context=%2Fazure%2Fai-services%2Fopenai%2Fcontext%2Fcontext) for more information.\n\n## Prerequisites\nTo get started, we'll cover a few prequisites. \n\nTo properly access the Azure OpenAI Service, we need to create the proper resources at the [Azure Portal](https://portal.azure.com) (you can check a detailed guide on how to do this in the [Microsoft Docs](https://learn.microsoft.com/azure/cognitive-services/openai/how-to/create-resource?pivots=web-portal))\n\nTo use your own data with Azure OpenAI models, you will need:\n\n1. Azure OpenAI access and a resource with a chat model deployed (for example, GPT-3 or GPT-4)\n2. Azure AI Search (f.k.a. Azure Cognitive Search) resource\n3. Azure Blob Storage resource\n4. Your documents to be used as data (See [data source options](https://learn.microsoft.com/azure/ai-services/openai/concepts/use-your-data#data-source-options))\n\n\nFor a full walk-through on how to upload your documents to blob storage and create an index using the Azure AI Studio, see this [Quickstart](https://learn.microsoft.com/azure/ai-services/openai/use-your-data-quickstart?pivots=programming-language-studio&tabs=command-line).\n\n## Setup\n\nFirst, we install the necessary dependencies."}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 299d2503-00df-4848-a924-0266a1f92a0a
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/azure/chat_with_your_own_data.ipynb", "title": "Azure chat completion models with your own data (preview)", "tokens": 2205, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"299d2503-00df-4848-a924-0266a1f92a0a\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/chat_with_your_own_data.ipynb\", \"title\": \"Azure chat completion models with your own data (preview)\", \"tokens\": 2205, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"0c03f8ed-9c1b-4625-add6-ca17f2d0176c\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/chat_with_your_own_data.ipynb\", \"title\": \"Azure chat completion models with your own data (preview)\", \"tokens\": 2205, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"4ec30e7d81fd63c5649ef3e786352185e9512594ae626d36f61e5d4fed8d7782\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"cb710e8d-e50d-4089-93f8-f89f14e59fe2\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/chat_with_your_own_data.ipynb\", \"title\": \"Azure chat completion models with your own data (preview)\", \"tokens\": 2205, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"7aef50c3d7ef051a664739e113f6a0c8ff77fb050e20279adfaf9e02043309d0\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"63543361-78c5-452e-a406-ac7816b19094\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"a3e8d8cd5fac279152ab544faffcebfaffcebe56c69d828e9bf7a069e894ec28\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 2862, \"end_char_idx\": 6104, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "0c03f8ed-9c1b-4625-add6-ca17f2d0176c", "doc_id": "0c03f8ed-9c1b-4625-add6-ca17f2d0176c", "ref_doc_id": "0c03f8ed-9c1b-4625-add6-ca17f2d0176c", "chroma:document": "For a full walk-through on how to upload your documents to blob storage and create an index using the Azure AI Studio, see this [Quickstart](https://learn.microsoft.com/azure/ai-services/openai/use-your-data-quickstart?pivots=programming-language-studio&tabs=command-line).\n\n## Setup\n\nFirst, we install the necessary dependencies.\n\n\n```python\n! pip install \"openai>=1.0.0,<2.0.0\"\n! pip install python-dotenv\n```\n\nIn this example, we'll use `dotenv` to load our environment variables. To connect with Azure OpenAI and the Search index, the following variables should be added to a `.env` file in `KEY=VALUE` format:\n\n* `AZURE_OPENAI_ENDPOINT` - the Azure OpenAI endpoint. This can be found under \"Keys and Endpoints\" for your Azure OpenAI resource in the Azure Portal.\n* `AZURE_OPENAI_API_KEY` - the Azure OpenAI API key. This can be found under \"Keys and Endpoints\" for your Azure OpenAI resource in the Azure Portal. Omit if using Azure Active Directory authentication (see below `Authentication using Microsoft Active Directory`)\n* `SEARCH_ENDPOINT` - the AI Search endpoint. This URL be found on the \"Overview\" of your Search resource on the Azure Portal.\n* `SEARCH_KEY` - the AI Search API key. Found under \"Keys\" for your Search resource in the Azure Portal.\n* `SEARCH_INDEX_NAME` - the name of the index you created with your own data.\n\n\n```python\nimport os\nimport openai\nimport dotenv\n\ndotenv.load_dotenv()\n```\n\n### Authentication\n\nThe Azure OpenAI service supports multiple authentication mechanisms that include API keys and Azure Active Directory token credentials.\n\n\n```python\nuse_azure_active_directory = False  # Set this flag to True if you are using Azure Active Directory\n```\n\n#### Authentication using API key\n\nTo set up the OpenAI SDK to use an *Azure API Key*, we need to set `api_key` to a key associated with your endpoint (you can find this key in *\"Keys and Endpoints\"* under *\"Resource Management\"* in the [Azure Portal](https://portal.azure.com)). You'll also find the endpoint for your resource here.\n\n\n```python\nif not use_azure_active_directory:\n    endpoint = os.environ[\"AZURE_OPENAI_ENDPOINT\"]\n    api_key = os.environ[\"AZURE_OPENAI_API_KEY\"]\n    # set the deployment name for the model we want to use\n    deployment = \"<deployment-id-of-the-model-to-use>\"\n\n    client = openai.AzureOpenAI(\n        base_url=f\"{endpoint}/openai/deployments/{deployment}/extensions\",\n        api_key=api_key,\n        api_version=\"2023-09-01-preview\"\n    )\n```\n\n#### Authentication using Azure Active Directory\nLet's now see how we can autheticate via Azure Active Directory. We'll start by installing the `azure-identity` library. This library will provide the token credentials we need to authenticate and help us build a token credential provider through the `get_bearer_token_provider` helper function. It's recommended to use `get_bearer_token_provider` over providing a static token to `AzureOpenAI` because this API will automatically cache and refresh tokens for you. \n\nFor more information on how to set up Azure Active Directory authentication with Azure OpenAI, see the [documentation](https://learn.microsoft.com/azure/ai-services/openai/how-to/managed-identity).\n\n\n```python\n! pip install \"azure-identity>=1.15.0\"\n```"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 63543361-78c5-452e-a406-ac7816b19094
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/azure/chat_with_your_own_data.ipynb", "title": "Azure chat completion models with your own data (preview)", "tokens": 2205, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"63543361-78c5-452e-a406-ac7816b19094\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/chat_with_your_own_data.ipynb\", \"title\": \"Azure chat completion models with your own data (preview)\", \"tokens\": 2205, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"0c03f8ed-9c1b-4625-add6-ca17f2d0176c\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/chat_with_your_own_data.ipynb\", \"title\": \"Azure chat completion models with your own data (preview)\", \"tokens\": 2205, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"4ec30e7d81fd63c5649ef3e786352185e9512594ae626d36f61e5d4fed8d7782\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"299d2503-00df-4848-a924-0266a1f92a0a\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/chat_with_your_own_data.ipynb\", \"title\": \"Azure chat completion models with your own data (preview)\", \"tokens\": 2205, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"55dbd35d26b7cb6c91bd433bdc23e42ff51c94a192f946cba281ff85130fe50a\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"cd4a977e-1724-4be3-9724-90120edd31ad\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"9b068f476c1fd86e5fa7007723a6eb46a6c68fcaf6f1b32cdbebc34ab04c6465\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 4440, \"end_char_idx\": 7040, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "0c03f8ed-9c1b-4625-add6-ca17f2d0176c", "doc_id": "0c03f8ed-9c1b-4625-add6-ca17f2d0176c", "ref_doc_id": "0c03f8ed-9c1b-4625-add6-ca17f2d0176c", "chroma:document": "```python\nuse_azure_active_directory = False  # Set this flag to True if you are using Azure Active Directory\n```\n\n#### Authentication using API key\n\nTo set up the OpenAI SDK to use an *Azure API Key*, we need to set `api_key` to a key associated with your endpoint (you can find this key in *\"Keys and Endpoints\"* under *\"Resource Management\"* in the [Azure Portal](https://portal.azure.com)). You'll also find the endpoint for your resource here.\n\n\n```python\nif not use_azure_active_directory:\n    endpoint = os.environ[\"AZURE_OPENAI_ENDPOINT\"]\n    api_key = os.environ[\"AZURE_OPENAI_API_KEY\"]\n    # set the deployment name for the model we want to use\n    deployment = \"<deployment-id-of-the-model-to-use>\"\n\n    client = openai.AzureOpenAI(\n        base_url=f\"{endpoint}/openai/deployments/{deployment}/extensions\",\n        api_key=api_key,\n        api_version=\"2023-09-01-preview\"\n    )\n```\n\n#### Authentication using Azure Active Directory\nLet's now see how we can autheticate via Azure Active Directory. We'll start by installing the `azure-identity` library. This library will provide the token credentials we need to authenticate and help us build a token credential provider through the `get_bearer_token_provider` helper function. It's recommended to use `get_bearer_token_provider` over providing a static token to `AzureOpenAI` because this API will automatically cache and refresh tokens for you. \n\nFor more information on how to set up Azure Active Directory authentication with Azure OpenAI, see the [documentation](https://learn.microsoft.com/azure/ai-services/openai/how-to/managed-identity).\n\n\n```python\n! pip install \"azure-identity>=1.15.0\"\n```\n\n\n```python\nfrom azure.identity import DefaultAzureCredential, get_bearer_token_provider\n\nif use_azure_active_directory:\n    endpoint = os.environ[\"AZURE_OPENAI_ENDPOINT\"]\n    api_key = os.environ[\"AZURE_OPENAI_API_KEY\"]\n    # set the deployment name for the model we want to use\n    deployment = \"<deployment-id-of-the-model-to-use>\"\n\n    client = openai.AzureOpenAI(\n        base_url=f\"{endpoint}/openai/deployments/{deployment}/extensions\",\n        azure_ad_token_provider=get_bearer_token_provider(DefaultAzureCredential(), \"https://cognitiveservices.azure.com/.default\"),\n        api_version=\"2023-09-01-preview\"\n    )\n```\n\n> Note: the AzureOpenAI infers the following arguments from their corresponding environment variables if they are not provided:\n\n- `api_key` from `AZURE_OPENAI_API_KEY`\n- `azure_ad_token` from `AZURE_OPENAI_AD_TOKEN`\n- `api_version` from `OPENAI_API_VERSION`\n- `azure_endpoint` from `AZURE_OPENAI_ENDPOINT`"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: cd4a977e-1724-4be3-9724-90120edd31ad
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/azure/chat_with_your_own_data.ipynb", "title": "Azure chat completion models with your own data (preview)", "tokens": 2205, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"cd4a977e-1724-4be3-9724-90120edd31ad\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/chat_with_your_own_data.ipynb\", \"title\": \"Azure chat completion models with your own data (preview)\", \"tokens\": 2205, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"0c03f8ed-9c1b-4625-add6-ca17f2d0176c\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/chat_with_your_own_data.ipynb\", \"title\": \"Azure chat completion models with your own data (preview)\", \"tokens\": 2205, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"4ec30e7d81fd63c5649ef3e786352185e9512594ae626d36f61e5d4fed8d7782\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"63543361-78c5-452e-a406-ac7816b19094\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/chat_with_your_own_data.ipynb\", \"title\": \"Azure chat completion models with your own data (preview)\", \"tokens\": 2205, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"a642657e6d271d32d144b9bcf0baa564d5c1f7b0e72a11f3d9b5b27a40d312ca\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"cc2b129d-0f2d-46ea-95a1-d6937742285a\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"4177c9e850ecfa2998aefdee2181db22fbf4f1ba8f212d4b382b15f953bcb512\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 6052, \"end_char_idx\": 9069, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "0c03f8ed-9c1b-4625-add6-ca17f2d0176c", "doc_id": "0c03f8ed-9c1b-4625-add6-ca17f2d0176c", "ref_doc_id": "0c03f8ed-9c1b-4625-add6-ca17f2d0176c", "chroma:document": "```python\n! pip install \"azure-identity>=1.15.0\"\n```\n\n\n```python\nfrom azure.identity import DefaultAzureCredential, get_bearer_token_provider\n\nif use_azure_active_directory:\n    endpoint = os.environ[\"AZURE_OPENAI_ENDPOINT\"]\n    api_key = os.environ[\"AZURE_OPENAI_API_KEY\"]\n    # set the deployment name for the model we want to use\n    deployment = \"<deployment-id-of-the-model-to-use>\"\n\n    client = openai.AzureOpenAI(\n        base_url=f\"{endpoint}/openai/deployments/{deployment}/extensions\",\n        azure_ad_token_provider=get_bearer_token_provider(DefaultAzureCredential(), \"https://cognitiveservices.azure.com/.default\"),\n        api_version=\"2023-09-01-preview\"\n    )\n```\n\n> Note: the AzureOpenAI infers the following arguments from their corresponding environment variables if they are not provided:\n\n- `api_key` from `AZURE_OPENAI_API_KEY`\n- `azure_ad_token` from `AZURE_OPENAI_AD_TOKEN`\n- `api_version` from `OPENAI_API_VERSION`\n- `azure_endpoint` from `AZURE_OPENAI_ENDPOINT`\n\n\n## Chat completion model with your own data\n\n### Setting the context\n\nIn this example, we want our model to base its responses on Azure AI services documentation data. Following the [Quickstart](https://learn.microsoft.com/azure/ai-services/openai/use-your-data-quickstart?tabs=command-line&pivots=programming-language-studio) shared previously, we have added the [markdown](https://github.com/MicrosoftDocs/azure-docs/blob/main/articles/ai-services/cognitive-services-and-machine-learning.md) file for the [Azure AI services and machine learning](https://learn.microsoft.com/azure/ai-services/cognitive-services-and-machine-learning) documentation page to our search index. The model is now ready to answer questions about Azure AI services and machine learning.\n\n### Code\n\nNow we can use Azure on your own data with Chat Completions. Providing our search endpoint, key, and index name in `dataSources`, any questions posed to the model will now be grounded in our own data. An additional property, `context`, will be provided in the response to show the data the model referenced to answer the question.\n\n\n```python\ncompletion = client.chat.completions.create(\n    messages=[{\"role\": \"user\", \"content\": \"What are the differences between Azure Machine Learning and Azure AI services?\"}],\n    model=deployment,\n    extra_body={\n        \"dataSources\": [\n            {\n                \"type\": \"AzureCognitiveSearch\",\n                \"parameters\": {\n                    \"endpoint\": os.environ[\"SEARCH_ENDPOINT\"],\n                    \"key\": os.environ[\"SEARCH_KEY\"],\n                    \"indexName\": os.environ[\"SEARCH_INDEX_NAME\"],\n                }\n            }\n        ]\n    }\n)\nprint(f\"{completion.choices[0].message.role}: {completion.choices[0].message.content}\")\n\n# `context` is in the model_extra for Azure\nprint(f\"\\nContext: {completion.choices[0].message.model_extra['context']['messages'][0]['content']}\")\n```\n\nIf you would prefer to stream the response from the model, you can pass the `stream=True` keyword argument:"}


created_at: 2024-07-28 18:59:18
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: cc2b129d-0f2d-46ea-95a1-d6937742285a
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/azure/chat_with_your_own_data.ipynb", "title": "Azure chat completion models with your own data (preview)", "tokens": 2205, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"cc2b129d-0f2d-46ea-95a1-d6937742285a\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/chat_with_your_own_data.ipynb\", \"title\": \"Azure chat completion models with your own data (preview)\", \"tokens\": 2205, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"0c03f8ed-9c1b-4625-add6-ca17f2d0176c\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/chat_with_your_own_data.ipynb\", \"title\": \"Azure chat completion models with your own data (preview)\", \"tokens\": 2205, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"4ec30e7d81fd63c5649ef3e786352185e9512594ae626d36f61e5d4fed8d7782\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"cd4a977e-1724-4be3-9724-90120edd31ad\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/chat_with_your_own_data.ipynb\", \"title\": \"Azure chat completion models with your own data (preview)\", \"tokens\": 2205, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"99f42a5905b3a9599d13c0b967232d33d1db50b218fd2973be6767484ca2cf4f\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 8151, \"end_char_idx\": 9990, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "0c03f8ed-9c1b-4625-add6-ca17f2d0176c", "doc_id": "0c03f8ed-9c1b-4625-add6-ca17f2d0176c", "ref_doc_id": "0c03f8ed-9c1b-4625-add6-ca17f2d0176c", "chroma:document": "```python\ncompletion = client.chat.completions.create(\n    messages=[{\"role\": \"user\", \"content\": \"What are the differences between Azure Machine Learning and Azure AI services?\"}],\n    model=deployment,\n    extra_body={\n        \"dataSources\": [\n            {\n                \"type\": \"AzureCognitiveSearch\",\n                \"parameters\": {\n                    \"endpoint\": os.environ[\"SEARCH_ENDPOINT\"],\n                    \"key\": os.environ[\"SEARCH_KEY\"],\n                    \"indexName\": os.environ[\"SEARCH_INDEX_NAME\"],\n                }\n            }\n        ]\n    }\n)\nprint(f\"{completion.choices[0].message.role}: {completion.choices[0].message.content}\")\n\n# `context` is in the model_extra for Azure\nprint(f\"\\nContext: {completion.choices[0].message.model_extra['context']['messages'][0]['content']}\")\n```\n\nIf you would prefer to stream the response from the model, you can pass the `stream=True` keyword argument:\n\n\n```python\nresponse = client.chat.completions.create(\n    messages=[{\"role\": \"user\", \"content\": \"What are the differences between Azure Machine Learning and Azure AI services?\"}],\n    model=deployment,\n    extra_body={\n        \"dataSources\": [\n            {\n                \"type\": \"AzureCognitiveSearch\",\n                \"parameters\": {\n                    \"endpoint\": os.environ[\"SEARCH_ENDPOINT\"],\n                    \"key\": os.environ[\"SEARCH_KEY\"],\n                    \"indexName\": os.environ[\"SEARCH_INDEX_NAME\"],\n                }\n            }\n        ]\n    },\n    stream=True,\n)\n\nfor chunk in response:\n    delta = chunk.choices[0].delta\n\n    if delta.role:\n        print(\"\\n\"+ delta.role + \": \", end=\"\", flush=True)\n    if delta.content:\n        print(delta.content, end=\"\", flush=True)\n    if delta.model_extra.get(\"context\"):\n        print(f\"Context: {delta.model_extra['context']}\", end=\"\", flush=True)\n```"}


created_at: 2024-07-28 18:59:25
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: c3c50273-6289-406a-ade2-5d2c6a9dbd38
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/azure/archive/completions.ipynb", "title": "Azure completions example", "tokens": 903, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"c3c50273-6289-406a-ade2-5d2c6a9dbd38\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/archive/completions.ipynb\", \"title\": \"Azure completions example\", \"tokens\": 903, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"489cf90b-7de2-4f5b-96e2-10e171c3611c\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/archive/completions.ipynb\", \"title\": \"Azure completions example\", \"tokens\": 903, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"63f93087a77114e71b10b5fcffac807ff702d5c89e4f3bea448e94d9f3f340cb\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"d76197f1-8c57-46c4-85e4-daca2d280f34\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"927f9a4d15c2070779d098d96c1eceb77e0c210c7b65a68b2565ad798546d011\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 0, \"end_char_idx\": 2276, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "489cf90b-7de2-4f5b-96e2-10e171c3611c", "doc_id": "489cf90b-7de2-4f5b-96e2-10e171c3611c", "ref_doc_id": "489cf90b-7de2-4f5b-96e2-10e171c3611c", "chroma:document": "# Azure completions example\n\n> Note: There is a newer version of the openai library available. See https://github.com/openai/openai-python/discussions/742\n\nThis example will cover completions using the Azure OpenAI service.\n\n## Setup\n\n\nFirst, we install the necessary dependencies.\n\n\n```python\n! pip install \"openai>=0.28.1,<1.0.0\"\n```\n\nFor the following sections to work properly we first have to setup some things. Let's start with the `api_base` and `api_version`. To find your `api_base` go to https://portal.azure.com, find your resource and then under \"Resource Management\" -> \"Keys and Endpoints\" look for the \"Endpoint\" value.\n\n\n```python\nimport os\nimport openai\n```\n\n\n```python\nopenai.api_version = '2023-05-15'\nopenai.api_base = '' # Please add your endpoint here\n```\n\nWe next have to setup the `api_type` and `api_key`. We can either get the key from the portal or we can get it through Microsoft Active Directory Authentication. Depending on this the `api_type` is either `azure` or `azure_ad`.\n\n### Setup: Portal\nLet's first look at getting the key from the portal. Go to https://portal.azure.com, find your resource and then under \"Resource Management\" -> \"Keys and Endpoints\" look for one of the \"Keys\" values.\n\n\n```python\nopenai.api_type = 'azure'\nopenai.api_key = os.environ[\"OPENAI_API_KEY\"]\n```\n\n> Note: In this example, we configured the library to use the Azure API by setting the variables in code. For development, consider setting the environment variables instead:\n\n```\nOPENAI_API_BASE\nOPENAI_API_KEY\nOPENAI_API_TYPE\nOPENAI_API_VERSION\n```\n\n### (Optional) Setup: Microsoft Active Directory Authentication\nLet's now see how we can get a key via Microsoft Active Directory Authentication. Uncomment the following code if you want to use Active Directory Authentication instead of keys from the portal.\n\n\n```python\n# from azure.identity import DefaultAzureCredential\n\n# default_credential = DefaultAzureCredential()\n# token = default_credential.get_token(\"https://cognitiveservices.azure.com/.default\")\n\n# openai.api_type = 'azure_ad'\n# openai.api_key = token.token\n```\n\nA token is valid for a period of time, after which it will expire. To ensure a valid token is sent with every request, you can refresh an expiring token by hooking into requests.auth:"}


created_at: 2024-07-28 18:59:25
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: d76197f1-8c57-46c4-85e4-daca2d280f34
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/azure/archive/completions.ipynb", "title": "Azure completions example", "tokens": 903, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"d76197f1-8c57-46c4-85e4-daca2d280f34\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/archive/completions.ipynb\", \"title\": \"Azure completions example\", \"tokens\": 903, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"489cf90b-7de2-4f5b-96e2-10e171c3611c\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/archive/completions.ipynb\", \"title\": \"Azure completions example\", \"tokens\": 903, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"63f93087a77114e71b10b5fcffac807ff702d5c89e4f3bea448e94d9f3f340cb\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"c3c50273-6289-406a-ade2-5d2c6a9dbd38\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/archive/completions.ipynb\", \"title\": \"Azure completions example\", \"tokens\": 903, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"cd96136d07485e14e23c132dec06fdf0bc58b561413ceca82be8f2f062f88858\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 637, \"end_char_idx\": 3915, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "489cf90b-7de2-4f5b-96e2-10e171c3611c", "doc_id": "489cf90b-7de2-4f5b-96e2-10e171c3611c", "ref_doc_id": "489cf90b-7de2-4f5b-96e2-10e171c3611c", "chroma:document": "```python\nimport os\nimport openai\n```\n\n\n```python\nopenai.api_version = '2023-05-15'\nopenai.api_base = '' # Please add your endpoint here\n```\n\nWe next have to setup the `api_type` and `api_key`. We can either get the key from the portal or we can get it through Microsoft Active Directory Authentication. Depending on this the `api_type` is either `azure` or `azure_ad`.\n\n### Setup: Portal\nLet's first look at getting the key from the portal. Go to https://portal.azure.com, find your resource and then under \"Resource Management\" -> \"Keys and Endpoints\" look for one of the \"Keys\" values.\n\n\n```python\nopenai.api_type = 'azure'\nopenai.api_key = os.environ[\"OPENAI_API_KEY\"]\n```\n\n> Note: In this example, we configured the library to use the Azure API by setting the variables in code. For development, consider setting the environment variables instead:\n\n```\nOPENAI_API_BASE\nOPENAI_API_KEY\nOPENAI_API_TYPE\nOPENAI_API_VERSION\n```\n\n### (Optional) Setup: Microsoft Active Directory Authentication\nLet's now see how we can get a key via Microsoft Active Directory Authentication. Uncomment the following code if you want to use Active Directory Authentication instead of keys from the portal.\n\n\n```python\n# from azure.identity import DefaultAzureCredential\n\n# default_credential = DefaultAzureCredential()\n# token = default_credential.get_token(\"https://cognitiveservices.azure.com/.default\")\n\n# openai.api_type = 'azure_ad'\n# openai.api_key = token.token\n```\n\nA token is valid for a period of time, after which it will expire. To ensure a valid token is sent with every request, you can refresh an expiring token by hooking into requests.auth:\n\n\n```python\nimport typing\nimport time\nimport requests\nif typing.TYPE_CHECKING:\n    from azure.core.credentials import TokenCredential\n\nclass TokenRefresh(requests.auth.AuthBase):\n\n    def __init__(self, credential: \"TokenCredential\", scopes: typing.List[str]) -> None:\n        self.credential = credential\n        self.scopes = scopes\n        self.cached_token: typing.Optional[str] = None\n\n    def __call__(self, req):\n        if not self.cached_token or self.cached_token.expires_on - time.time() < 300:\n            self.cached_token = self.credential.get_token(*self.scopes)\n        req.headers[\"Authorization\"] = f\"Bearer {self.cached_token.token}\"\n        return req\n\nsession = requests.Session()\nsession.auth = TokenRefresh(default_credential, [\"https://cognitiveservices.azure.com/.default\"])\n\nopenai.requestssession = session\n```\n\n## Deployments\nIn this section we are going to create a deployment using the `gpt-3.5-turbo-instruct` model that we can then use to create completions.\n\n### Deployments: Create manually\nCreate a new deployment by going to your Resource in your portal under \"Resource Management\" -> \"Model deployments\". Select `gpt-3.5-turbo-instruct` as the model.\n\n\n```python\ndeployment_id = '' # Fill in the deployment id from the portal here\n```\n\n### Completions\nNow let's send a sample completion to the deployment.\n\n\n```python\nprompt = \"The food was delicious and the waiter\"\ncompletion = openai.Completion.create(deployment_id=deployment_id,\n                                     prompt=prompt, stop=\".\", temperature=0)\n                                \nprint(f\"{prompt}{completion['choices'][0]['text']}.\")\n```"}


created_at: 2024-07-28 18:59:25
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 0cf61f16-028b-492f-884e-db72de71c6d4
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/azure/archive/whisper.ipynb", "title": "Azure audio whisper (preview) example", "tokens": 1088, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"0cf61f16-028b-492f-884e-db72de71c6d4\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/archive/whisper.ipynb\", \"title\": \"Azure audio whisper (preview) example\", \"tokens\": 1088, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"1f3e35cb-d354-44e8-ab80-5d4638cb8dcf\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/archive/whisper.ipynb\", \"title\": \"Azure audio whisper (preview) example\", \"tokens\": 1088, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"078cb8f441b8c6d46823a1448b8a2fdac5e7dfc658867a96a545553dab72a794\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"1bccc194-2a59-44c2-b817-77ae563a4674\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"8b2df007a1af0dd6e539313308ca210e83cc154d3fbbdde619469781d7ea51dd\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 0, \"end_char_idx\": 2995, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "1f3e35cb-d354-44e8-ab80-5d4638cb8dcf", "doc_id": "1f3e35cb-d354-44e8-ab80-5d4638cb8dcf", "ref_doc_id": "1f3e35cb-d354-44e8-ab80-5d4638cb8dcf", "chroma:document": "# Azure audio whisper (preview) example\n\n> Note: There is a newer version of the openai library available. See https://github.com/openai/openai-python/discussions/742\n\nThe example shows how to use the Azure OpenAI Whisper model to transcribe audio files.\n\n## Setup\n\nFirst, we install the necessary dependencies.\n\n\n```python\n! pip install \"openai>=0.28.1,<1.0.0\"\n! pip install python-dotenv\n```\n\nNext, we'll import our libraries and configure the Python OpenAI SDK to work with the Azure OpenAI service.\n\n> Note: In this example, we configured the library to use the Azure API by setting the variables in code. For development, consider setting the environment variables instead:\n\n```\nOPENAI_API_BASE\nOPENAI_API_KEY\nOPENAI_API_TYPE\nOPENAI_API_VERSION\n```\n\n\n```python\nimport os\nimport dotenv\nimport openai\n\n\ndotenv.load_dotenv()\n```\n\n\n\n\n    True\n\n\n\n\nTo properly access the Azure OpenAI Service, we need to create the proper resources at the [Azure Portal](https://portal.azure.com) (you can check a detailed guide on how to do this in the [Microsoft Docs](https://learn.microsoft.com/en-us/azure/cognitive-services/openai/how-to/create-resource?pivots=web-portal))\n\nOnce the resource is created, the first thing we need to use is its endpoint. You can get the endpoint by looking at the *\"Keys and Endpoints\"* section under the *\"Resource Management\"* section. Having this, we will set up the SDK using this information:\n\n\n```python\nopenai.api_base = os.environ[\"OPENAI_API_BASE\"]\n\n# Min API version that supports Whisper\nopenai.api_version = \"2023-09-01-preview\"\n\n# Enter the deployment_id to use for the Whisper model\ndeployment_id = \"<deployment-id-for-your-whisper-model>\"\n```\n\n### Authentication\n\nThe Azure OpenAI service supports multiple authentication mechanisms that include API keys and Azure credentials.\n\n\n```python\n# set to True if using Azure Active Directory authentication\nuse_azure_active_directory = False\n```\n\n\n#### Authentication using API key\n\nTo set up the OpenAI SDK to use an *Azure API Key*, we need to set up the `api_type` to `azure` and set `api_key` to a key associated with your endpoint (you can find this key in *\"Keys and Endpoints\"* under *\"Resource Management\"* in the [Azure Portal](https://portal.azure.com))\n\n\n```python\nif not use_azure_active_directory:\n    openai.api_type = 'azure'\n    openai.api_key = os.environ[\"OPENAI_API_KEY\"]\n```\n\n#### Authentication using Azure Active Directory\nLet's now see how we can get a key via Microsoft Active Directory Authentication.\n\n\n```python\nfrom azure.identity import DefaultAzureCredential\n\nif use_azure_active_directory:\n    default_credential = DefaultAzureCredential()\n    token = default_credential.get_token(\"https://cognitiveservices.azure.com/.default\")\n\n    openai.api_type = 'azure_ad'\n    openai.api_key = token.token\n```\n\nA token is valid for a period of time, after which it will expire. To ensure a valid token is sent with every request, you can refresh an expiring token by hooking into requests.auth:"}


created_at: 2024-07-28 18:59:25
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 1bccc194-2a59-44c2-b817-77ae563a4674
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/azure/archive/whisper.ipynb", "title": "Azure audio whisper (preview) example", "tokens": 1088, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"1bccc194-2a59-44c2-b817-77ae563a4674\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/archive/whisper.ipynb\", \"title\": \"Azure audio whisper (preview) example\", \"tokens\": 1088, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"1f3e35cb-d354-44e8-ab80-5d4638cb8dcf\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/archive/whisper.ipynb\", \"title\": \"Azure audio whisper (preview) example\", \"tokens\": 1088, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"078cb8f441b8c6d46823a1448b8a2fdac5e7dfc658867a96a545553dab72a794\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"0cf61f16-028b-492f-884e-db72de71c6d4\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/archive/whisper.ipynb\", \"title\": \"Azure audio whisper (preview) example\", \"tokens\": 1088, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"3870cdccc5700223c1261ea70d4e16b9731f322bccfd893389515ffd7b0a707a\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 1421, \"end_char_idx\": 4768, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "1f3e35cb-d354-44e8-ab80-5d4638cb8dcf", "doc_id": "1f3e35cb-d354-44e8-ab80-5d4638cb8dcf", "ref_doc_id": "1f3e35cb-d354-44e8-ab80-5d4638cb8dcf", "chroma:document": "```python\nopenai.api_base = os.environ[\"OPENAI_API_BASE\"]\n\n# Min API version that supports Whisper\nopenai.api_version = \"2023-09-01-preview\"\n\n# Enter the deployment_id to use for the Whisper model\ndeployment_id = \"<deployment-id-for-your-whisper-model>\"\n```\n\n### Authentication\n\nThe Azure OpenAI service supports multiple authentication mechanisms that include API keys and Azure credentials.\n\n\n```python\n# set to True if using Azure Active Directory authentication\nuse_azure_active_directory = False\n```\n\n\n#### Authentication using API key\n\nTo set up the OpenAI SDK to use an *Azure API Key*, we need to set up the `api_type` to `azure` and set `api_key` to a key associated with your endpoint (you can find this key in *\"Keys and Endpoints\"* under *\"Resource Management\"* in the [Azure Portal](https://portal.azure.com))\n\n\n```python\nif not use_azure_active_directory:\n    openai.api_type = 'azure'\n    openai.api_key = os.environ[\"OPENAI_API_KEY\"]\n```\n\n#### Authentication using Azure Active Directory\nLet's now see how we can get a key via Microsoft Active Directory Authentication.\n\n\n```python\nfrom azure.identity import DefaultAzureCredential\n\nif use_azure_active_directory:\n    default_credential = DefaultAzureCredential()\n    token = default_credential.get_token(\"https://cognitiveservices.azure.com/.default\")\n\n    openai.api_type = 'azure_ad'\n    openai.api_key = token.token\n```\n\nA token is valid for a period of time, after which it will expire. To ensure a valid token is sent with every request, you can refresh an expiring token by hooking into requests.auth:\n\n\n```python\nimport typing\nimport time\nimport requests\n\nif typing.TYPE_CHECKING:\n    from azure.core.credentials import TokenCredential\n\nclass TokenRefresh(requests.auth.AuthBase):\n\n    def __init__(self, credential: \"TokenCredential\", scopes: typing.List[str]) -> None:\n        self.credential = credential\n        self.scopes = scopes\n        self.cached_token: typing.Optional[str] = None\n\n    def __call__(self, req):\n        if not self.cached_token or self.cached_token.expires_on - time.time() < 300:\n            self.cached_token = self.credential.get_token(*self.scopes)\n        req.headers[\"Authorization\"] = f\"Bearer {self.cached_token.token}\"\n        return req\n\nif use_azure_active_directory:\n    session = requests.Session()\n    session.auth = TokenRefresh(default_credential, [\"https://cognitiveservices.azure.com/.default\"])\n\n    openai.requestssession = session\n```\n\n## Audio transcription\n\nAudio transcription, or speech-to-text, is the process of converting spoken words into text. Use the `openai.Audio.transcribe` method to transcribe an audio file stream to text.\n\nYou can get sample audio files from the [Azure AI Speech SDK repository at GitHub](https://github.com/Azure-Samples/cognitive-services-speech-sdk/tree/master/sampledata/audiofiles).\n\n\n```python\n# download sample audio file\nimport requests\n\nsample_audio_url = \"https://github.com/Azure-Samples/cognitive-services-speech-sdk/raw/master/sampledata/audiofiles/wikipediaOcelot.wav\"\naudio_file = requests.get(sample_audio_url)\nwith open(\"wikipediaOcelot.wav\", \"wb\") as f:\n    f.write(audio_file.content)\n```\n\n\n```python\ntranscription = openai.Audio.transcribe(\n    file=open(\"wikipediaOcelot.wav\", \"rb\"),\n    model=\"whisper-1\",\n    deployment_id=deployment_id,\n)\nprint(transcription.text)\n```"}


created_at: 2024-07-28 18:59:25
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: b2691a99-18ce-477d-a9c9-535a61d01da5
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/azure/archive/chat.ipynb", "title": "Azure chat completions example (preview)", "tokens": 1164, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"b2691a99-18ce-477d-a9c9-535a61d01da5\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/archive/chat.ipynb\", \"title\": \"Azure chat completions example (preview)\", \"tokens\": 1164, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"62da548d-81ca-4ba8-9f64-bcdaa233131f\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/archive/chat.ipynb\", \"title\": \"Azure chat completions example (preview)\", \"tokens\": 1164, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"53d52c5d42ad01089f2f5de642fd0f7b756c50a816e31657bc1bda528b67c279\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"9735a59d-a987-467b-8f61-4e9c2cf8513b\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"f14f8583f21a13a95c52fb56c41c7e521a95329b8351eea86541c5abe5bd6488\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 0, \"end_char_idx\": 2297, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "62da548d-81ca-4ba8-9f64-bcdaa233131f", "doc_id": "62da548d-81ca-4ba8-9f64-bcdaa233131f", "ref_doc_id": "62da548d-81ca-4ba8-9f64-bcdaa233131f", "chroma:document": "# Azure chat completions example (preview)\n\n> Note: There is a newer version of the openai library available. See https://github.com/openai/openai-python/discussions/742\n\nThis example will cover chat completions using the Azure OpenAI service.\n\n## Setup\n\n\nFirst, we install the necessary dependencies.\n\n\n```python\n! pip install \"openai>=0.28.1,<1.0.0\"\n```\n\nFor the following sections to work properly we first have to setup some things. Let's start with the `api_base` and `api_version`. To find your `api_base` go to https://portal.azure.com, find your resource and then under \"Resource Management\" -> \"Keys and Endpoints\" look for the \"Endpoint\" value.\n\n\n```python\nimport os\nimport openai\n```\n\n\n```python\nopenai.api_version = '2023-05-15'\nopenai.api_base = '' # Please add your endpoint here\n```\n\nWe next have to setup the `api_type` and `api_key`. We can either get the key from the portal or we can get it through Microsoft Active Directory Authentication. Depending on this the `api_type` is either `azure` or `azure_ad`.\n\n### Setup: Portal\nLet's first look at getting the key from the portal. Go to https://portal.azure.com, find your resource and then under \"Resource Management\" -> \"Keys and Endpoints\" look for one of the \"Keys\" values.\n\n\n```python\nopenai.api_type = 'azure'\nopenai.api_key = os.environ[\"OPENAI_API_KEY\"]\n\n```\n\n> Note: In this example, we configured the library to use the Azure API by setting the variables in code. For development, consider setting the environment variables instead:\n\n```\nOPENAI_API_BASE\nOPENAI_API_KEY\nOPENAI_API_TYPE\nOPENAI_API_VERSION\n```\n\n### (Optional) Setup: Microsoft Active Directory Authentication\nLet's now see how we can get a key via Microsoft Active Directory Authentication. Uncomment the following code if you want to use Active Directory Authentication instead of keys from the portal.\n\n\n```python\n# from azure.identity import DefaultAzureCredential\n\n# default_credential = DefaultAzureCredential()\n# token = default_credential.get_token(\"https://cognitiveservices.azure.com/.default\")\n\n# openai.api_type = 'azure_ad'\n# openai.api_key = token.token\n```\n\nA token is valid for a period of time, after which it will expire. To ensure a valid token is sent with every request, you can refresh an expiring token by hooking into requests.auth:"}


created_at: 2024-07-28 18:59:25
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 9735a59d-a987-467b-8f61-4e9c2cf8513b
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/azure/archive/chat.ipynb", "title": "Azure chat completions example (preview)", "tokens": 1164, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"9735a59d-a987-467b-8f61-4e9c2cf8513b\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/archive/chat.ipynb\", \"title\": \"Azure chat completions example (preview)\", \"tokens\": 1164, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"62da548d-81ca-4ba8-9f64-bcdaa233131f\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/archive/chat.ipynb\", \"title\": \"Azure chat completions example (preview)\", \"tokens\": 1164, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"53d52c5d42ad01089f2f5de642fd0f7b756c50a816e31657bc1bda528b67c279\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"b2691a99-18ce-477d-a9c9-535a61d01da5\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/archive/chat.ipynb\", \"title\": \"Azure chat completions example (preview)\", \"tokens\": 1164, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"9390cf8dfd9d1b71b2bb4a26586404d7518df250c6946b7f8130909608c5a10b\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"1b40768d-844a-4c53-a151-64675e83119c\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"71982df42fc00c04aa021216539f95d33c33a7f0a1de6c11cec174e66e9d8a49\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 657, \"end_char_idx\": 3698, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "62da548d-81ca-4ba8-9f64-bcdaa233131f", "doc_id": "62da548d-81ca-4ba8-9f64-bcdaa233131f", "ref_doc_id": "62da548d-81ca-4ba8-9f64-bcdaa233131f", "chroma:document": "```python\nimport os\nimport openai\n```\n\n\n```python\nopenai.api_version = '2023-05-15'\nopenai.api_base = '' # Please add your endpoint here\n```\n\nWe next have to setup the `api_type` and `api_key`. We can either get the key from the portal or we can get it through Microsoft Active Directory Authentication. Depending on this the `api_type` is either `azure` or `azure_ad`.\n\n### Setup: Portal\nLet's first look at getting the key from the portal. Go to https://portal.azure.com, find your resource and then under \"Resource Management\" -> \"Keys and Endpoints\" look for one of the \"Keys\" values.\n\n\n```python\nopenai.api_type = 'azure'\nopenai.api_key = os.environ[\"OPENAI_API_KEY\"]\n\n```\n\n> Note: In this example, we configured the library to use the Azure API by setting the variables in code. For development, consider setting the environment variables instead:\n\n```\nOPENAI_API_BASE\nOPENAI_API_KEY\nOPENAI_API_TYPE\nOPENAI_API_VERSION\n```\n\n### (Optional) Setup: Microsoft Active Directory Authentication\nLet's now see how we can get a key via Microsoft Active Directory Authentication. Uncomment the following code if you want to use Active Directory Authentication instead of keys from the portal.\n\n\n```python\n# from azure.identity import DefaultAzureCredential\n\n# default_credential = DefaultAzureCredential()\n# token = default_credential.get_token(\"https://cognitiveservices.azure.com/.default\")\n\n# openai.api_type = 'azure_ad'\n# openai.api_key = token.token\n```\n\nA token is valid for a period of time, after which it will expire. To ensure a valid token is sent with every request, you can refresh an expiring token by hooking into requests.auth:\n\n\n```python\nimport typing\nimport time\nimport requests\nif typing.TYPE_CHECKING:\n    from azure.core.credentials import TokenCredential\n\nclass TokenRefresh(requests.auth.AuthBase):\n\n    def __init__(self, credential: \"TokenCredential\", scopes: typing.List[str]) -> None:\n        self.credential = credential\n        self.scopes = scopes\n        self.cached_token: typing.Optional[str] = None\n\n    def __call__(self, req):\n        if not self.cached_token or self.cached_token.expires_on - time.time() < 300:\n            self.cached_token = self.credential.get_token(*self.scopes)\n        req.headers[\"Authorization\"] = f\"Bearer {self.cached_token.token}\"\n        return req\n\nsession = requests.Session()\nsession.auth = TokenRefresh(default_credential, [\"https://cognitiveservices.azure.com/.default\"])\n\nopenai.requestssession = session\n```\n\n## Deployments\nIn this section we are going to create a deployment using the `gpt-35-turbo` model that we can then use to create chat completions.\n\n### Deployments: Create manually\nLet's create a deployment using the `gpt-35-turbo` model. Go to https://portal.azure.com, find your resource and then under \"Resource Management\" -> \"Model deployments\" create a new `gpt-35-turbo` deployment. \n\n\n```python\ndeployment_id = '' # Fill in the deployment id from the portal here\n```\n\n### Create chat completion\nNow let's send a sample chat completion to the deployment."}


created_at: 2024-07-28 18:59:25
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 1b40768d-844a-4c53-a151-64675e83119c
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/azure/archive/chat.ipynb", "title": "Azure chat completions example (preview)", "tokens": 1164, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"1b40768d-844a-4c53-a151-64675e83119c\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/archive/chat.ipynb\", \"title\": \"Azure chat completions example (preview)\", \"tokens\": 1164, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"62da548d-81ca-4ba8-9f64-bcdaa233131f\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/archive/chat.ipynb\", \"title\": \"Azure chat completions example (preview)\", \"tokens\": 1164, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"53d52c5d42ad01089f2f5de642fd0f7b756c50a816e31657bc1bda528b67c279\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"9735a59d-a987-467b-8f61-4e9c2cf8513b\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/archive/chat.ipynb\", \"title\": \"Azure chat completions example (preview)\", \"tokens\": 1164, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"e731cee08237a51bb35861f2bdd32560b1fe2b04343cdc459acc4fdfb5e852ab\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 2300, \"end_char_idx\": 4942, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "62da548d-81ca-4ba8-9f64-bcdaa233131f", "doc_id": "62da548d-81ca-4ba8-9f64-bcdaa233131f", "ref_doc_id": "62da548d-81ca-4ba8-9f64-bcdaa233131f", "chroma:document": "```python\nimport typing\nimport time\nimport requests\nif typing.TYPE_CHECKING:\n    from azure.core.credentials import TokenCredential\n\nclass TokenRefresh(requests.auth.AuthBase):\n\n    def __init__(self, credential: \"TokenCredential\", scopes: typing.List[str]) -> None:\n        self.credential = credential\n        self.scopes = scopes\n        self.cached_token: typing.Optional[str] = None\n\n    def __call__(self, req):\n        if not self.cached_token or self.cached_token.expires_on - time.time() < 300:\n            self.cached_token = self.credential.get_token(*self.scopes)\n        req.headers[\"Authorization\"] = f\"Bearer {self.cached_token.token}\"\n        return req\n\nsession = requests.Session()\nsession.auth = TokenRefresh(default_credential, [\"https://cognitiveservices.azure.com/.default\"])\n\nopenai.requestssession = session\n```\n\n## Deployments\nIn this section we are going to create a deployment using the `gpt-35-turbo` model that we can then use to create chat completions.\n\n### Deployments: Create manually\nLet's create a deployment using the `gpt-35-turbo` model. Go to https://portal.azure.com, find your resource and then under \"Resource Management\" -> \"Model deployments\" create a new `gpt-35-turbo` deployment. \n\n\n```python\ndeployment_id = '' # Fill in the deployment id from the portal here\n```\n\n### Create chat completion\nNow let's send a sample chat completion to the deployment.\n\n\n```python\n# For all possible arguments see https://platform.openai.com/docs/api-reference/chat-completions/create\nresponse = openai.ChatCompletion.create(\n    deployment_id=deployment_id,\n    messages=[\n        {\"role\": \"system\", \"content\": \"You are a helpful assistant.\"},\n        {\"role\": \"user\", \"content\": \"Knock knock.\"},\n        {\"role\": \"assistant\", \"content\": \"Who's there?\"},\n        {\"role\": \"user\", \"content\": \"Orange.\"},\n    ],\n    temperature=0,\n)\n\nprint(f\"{response.choices[0].message.role}: {response.choices[0].message.content}\")\n```\n\nWe can also stream the response.\n\n\n\n```python\nresponse = openai.ChatCompletion.create(\n    deployment_id=deployment_id,\n    messages=[\n        {\"role\": \"system\", \"content\": \"You are a helpful assistant.\"},\n        {\"role\": \"user\", \"content\": \"Knock knock.\"},\n        {\"role\": \"assistant\", \"content\": \"Who's there?\"},\n        {\"role\": \"user\", \"content\": \"Orange.\"},\n    ],\n    temperature=0,\n    stream=True\n)\n\nfor chunk in response:\n    if len(chunk.choices) > 0:\n        delta = chunk.choices[0].delta\n\n        if \"role\" in delta.keys():\n            print(delta.role + \": \", end=\"\", flush=True)\n        if \"content\" in delta.keys():\n            print(delta.content, end=\"\", flush=True)\n```"}


created_at: 2024-07-28 18:59:25
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: f6064cca-e1fb-4943-b48e-b4166eecb187
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/azure/archive/embeddings.ipynb", "title": "Azure embeddings example", "tokens": 1015, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"f6064cca-e1fb-4943-b48e-b4166eecb187\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/archive/embeddings.ipynb\", \"title\": \"Azure embeddings example\", \"tokens\": 1015, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"bd394da3-f031-44a1-a6a2-6f261c4a2b45\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/archive/embeddings.ipynb\", \"title\": \"Azure embeddings example\", \"tokens\": 1015, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"b223a2145303566d1eca6e5926969569973a4d484a5cb6d353db5ef86daaf1b9\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"c929add6-b65e-47be-a490-8941c95ddeea\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"68f65e56aa830071d7db7ff48c1e8357be8bb55182030057d900da43cca765ce\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 0, \"end_char_idx\": 2258, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "bd394da3-f031-44a1-a6a2-6f261c4a2b45", "doc_id": "bd394da3-f031-44a1-a6a2-6f261c4a2b45", "ref_doc_id": "bd394da3-f031-44a1-a6a2-6f261c4a2b45", "chroma:document": "# Azure embeddings example\n\n> Note: There is a newer version of the openai library available. See https://github.com/openai/openai-python/discussions/742\n\nThis example will cover embeddings using the Azure OpenAI service.\n\n## Setup\n\nFirst, we install the necessary dependencies.\n\n! pip install \"openai>=0.28.1,<1.0.0\"\n\nFor the following sections to work properly we first have to setup some things. Let's start with the `api_base` and `api_version`. To find your `api_base` go to https://portal.azure.com, find your resource and then under \"Resource Management\" -> \"Keys and Endpoints\" look for the \"Endpoint\" value.\n\n\n```python\nimport os\nimport openai\n```\n\n\n```python\nopenai.api_version = '2023-05-15'\nopenai.api_base = '' # Please add your endpoint here\n```\n\nWe next have to setup the `api_type` and `api_key`. We can either get the key from the portal or we can get it through Microsoft Active Directory Authentication. Depending on this the `api_type` is either `azure` or `azure_ad`.\n\n### Setup: Portal\nLet's first look at getting the key from the portal. Go to https://portal.azure.com, find your resource and then under \"Resource Management\" -> \"Keys and Endpoints\" look for one of the \"Keys\" values.\n\n\n```python\nopenai.api_type = 'azure'\nopenai.api_key = os.environ[\"OPENAI_API_KEY\"]\n```\n\n> Note: In this example, we configured the library to use the Azure API by setting the variables in code. For development, consider setting the environment variables instead:\n\n```\nOPENAI_API_BASE\nOPENAI_API_KEY\nOPENAI_API_TYPE\nOPENAI_API_VERSION\n```\n\n### (Optional) Setup: Microsoft Active Directory Authentication\nLet's now see how we can get a key via Microsoft Active Directory Authentication. Uncomment the following code if you want to use Active Directory Authentication instead of keys from the portal.\n\n\n```python\n# from azure.identity import DefaultAzureCredential\n\n# default_credential = DefaultAzureCredential()\n# token = default_credential.get_token(\"https://cognitiveservices.azure.com/.default\")\n\n# openai.api_type = 'azure_ad'\n# openai.api_key = token.token\n```\n\nA token is valid for a period of time, after which it will expire. To ensure a valid token is sent with every request, you can refresh an expiring token by hooking into requests.auth:"}


created_at: 2024-07-28 18:59:25
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: c929add6-b65e-47be-a490-8941c95ddeea
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/azure/archive/embeddings.ipynb", "title": "Azure embeddings example", "tokens": 1015, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"c929add6-b65e-47be-a490-8941c95ddeea\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/archive/embeddings.ipynb\", \"title\": \"Azure embeddings example\", \"tokens\": 1015, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"bd394da3-f031-44a1-a6a2-6f261c4a2b45\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/archive/embeddings.ipynb\", \"title\": \"Azure embeddings example\", \"tokens\": 1015, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"b223a2145303566d1eca6e5926969569973a4d484a5cb6d353db5ef86daaf1b9\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"f6064cca-e1fb-4943-b48e-b4166eecb187\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/archive/embeddings.ipynb\", \"title\": \"Azure embeddings example\", \"tokens\": 1015, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"892562f3ac8cee006d5aed959f18c1a7614114cc997735862e96bc9b2c316518\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"7ebf5c81-50d6-4744-80a6-73f047e3e4ed\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"8d03c1d6529f6d46ea9697dae7a7b27905b44ee829f649897e786f8ceac5f4bd\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 619, \"end_char_idx\": 3673, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "bd394da3-f031-44a1-a6a2-6f261c4a2b45", "doc_id": "bd394da3-f031-44a1-a6a2-6f261c4a2b45", "ref_doc_id": "bd394da3-f031-44a1-a6a2-6f261c4a2b45", "chroma:document": "```python\nimport os\nimport openai\n```\n\n\n```python\nopenai.api_version = '2023-05-15'\nopenai.api_base = '' # Please add your endpoint here\n```\n\nWe next have to setup the `api_type` and `api_key`. We can either get the key from the portal or we can get it through Microsoft Active Directory Authentication. Depending on this the `api_type` is either `azure` or `azure_ad`.\n\n### Setup: Portal\nLet's first look at getting the key from the portal. Go to https://portal.azure.com, find your resource and then under \"Resource Management\" -> \"Keys and Endpoints\" look for one of the \"Keys\" values.\n\n\n```python\nopenai.api_type = 'azure'\nopenai.api_key = os.environ[\"OPENAI_API_KEY\"]\n```\n\n> Note: In this example, we configured the library to use the Azure API by setting the variables in code. For development, consider setting the environment variables instead:\n\n```\nOPENAI_API_BASE\nOPENAI_API_KEY\nOPENAI_API_TYPE\nOPENAI_API_VERSION\n```\n\n### (Optional) Setup: Microsoft Active Directory Authentication\nLet's now see how we can get a key via Microsoft Active Directory Authentication. Uncomment the following code if you want to use Active Directory Authentication instead of keys from the portal.\n\n\n```python\n# from azure.identity import DefaultAzureCredential\n\n# default_credential = DefaultAzureCredential()\n# token = default_credential.get_token(\"https://cognitiveservices.azure.com/.default\")\n\n# openai.api_type = 'azure_ad'\n# openai.api_key = token.token\n```\n\nA token is valid for a period of time, after which it will expire. To ensure a valid token is sent with every request, you can refresh an expiring token by hooking into requests.auth:\n\n\n```python\nimport typing\nimport time\nimport requests\nif typing.TYPE_CHECKING:\n    from azure.core.credentials import TokenCredential\n\nclass TokenRefresh(requests.auth.AuthBase):\n\n    def __init__(self, credential: \"TokenCredential\", scopes: typing.List[str]) -> None:\n        self.credential = credential\n        self.scopes = scopes\n        self.cached_token: typing.Optional[str] = None\n\n    def __call__(self, req):\n        if not self.cached_token or self.cached_token.expires_on - time.time() < 300:\n            self.cached_token = self.credential.get_token(*self.scopes)\n        req.headers[\"Authorization\"] = f\"Bearer {self.cached_token.token}\"\n        return req\n\nsession = requests.Session()\nsession.auth = TokenRefresh(default_credential, [\"https://cognitiveservices.azure.com/.default\"])\n\nopenai.requestssession = session\n```\n\n## Deployments\nIn this section we are going to create a deployment that we can use to create embeddings.\n\n### Deployments: Create manually\nLet's create a deployment using the `text-similarity-curie-001` model. Create a new deployment by going to your Resource in your portal under \"Resource Management\" -> \"Model deployments\".\n\n\n```python\ndeployment_id = '' # Fill in the deployment id from the portal here\n```\n\n### Deployments: Listing\nNow because creating a new deployment takes a long time, let's look in the subscription for an already finished deployment that succeeded."}


created_at: 2024-07-28 18:59:25
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 7ebf5c81-50d6-4744-80a6-73f047e3e4ed
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/azure/archive/embeddings.ipynb", "title": "Azure embeddings example", "tokens": 1015, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"7ebf5c81-50d6-4744-80a6-73f047e3e4ed\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/archive/embeddings.ipynb\", \"title\": \"Azure embeddings example\", \"tokens\": 1015, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"bd394da3-f031-44a1-a6a2-6f261c4a2b45\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/archive/embeddings.ipynb\", \"title\": \"Azure embeddings example\", \"tokens\": 1015, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"b223a2145303566d1eca6e5926969569973a4d484a5cb6d353db5ef86daaf1b9\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"c929add6-b65e-47be-a490-8941c95ddeea\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/archive/embeddings.ipynb\", \"title\": \"Azure embeddings example\", \"tokens\": 1015, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"3ffb11a851014719a36478fbaed07e49eb0709154f35ec497d1e30645bbc0907\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 2261, \"end_char_idx\": 4573, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "bd394da3-f031-44a1-a6a2-6f261c4a2b45", "doc_id": "bd394da3-f031-44a1-a6a2-6f261c4a2b45", "ref_doc_id": "bd394da3-f031-44a1-a6a2-6f261c4a2b45", "chroma:document": "```python\nimport typing\nimport time\nimport requests\nif typing.TYPE_CHECKING:\n    from azure.core.credentials import TokenCredential\n\nclass TokenRefresh(requests.auth.AuthBase):\n\n    def __init__(self, credential: \"TokenCredential\", scopes: typing.List[str]) -> None:\n        self.credential = credential\n        self.scopes = scopes\n        self.cached_token: typing.Optional[str] = None\n\n    def __call__(self, req):\n        if not self.cached_token or self.cached_token.expires_on - time.time() < 300:\n            self.cached_token = self.credential.get_token(*self.scopes)\n        req.headers[\"Authorization\"] = f\"Bearer {self.cached_token.token}\"\n        return req\n\nsession = requests.Session()\nsession.auth = TokenRefresh(default_credential, [\"https://cognitiveservices.azure.com/.default\"])\n\nopenai.requestssession = session\n```\n\n## Deployments\nIn this section we are going to create a deployment that we can use to create embeddings.\n\n### Deployments: Create manually\nLet's create a deployment using the `text-similarity-curie-001` model. Create a new deployment by going to your Resource in your portal under \"Resource Management\" -> \"Model deployments\".\n\n\n```python\ndeployment_id = '' # Fill in the deployment id from the portal here\n```\n\n### Deployments: Listing\nNow because creating a new deployment takes a long time, let's look in the subscription for an already finished deployment that succeeded.\n\n\n```python\nprint('While deployment running, selecting a completed one that supports embeddings.')\ndeployment_id = None\nresult = openai.Deployment.list()\nfor deployment in result.data:\n    if deployment[\"status\"] != \"succeeded\":\n        continue\n    \n    model = openai.Model.retrieve(deployment[\"model\"])\n    if model[\"capabilities\"][\"embeddings\"] != True:\n        continue\n    \n    deployment_id = deployment[\"id\"]\n    break\n\nif not deployment_id:\n    print('No deployment with status: succeeded found.')\nelse:\n    print(f'Found a succeeded deployment that supports embeddings with id: {deployment_id}.')\n```\n\n### Embeddings\nNow let's send a sample embedding to the deployment.\n\n\n```python\nembeddings = openai.Embedding.create(deployment_id=deployment_id,\n                                     input=\"The food was delicious and the waiter...\")\n                                \nprint(embeddings)\n```"}


created_at: 2024-07-28 18:59:25
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 59087eb1-b456-4fc6-804e-a153f55b7017
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/azure/archive/DALL-E.ipynb", "title": "Azure DALL\u00b7E image generation example", "tokens": 1190, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"59087eb1-b456-4fc6-804e-a153f55b7017\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/archive/DALL-E.ipynb\", \"title\": \"Azure DALL\\u00b7E image generation example\", \"tokens\": 1190, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"1e2fd563-4a17-4258-9fcd-279cdf2b07f8\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/archive/DALL-E.ipynb\", \"title\": \"Azure DALL\\u00b7E image generation example\", \"tokens\": 1190, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"c227d1babd0c3e54858abf278e8b790d41d1e58013d4c3a966f18e50cf11d353\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"2031cd97-271f-4424-b93e-32c314786192\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"5e45390f26c442bab7bacf8f5d2204a9119c37f08d1a9451ec9acb491ec0ae66\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 0, \"end_char_idx\": 2905, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "1e2fd563-4a17-4258-9fcd-279cdf2b07f8", "doc_id": "1e2fd563-4a17-4258-9fcd-279cdf2b07f8", "ref_doc_id": "1e2fd563-4a17-4258-9fcd-279cdf2b07f8", "chroma:document": "# Azure DALL\u00b7E image generation example\n\n> Note: There is a newer version of the openai library available. See https://github.com/openai/openai-python/discussions/742\n\nThis notebook shows how to generate images with the Azure OpenAI service.\n\n## Setup\n\nFirst, we install the necessary dependencies.\n\n\n```python\n! pip install \"openai>=0.28.1,<1.0.0\"\n# We need requests to retrieve the generated image\n! pip install requests\n# We use Pillow to display the generated image\n! pip install pillow \n# (Optional) If you want to use Microsoft Active Directory\n! pip install azure-identity\n```\n\n\n```python\nimport os\nimport openai\n```\n\n\nAdditionally, to properly access the Azure OpenAI Service, we need to create the proper resources at the [Azure Portal](https://portal.azure.com) (you can check a detailed guide on how to do this in the [Microsoft Docs](https://learn.microsoft.com/en-us/azure/cognitive-services/openai/how-to/create-resource?pivots=web-portal))\n\nOnce the resource is created, the first thing we need to use is its endpoint. You can get the endpoint by looking at the *\"Keys and Endpoints\"* section under the *\"Resource Management\"* section. Having this, we will set up the SDK using this information:\n\n\n```python\nopenai.api_base = '' # Add your endpoint here\n\n# At the moment DALL\u00b7E is only supported by the 2023-06-01-preview API version\nopenai.api_version = '2023-06-01-preview'\n```\n\n### Authentication\n\nThe Azure OpenAI service supports multiple authentication mechanisms that include API keys and Azure credentials.\n\n\n```python\nuse_azure_active_directory = False\n```\n\n\n#### Authentication using API key\n\nTo set up the OpenAI SDK to use an *Azure API Key*, we need to set up the `api_type` to `azure` and set `api_key` to a key associated with your endpoint (you can find this key in *\"Keys and Endpoints\"* under *\"Resource Management\"* in the [Azure Portal](https://portal.azure.com))\n\n\n```python\nif not use_azure_active_directory:\n    openai.api_type = 'azure'\n    openai.api_key = os.environ[\"OPENAI_API_KEY\"]\n```\n\n> Note: In this example, we configured the library to use the Azure API by setting the variables in code. For development, consider setting the environment variables instead:\n\n```\nOPENAI_API_BASE\nOPENAI_API_KEY\nOPENAI_API_TYPE\nOPENAI_API_VERSION\n```\n\n#### Authentication using Microsoft Active Directory\nLet's now see how we can get a key via Microsoft Active Directory Authentication.\n\n\n```python\nfrom azure.identity import DefaultAzureCredential\n\nif use_azure_active_directory:\n    default_credential = DefaultAzureCredential()\n    token = default_credential.get_token(\"https://cognitiveservices.azure.com/.default\")\n\n    openai.api_type = 'azure_ad'\n    openai.api_key = token.token\n```\n\nA token is valid for a period of time, after which it will expire. To ensure a valid token is sent with every request, you can refresh an expiring token by hooking into requests.auth:"}


created_at: 2024-07-28 18:59:25
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: 2031cd97-271f-4424-b93e-32c314786192
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/azure/archive/DALL-E.ipynb", "title": "Azure DALL\u00b7E image generation example", "tokens": 1190, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"2031cd97-271f-4424-b93e-32c314786192\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/archive/DALL-E.ipynb\", \"title\": \"Azure DALL\\u00b7E image generation example\", \"tokens\": 1190, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"1e2fd563-4a17-4258-9fcd-279cdf2b07f8\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/archive/DALL-E.ipynb\", \"title\": \"Azure DALL\\u00b7E image generation example\", \"tokens\": 1190, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"c227d1babd0c3e54858abf278e8b790d41d1e58013d4c3a966f18e50cf11d353\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"59087eb1-b456-4fc6-804e-a153f55b7017\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/archive/DALL-E.ipynb\", \"title\": \"Azure DALL\\u00b7E image generation example\", \"tokens\": 1190, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"c28da1edf18cd60f556f74aa40cfd7de4dcf94a1851a4f9a6eaa41a7ff266673\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"e9dc658d-8306-41bd-b4a2-eebe49c4bc1e\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"b8fa68b36d32c8a9eb5599bd4bd3bebcef5ce7b22e8cdfbb005106e0f6e5f841\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 1213, \"end_char_idx\": 4346, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "1e2fd563-4a17-4258-9fcd-279cdf2b07f8", "doc_id": "1e2fd563-4a17-4258-9fcd-279cdf2b07f8", "ref_doc_id": "1e2fd563-4a17-4258-9fcd-279cdf2b07f8", "chroma:document": "```python\nopenai.api_base = '' # Add your endpoint here\n\n# At the moment DALL\u00b7E is only supported by the 2023-06-01-preview API version\nopenai.api_version = '2023-06-01-preview'\n```\n\n### Authentication\n\nThe Azure OpenAI service supports multiple authentication mechanisms that include API keys and Azure credentials.\n\n\n```python\nuse_azure_active_directory = False\n```\n\n\n#### Authentication using API key\n\nTo set up the OpenAI SDK to use an *Azure API Key*, we need to set up the `api_type` to `azure` and set `api_key` to a key associated with your endpoint (you can find this key in *\"Keys and Endpoints\"* under *\"Resource Management\"* in the [Azure Portal](https://portal.azure.com))\n\n\n```python\nif not use_azure_active_directory:\n    openai.api_type = 'azure'\n    openai.api_key = os.environ[\"OPENAI_API_KEY\"]\n```\n\n> Note: In this example, we configured the library to use the Azure API by setting the variables in code. For development, consider setting the environment variables instead:\n\n```\nOPENAI_API_BASE\nOPENAI_API_KEY\nOPENAI_API_TYPE\nOPENAI_API_VERSION\n```\n\n#### Authentication using Microsoft Active Directory\nLet's now see how we can get a key via Microsoft Active Directory Authentication.\n\n\n```python\nfrom azure.identity import DefaultAzureCredential\n\nif use_azure_active_directory:\n    default_credential = DefaultAzureCredential()\n    token = default_credential.get_token(\"https://cognitiveservices.azure.com/.default\")\n\n    openai.api_type = 'azure_ad'\n    openai.api_key = token.token\n```\n\nA token is valid for a period of time, after which it will expire. To ensure a valid token is sent with every request, you can refresh an expiring token by hooking into requests.auth:\n\n\n```python\nimport typing\nimport time\nimport requests\n\nif typing.TYPE_CHECKING:\n    from azure.core.credentials import TokenCredential\n\nclass TokenRefresh(requests.auth.AuthBase):\n\n    def __init__(self, credential: \"TokenCredential\", scopes: typing.List[str]) -> None:\n        self.credential = credential\n        self.scopes = scopes\n        self.cached_token: typing.Optional[str] = None\n\n    def __call__(self, req):\n        if not self.cached_token or self.cached_token.expires_on - time.time() < 300:\n            self.cached_token = self.credential.get_token(*self.scopes)\n        req.headers[\"Authorization\"] = f\"Bearer {self.cached_token.token}\"\n        return req\n\nif use_azure_active_directory:\n    session = requests.Session()\n    session.auth = TokenRefresh(default_credential, [\"https://cognitiveservices.azure.com/.default\"])\n\n    openai.requestssession = session\n```\n\n## Generations\n\nWith setup and authentication complete, you can now generate images on the Azure OpenAI service and retrieve them from the returned URLs.\n\n#### 1. Generate the images\n\nThe first step in this process is to actually generate the images:\n\n\n```python\ngeneration_response = openai.Image.create(\n    prompt='A cyberpunk monkey hacker dreaming of a beautiful bunch of bananas, digital art',\n    size='1024x1024',\n    n=2\n)\n\nprint(generation_response)\n```\n\nHaving the response from the `Image.create` call, we download from the URL using `requests`."}


created_at: 2024-07-28 18:59:25
topic: persistent://default/default/4bfc3c11-fb71-4cc9-8c12-01ed076a0e01
id: e9dc658d-8306-41bd-b4a2-eebe49c4bc1e
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/azure/archive/DALL-E.ipynb", "title": "Azure DALL\u00b7E image generation example", "tokens": 1190, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"e9dc658d-8306-41bd-b4a2-eebe49c4bc1e\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/archive/DALL-E.ipynb\", \"title\": \"Azure DALL\\u00b7E image generation example\", \"tokens\": 1190, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"excluded_embed_metadata_keys\": [\"url\", \"tokens\", \"retrieve_doc\", \"source\"], \"excluded_llm_metadata_keys\": [\"title\", \"tokens\", \"retrieve_doc\", \"source\"], \"relationships\": {\"1\": {\"node_id\": \"1e2fd563-4a17-4258-9fcd-279cdf2b07f8\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/archive/DALL-E.ipynb\", \"title\": \"Azure DALL\\u00b7E image generation example\", \"tokens\": 1190, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"c227d1babd0c3e54858abf278e8b790d41d1e58013d4c3a966f18e50cf11d353\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"2031cd97-271f-4424-b93e-32c314786192\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/azure/archive/DALL-E.ipynb\", \"title\": \"Azure DALL\\u00b7E image generation example\", \"tokens\": 1190, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"0f15e1d49a2166caaba8a0f91be35877bb183f69ec1915783fc53d3c7dc4b722\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 2908, \"end_char_idx\": 5186, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "1e2fd563-4a17-4258-9fcd-279cdf2b07f8", "doc_id": "1e2fd563-4a17-4258-9fcd-279cdf2b07f8", "ref_doc_id": "1e2fd563-4a17-4258-9fcd-279cdf2b07f8", "chroma:document": "```python\nimport typing\nimport time\nimport requests\n\nif typing.TYPE_CHECKING:\n    from azure.core.credentials import TokenCredential\n\nclass TokenRefresh(requests.auth.AuthBase):\n\n    def __init__(self, credential: \"TokenCredential\", scopes: typing.List[str]) -> None:\n        self.credential = credential\n        self.scopes = scopes\n        self.cached_token: typing.Optional[str] = None\n\n    def __call__(self, req):\n        if not self.cached_token or self.cached_token.expires_on - time.time() < 300:\n            self.cached_token = self.credential.get_token(*self.scopes)\n        req.headers[\"Authorization\"] = f\"Bearer {self.cached_token.token}\"\n        return req\n\nif use_azure_active_directory:\n    session = requests.Session()\n    session.auth = TokenRefresh(default_credential, [\"https://cognitiveservices.azure.com/.default\"])\n\n    openai.requestssession = session\n```\n\n## Generations\n\nWith setup and authentication complete, you can now generate images on the Azure OpenAI service and retrieve them from the returned URLs.\n\n#### 1. Generate the images\n\nThe first step in this process is to actually generate the images:\n\n\n```python\ngeneration_response = openai.Image.create(\n    prompt='A cyberpunk monkey hacker dreaming of a beautiful bunch of bananas, digital art',\n    size='1024x1024',\n    n=2\n)\n\nprint(generation_response)\n```\n\nHaving the response from the `Image.create` call, we download from the URL using `requests`.\n\n\n```python\nimport os\nimport requests\n\n# First a little setup\nimage_dir = os.path.join(os.curdir, 'images')\n# If the directory doesn't exist, create it\nif not os.path.isdir(image_dir):\n    os.mkdir(image_dir)\n\n# With the directory in place, we can initialize the image path (note that filetype should be png)\nimage_path = os.path.join(image_dir, 'generated_image.png')\n\n# Now we can retrieve the generated image\nimage_url = generation_response[\"data\"][0][\"url\"]  # extract image URL from response\ngenerated_image = requests.get(image_url).content  # download the image\nwith open(image_path, \"wb\") as image_file:\n    image_file.write(generated_image)\n```\n\nWith the image downloaded, we use the [Pillow](https://pypi.org/project/Pillow/) library to open and display it:\n\n\n```python\nfrom PIL import Image \n\ndisplay(Image.open(image_path))\n```"}


