# embeddings_queue

created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 814e8160-7045-4570-937c-07fb489ff94c
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/cassandra_astradb/Philosophical_Quotes_cassIO.ipynb", "title": "Philosophy with Vector Embeddings, OpenAI and Cassandra / Astra DB through CQL", "tokens": 6051, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"814e8160-7045-4570-937c-07fb489ff94c\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/cassandra_astradb/Philosophical_Quotes_cassIO.ipynb\", \"title\": \"Philosophy with Vector Embeddings, OpenAI and Cassandra / Astra DB through CQL\", \"tokens\": 6051, \"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\": \"8938aaa0-39b6-4913-afa3-644dfcdc84cb\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/cassandra_astradb/Philosophical_Quotes_cassIO.ipynb\", \"title\": \"Philosophy with Vector Embeddings, OpenAI and Cassandra / Astra DB through CQL\", \"tokens\": 6051, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"723f825cd19bd5d01794b8111cf19db861b8b27b9247f5207316ec1dc1f05a13\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"917f5c67-4765-4236-bbd1-e5c2895d11e4\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/cassandra_astradb/Philosophical_Quotes_cassIO.ipynb\", \"title\": \"Philosophy with Vector Embeddings, OpenAI and Cassandra / Astra DB through CQL\", \"tokens\": 6051, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"929c6445853f9b9a45ff8952594bdeb3f34dd71b9215ba86808e68420c84d247\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"32d137b6-abde-41db-af87-1e78c893e016\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"89d48b7eaa67e5c817c7687ebd38cd8cde2bfd848b371004be805ff78708f4cd\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 12917, \"end_char_idx\": 16194, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "8938aaa0-39b6-4913-afa3-644dfcdc84cb", "doc_id": "8938aaa0-39b6-4913-afa3-644dfcdc84cb", "ref_doc_id": "8938aaa0-39b6-4913-afa3-644dfcdc84cb", "chroma:document": "Search constrained to a tag (out of those saved earlier with the quotes):\n\n\n```python\nfind_quote_and_author(\"We struggle all our life for nothing\", 2, tags=[\"politics\"])\n```\n\n\n\n\n    [('Mankind will never see an end of trouble until lovers of wisdom come to hold political power, or the holders of power become lovers of wisdom',\n      'plato'),\n     ('Everything the State says is a lie, and everything it has it has stolen.',\n      'nietzsche')]\n\n\n\n### Cutting out irrelevant results\n\nThe vector similarity search generally returns the vectors that are closest to the query, even if that means results that might be somewhat irrelevant if there's nothing better.\n\nTo keep this issue under control, you can get the actual \"distance\" between the query and each result, and then set a cutoff on it, effectively discarding results that are beyond that threshold.\nTuning this threshold correctly is not an easy problem: here, we'll just show you the way.\n\nTo get a feeling on how this works, try the following query and play with the choice of quote and threshold to compare the results:\n\n_Note (for the mathematically inclined): this \"distance\" is exactly the cosine similarity between the vectors, i.e. the scalar product divided by the product of the norms of the two vectors. As such, it is a number ranging from -1 to +1, where -1 is for exactly opposite-facing vectors and +1 for identically-oriented vectors. Elsewhere (e.g. in the \"CQL\" counterpart of this demo) you would get a rescaling of this quantity to fit the [0, 1] interval, which means the resulting numerical values and adequate thresholds there are transformed accordingly._\n\n\n```python\nquote = \"Animals are our equals.\"\n# quote = \"Be good.\"\n# quote = \"This teapot is strange.\"\n\nmetric_threshold = 0.84\n\nquote_vector = client.embeddings.create(\n    input=[quote],\n    model=embedding_model_name,\n).data[0].embedding\n\nresults = list(v_table.metric_ann_search(\n    quote_vector,\n    n=8,\n    metric=\"cos\",\n    metric_threshold=metric_threshold,\n))\n\nprint(f\"{len(results)} quotes within the threshold:\")\nfor idx, result in enumerate(results):\n    print(f\"    {idx}. [distance={result['distance']:.3f}] \\\"{result['body_blob'][:70]}...\\\"\")\n```\n\n    3 quotes within the threshold:\n        0. [distance=0.855] \"The assumption that animals are without rights, and the illusion that ...\"\n        1. [distance=0.843] \"Animals are in possession of themselves; their soul is in possession o...\"\n        2. [distance=0.841] \"At his best, man is the noblest of all animals; separated from law and...\"\n\n\n## Use case 2: **quote generator**\n\nFor this task you need another component from OpenAI, namely an LLM to generate the quote for us (based on input obtained by querying the Vector Store).\n\nYou also need a template for the prompt that will be filled for the generate-quote LLM completion task.\n\n\n```python\ncompletion_model_name = \"gpt-3.5-turbo\"\n\ngeneration_prompt_template = \"\"\"\"Generate a single short philosophical quote on the given topic,\nsimilar in spirit and form to the provided actual example quotes.\nDo not exceed 20-30 words in your quote.\n\nREFERENCE TOPIC: \"{topic}\"\n\nACTUAL EXAMPLES:\n{examples}\n\"\"\"\n```\n\nLike for search, this functionality is best wrapped into a handy function (which internally uses search):"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 32d137b6-abde-41db-af87-1e78c893e016
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/cassandra_astradb/Philosophical_Quotes_cassIO.ipynb", "title": "Philosophy with Vector Embeddings, OpenAI and Cassandra / Astra DB through CQL", "tokens": 6051, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"32d137b6-abde-41db-af87-1e78c893e016\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/cassandra_astradb/Philosophical_Quotes_cassIO.ipynb\", \"title\": \"Philosophy with Vector Embeddings, OpenAI and Cassandra / Astra DB through CQL\", \"tokens\": 6051, \"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\": \"8938aaa0-39b6-4913-afa3-644dfcdc84cb\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/cassandra_astradb/Philosophical_Quotes_cassIO.ipynb\", \"title\": \"Philosophy with Vector Embeddings, OpenAI and Cassandra / Astra DB through CQL\", \"tokens\": 6051, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"723f825cd19bd5d01794b8111cf19db861b8b27b9247f5207316ec1dc1f05a13\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"814e8160-7045-4570-937c-07fb489ff94c\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/cassandra_astradb/Philosophical_Quotes_cassIO.ipynb\", \"title\": \"Philosophy with Vector Embeddings, OpenAI and Cassandra / Astra DB through CQL\", \"tokens\": 6051, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"1fd26059dcf9c67dbcdafec81d0314d17a32a98c0e3075f88520704673872abc\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"7c5f12e6-6bd5-4f7a-8137-c7b661480300\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"c188a6e724b939f89487e1ae7ca4bf7a3a9f415d819c43a28f76446a1fb980d7\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 14560, \"end_char_idx\": 17411, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "8938aaa0-39b6-4913-afa3-644dfcdc84cb", "doc_id": "8938aaa0-39b6-4913-afa3-644dfcdc84cb", "ref_doc_id": "8938aaa0-39b6-4913-afa3-644dfcdc84cb", "chroma:document": "```python\nquote = \"Animals are our equals.\"\n# quote = \"Be good.\"\n# quote = \"This teapot is strange.\"\n\nmetric_threshold = 0.84\n\nquote_vector = client.embeddings.create(\n    input=[quote],\n    model=embedding_model_name,\n).data[0].embedding\n\nresults = list(v_table.metric_ann_search(\n    quote_vector,\n    n=8,\n    metric=\"cos\",\n    metric_threshold=metric_threshold,\n))\n\nprint(f\"{len(results)} quotes within the threshold:\")\nfor idx, result in enumerate(results):\n    print(f\"    {idx}. [distance={result['distance']:.3f}] \\\"{result['body_blob'][:70]}...\\\"\")\n```\n\n    3 quotes within the threshold:\n        0. [distance=0.855] \"The assumption that animals are without rights, and the illusion that ...\"\n        1. [distance=0.843] \"Animals are in possession of themselves; their soul is in possession o...\"\n        2. [distance=0.841] \"At his best, man is the noblest of all animals; separated from law and...\"\n\n\n## Use case 2: **quote generator**\n\nFor this task you need another component from OpenAI, namely an LLM to generate the quote for us (based on input obtained by querying the Vector Store).\n\nYou also need a template for the prompt that will be filled for the generate-quote LLM completion task.\n\n\n```python\ncompletion_model_name = \"gpt-3.5-turbo\"\n\ngeneration_prompt_template = \"\"\"\"Generate a single short philosophical quote on the given topic,\nsimilar in spirit and form to the provided actual example quotes.\nDo not exceed 20-30 words in your quote.\n\nREFERENCE TOPIC: \"{topic}\"\n\nACTUAL EXAMPLES:\n{examples}\n\"\"\"\n```\n\nLike for search, this functionality is best wrapped into a handy function (which internally uses search):\n\n\n```python\ndef generate_quote(topic, n=2, author=None, tags=None):\n    quotes = find_quote_and_author(query_quote=topic, n=n, author=author, tags=tags)\n    if quotes:\n        prompt = generation_prompt_template.format(\n            topic=topic,\n            examples=\"\\n\".join(f\"  - {quote[0]}\" for quote in quotes),\n        )\n        # a little logging:\n        print(\"** quotes found:\")\n        for q, a in quotes:\n            print(f\"**    - {q} ({a})\")\n        print(\"** end of logging\")\n        #\n        response = client.chat.completions.create(\n            model=completion_model_name,\n            messages=[{\"role\": \"user\", \"content\": prompt}],\n            temperature=0.7,\n            max_tokens=320,\n        )\n        return response.choices[0].message.content.replace('\"', '').strip()\n    else:\n        print(\"** no quotes found.\")\n        return None\n```\n\n_Note: similar to the case of the embedding computation, the code for the Chat Completion API would be slightly different for OpenAI prior to v1.0._\n\n#### Putting quote generation to test\n\nJust passing a text (a \"quote\", but one can actually just suggest a topic since its vector embedding will still end up at the right place in the vector space):"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 7c5f12e6-6bd5-4f7a-8137-c7b661480300
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/cassandra_astradb/Philosophical_Quotes_cassIO.ipynb", "title": "Philosophy with Vector Embeddings, OpenAI and Cassandra / Astra DB through CQL", "tokens": 6051, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"7c5f12e6-6bd5-4f7a-8137-c7b661480300\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/cassandra_astradb/Philosophical_Quotes_cassIO.ipynb\", \"title\": \"Philosophy with Vector Embeddings, OpenAI and Cassandra / Astra DB through CQL\", \"tokens\": 6051, \"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\": \"8938aaa0-39b6-4913-afa3-644dfcdc84cb\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/cassandra_astradb/Philosophical_Quotes_cassIO.ipynb\", \"title\": \"Philosophy with Vector Embeddings, OpenAI and Cassandra / Astra DB through CQL\", \"tokens\": 6051, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"723f825cd19bd5d01794b8111cf19db861b8b27b9247f5207316ec1dc1f05a13\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"32d137b6-abde-41db-af87-1e78c893e016\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/cassandra_astradb/Philosophical_Quotes_cassIO.ipynb\", \"title\": \"Philosophy with Vector Embeddings, OpenAI and Cassandra / Astra DB through CQL\", \"tokens\": 6051, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"1520c044285032ea5a358010c8e0eeab28a8cddbf5ba00316720d6118c17394b\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"d845f904-c5e5-4e1c-bf9c-404e98134c0a\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"28f01cd6aa2437d3c28608fe26670f51cd613835fcffabd190b11f5eb4a8c835\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 15768, \"end_char_idx\": 19208, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "8938aaa0-39b6-4913-afa3-644dfcdc84cb", "doc_id": "8938aaa0-39b6-4913-afa3-644dfcdc84cb", "ref_doc_id": "8938aaa0-39b6-4913-afa3-644dfcdc84cb", "chroma:document": "```python\ncompletion_model_name = \"gpt-3.5-turbo\"\n\ngeneration_prompt_template = \"\"\"\"Generate a single short philosophical quote on the given topic,\nsimilar in spirit and form to the provided actual example quotes.\nDo not exceed 20-30 words in your quote.\n\nREFERENCE TOPIC: \"{topic}\"\n\nACTUAL EXAMPLES:\n{examples}\n\"\"\"\n```\n\nLike for search, this functionality is best wrapped into a handy function (which internally uses search):\n\n\n```python\ndef generate_quote(topic, n=2, author=None, tags=None):\n    quotes = find_quote_and_author(query_quote=topic, n=n, author=author, tags=tags)\n    if quotes:\n        prompt = generation_prompt_template.format(\n            topic=topic,\n            examples=\"\\n\".join(f\"  - {quote[0]}\" for quote in quotes),\n        )\n        # a little logging:\n        print(\"** quotes found:\")\n        for q, a in quotes:\n            print(f\"**    - {q} ({a})\")\n        print(\"** end of logging\")\n        #\n        response = client.chat.completions.create(\n            model=completion_model_name,\n            messages=[{\"role\": \"user\", \"content\": prompt}],\n            temperature=0.7,\n            max_tokens=320,\n        )\n        return response.choices[0].message.content.replace('\"', '').strip()\n    else:\n        print(\"** no quotes found.\")\n        return None\n```\n\n_Note: similar to the case of the embedding computation, the code for the Chat Completion API would be slightly different for OpenAI prior to v1.0._\n\n#### Putting quote generation to test\n\nJust passing a text (a \"quote\", but one can actually just suggest a topic since its vector embedding will still end up at the right place in the vector space):\n\n\n```python\nq_topic = generate_quote(\"politics and virtue\")\nprint(\"\\nA new generated quote:\")\nprint(q_topic)\n```\n\n    ** quotes found:\n    **    - Happiness is the reward of virtue. (aristotle)\n    **    - Our moral virtues benefit mainly other people; intellectual virtues, on the other hand, benefit primarily ourselves; therefore the former make us universally popular, the latter unpopular. (schopenhauer)\n    ** end of logging\n    \n    A new generated quote:\n    Virtuous politics purifies society, while corrupt politics breeds chaos and decay.\n\n\nUse inspiration from just a single philosopher:\n\n\n```python\nq_topic = generate_quote(\"animals\", author=\"schopenhauer\")\nprint(\"\\nA new generated quote:\")\nprint(q_topic)\n```\n\n    ** quotes found:\n    **    - Because Christian morality leaves animals out of account, they are at once outlawed in philosophical morals; they are mere 'things,' mere means to any ends whatsoever. They can therefore be used for vivisection, hunting, coursing, bullfights, and horse racing, and can be whipped to death as they struggle along with heavy carts of stone. Shame on such a morality that is worthy of pariahs, and that fails to recognize the eternal essence that exists in every living thing, and shines forth with inscrutable significance from all eyes that see the sun! (schopenhauer)\n    **    - The assumption that animals are without rights, and the illusion that our treatment of them has no moral significance, is a positively outrageous example of Western crudity and barbarity. Universal compassion is the only guarantee of morality. (schopenhauer)\n    ** end of logging\n    \n    A new generated quote:\n    The true measure of humanity lies not in our dominion over animals, but in our ability to show compassion and respect for all living beings."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: d845f904-c5e5-4e1c-bf9c-404e98134c0a
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/cassandra_astradb/Philosophical_Quotes_cassIO.ipynb", "title": "Philosophy with Vector Embeddings, OpenAI and Cassandra / Astra DB through CQL", "tokens": 6051, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"d845f904-c5e5-4e1c-bf9c-404e98134c0a\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/cassandra_astradb/Philosophical_Quotes_cassIO.ipynb\", \"title\": \"Philosophy with Vector Embeddings, OpenAI and Cassandra / Astra DB through CQL\", \"tokens\": 6051, \"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\": \"8938aaa0-39b6-4913-afa3-644dfcdc84cb\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/cassandra_astradb/Philosophical_Quotes_cassIO.ipynb\", \"title\": \"Philosophy with Vector Embeddings, OpenAI and Cassandra / Astra DB through CQL\", \"tokens\": 6051, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"723f825cd19bd5d01794b8111cf19db861b8b27b9247f5207316ec1dc1f05a13\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"7c5f12e6-6bd5-4f7a-8137-c7b661480300\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/cassandra_astradb/Philosophical_Quotes_cassIO.ipynb\", \"title\": \"Philosophy with Vector Embeddings, OpenAI and Cassandra / Astra DB through CQL\", \"tokens\": 6051, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"572205a30c09ff140fbca2a7f25b0da8acc2d55af121297633fe50672e167e13\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"2df7ff6b-ba7e-4504-b96b-068510c45d63\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"c26e01f72c6f2863c881361edd6a6c855ab22d8284c6cc1a8dae242198d2c4cf\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 17414, \"end_char_idx\": 20295, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "8938aaa0-39b6-4913-afa3-644dfcdc84cb", "doc_id": "8938aaa0-39b6-4913-afa3-644dfcdc84cb", "ref_doc_id": "8938aaa0-39b6-4913-afa3-644dfcdc84cb", "chroma:document": "```python\nq_topic = generate_quote(\"politics and virtue\")\nprint(\"\\nA new generated quote:\")\nprint(q_topic)\n```\n\n    ** quotes found:\n    **    - Happiness is the reward of virtue. (aristotle)\n    **    - Our moral virtues benefit mainly other people; intellectual virtues, on the other hand, benefit primarily ourselves; therefore the former make us universally popular, the latter unpopular. (schopenhauer)\n    ** end of logging\n    \n    A new generated quote:\n    Virtuous politics purifies society, while corrupt politics breeds chaos and decay.\n\n\nUse inspiration from just a single philosopher:\n\n\n```python\nq_topic = generate_quote(\"animals\", author=\"schopenhauer\")\nprint(\"\\nA new generated quote:\")\nprint(q_topic)\n```\n\n    ** quotes found:\n    **    - Because Christian morality leaves animals out of account, they are at once outlawed in philosophical morals; they are mere 'things,' mere means to any ends whatsoever. They can therefore be used for vivisection, hunting, coursing, bullfights, and horse racing, and can be whipped to death as they struggle along with heavy carts of stone. Shame on such a morality that is worthy of pariahs, and that fails to recognize the eternal essence that exists in every living thing, and shines forth with inscrutable significance from all eyes that see the sun! (schopenhauer)\n    **    - The assumption that animals are without rights, and the illusion that our treatment of them has no moral significance, is a positively outrageous example of Western crudity and barbarity. Universal compassion is the only guarantee of morality. (schopenhauer)\n    ** end of logging\n    \n    A new generated quote:\n    The true measure of humanity lies not in our dominion over animals, but in our ability to show compassion and respect for all living beings.\n\n\n## (Optional) **Partitioning**\n\nThere's an interesting topic to examine before completing this quickstart. While, generally, tags and quotes can be in any relationship (e.g. a quote having multiple tags), _authors_ are effectively an exact grouping (they define a \"disjoint partitioning\" on the set of quotes): each quote has exactly one author (for us, at least).\n\nNow, suppose you know in advance your application will usually (or always) run queries on a _single author_. Then you can take full advantage of the underlying database structure: if you group quotes in **partitions** (one per author), vector queries on just an author will use less resources and return much faster.\n\nWe'll not dive into the details here, which have to do with the Cassandra storage internals: the important message is that **if your queries are run within a group, consider partitioning accordingly to boost performance**.\n\nYou'll now see this choice in action.\n\nFirst, you need a different table abstraction from CassIO:\n\n\n```python\nfrom cassio.table import ClusteredMetadataVectorCassandraTable\n```"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 2df7ff6b-ba7e-4504-b96b-068510c45d63
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/cassandra_astradb/Philosophical_Quotes_cassIO.ipynb", "title": "Philosophy with Vector Embeddings, OpenAI and Cassandra / Astra DB through CQL", "tokens": 6051, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"2df7ff6b-ba7e-4504-b96b-068510c45d63\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/cassandra_astradb/Philosophical_Quotes_cassIO.ipynb\", \"title\": \"Philosophy with Vector Embeddings, OpenAI and Cassandra / Astra DB through CQL\", \"tokens\": 6051, \"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\": \"8938aaa0-39b6-4913-afa3-644dfcdc84cb\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/cassandra_astradb/Philosophical_Quotes_cassIO.ipynb\", \"title\": \"Philosophy with Vector Embeddings, OpenAI and Cassandra / Astra DB through CQL\", \"tokens\": 6051, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"723f825cd19bd5d01794b8111cf19db861b8b27b9247f5207316ec1dc1f05a13\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"d845f904-c5e5-4e1c-bf9c-404e98134c0a\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/cassandra_astradb/Philosophical_Quotes_cassIO.ipynb\", \"title\": \"Philosophy with Vector Embeddings, OpenAI and Cassandra / Astra DB through CQL\", \"tokens\": 6051, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"39cf7c9d6d0b297719c69bbd675abb83a181a9d317136a1af41b50f85b9b4731\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"efb11482-3ae1-47ee-8975-755de9e7792b\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"06cf7088182946ccae7ef6824b5c7de4c4cc7556832bfe7598b65f1ca1a76eab\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 19211, \"end_char_idx\": 21300, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "8938aaa0-39b6-4913-afa3-644dfcdc84cb", "doc_id": "8938aaa0-39b6-4913-afa3-644dfcdc84cb", "ref_doc_id": "8938aaa0-39b6-4913-afa3-644dfcdc84cb", "chroma:document": "## (Optional) **Partitioning**\n\nThere's an interesting topic to examine before completing this quickstart. While, generally, tags and quotes can be in any relationship (e.g. a quote having multiple tags), _authors_ are effectively an exact grouping (they define a \"disjoint partitioning\" on the set of quotes): each quote has exactly one author (for us, at least).\n\nNow, suppose you know in advance your application will usually (or always) run queries on a _single author_. Then you can take full advantage of the underlying database structure: if you group quotes in **partitions** (one per author), vector queries on just an author will use less resources and return much faster.\n\nWe'll not dive into the details here, which have to do with the Cassandra storage internals: the important message is that **if your queries are run within a group, consider partitioning accordingly to boost performance**.\n\nYou'll now see this choice in action.\n\nFirst, you need a different table abstraction from CassIO:\n\n\n```python\nfrom cassio.table import ClusteredMetadataVectorCassandraTable\n```\n\n\n```python\nv_table_partitioned = ClusteredMetadataVectorCassandraTable(table=\"philosophers_cassio_partitioned\", vector_dimension=1536)\n```\n\nNow repeat the compute-embeddings-and-insert step on the new table.\n\nCompared to what you have seen earlier, there is a crucial difference in that now the quote's author is stored as the _partition id_ for the inserted row, instead of being added to the catch-all \"metadata\" dictionary.\n\nWhile you are at it, by way of demonstration, you will insert all quotes by a given author _concurrently_: with CassIO, this is done by usng the asynchronous `put_async` method for each quote, collecting the resulting list of `Future` objects, and calling the `result()` method on them all afterwards, to ensure they all have executed. Cassandra / Astra DB well supports a high degree of concurrency in I/O operations.\n\n_(Note: one could have cached the embeddings computed previously to save a few API tokens -- here, however, we wanted to keep the code easier to inspect.)_"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: efb11482-3ae1-47ee-8975-755de9e7792b
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/cassandra_astradb/Philosophical_Quotes_cassIO.ipynb", "title": "Philosophy with Vector Embeddings, OpenAI and Cassandra / Astra DB through CQL", "tokens": 6051, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"efb11482-3ae1-47ee-8975-755de9e7792b\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/cassandra_astradb/Philosophical_Quotes_cassIO.ipynb\", \"title\": \"Philosophy with Vector Embeddings, OpenAI and Cassandra / Astra DB through CQL\", \"tokens\": 6051, \"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\": \"8938aaa0-39b6-4913-afa3-644dfcdc84cb\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/cassandra_astradb/Philosophical_Quotes_cassIO.ipynb\", \"title\": \"Philosophy with Vector Embeddings, OpenAI and Cassandra / Astra DB through CQL\", \"tokens\": 6051, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"723f825cd19bd5d01794b8111cf19db861b8b27b9247f5207316ec1dc1f05a13\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"2df7ff6b-ba7e-4504-b96b-068510c45d63\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/cassandra_astradb/Philosophical_Quotes_cassIO.ipynb\", \"title\": \"Philosophy with Vector Embeddings, OpenAI and Cassandra / Astra DB through CQL\", \"tokens\": 6051, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"df9f374bc5ae43309d4f8bfdbe82dd35f2a864770dcf3d676d6b811699f50b2e\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"1aca468d-bc24-45fc-9de8-1de72112573f\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"b8d19c4159f80dc3a9c720af1ea488944a32a179071927843ff77b665d6dcd38\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 20219, \"end_char_idx\": 23002, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "8938aaa0-39b6-4913-afa3-644dfcdc84cb", "doc_id": "8938aaa0-39b6-4913-afa3-644dfcdc84cb", "ref_doc_id": "8938aaa0-39b6-4913-afa3-644dfcdc84cb", "chroma:document": "```python\nfrom cassio.table import ClusteredMetadataVectorCassandraTable\n```\n\n\n```python\nv_table_partitioned = ClusteredMetadataVectorCassandraTable(table=\"philosophers_cassio_partitioned\", vector_dimension=1536)\n```\n\nNow repeat the compute-embeddings-and-insert step on the new table.\n\nCompared to what you have seen earlier, there is a crucial difference in that now the quote's author is stored as the _partition id_ for the inserted row, instead of being added to the catch-all \"metadata\" dictionary.\n\nWhile you are at it, by way of demonstration, you will insert all quotes by a given author _concurrently_: with CassIO, this is done by usng the asynchronous `put_async` method for each quote, collecting the resulting list of `Future` objects, and calling the `result()` method on them all afterwards, to ensure they all have executed. Cassandra / Astra DB well supports a high degree of concurrency in I/O operations.\n\n_(Note: one could have cached the embeddings computed previously to save a few API tokens -- here, however, we wanted to keep the code easier to inspect.)_\n\n\n```python\nBATCH_SIZE = 50\n\nnum_batches = ((len(philo_dataset) + BATCH_SIZE - 1) // BATCH_SIZE)\n\nquotes_list = philo_dataset[\"quote\"]\nauthors_list = philo_dataset[\"author\"]\ntags_list = philo_dataset[\"tags\"]\n\nprint(\"Starting to store entries:\")\nfor batch_i in range(num_batches):\n    b_start = batch_i * BATCH_SIZE\n    b_end = (batch_i + 1) * BATCH_SIZE\n    # compute the embedding vectors for this batch\n    b_emb_results = client.embeddings.create(\n        input=quotes_list[b_start : b_end],\n        model=embedding_model_name,\n    )\n    # prepare the rows for insertion\n    futures = []\n    print(\"B \", end=\"\")\n    for entry_idx, emb_result in zip(range(b_start, b_end), b_emb_results.data):\n        if tags_list[entry_idx]:\n            tags = {\n                tag\n                for tag in tags_list[entry_idx].split(\";\")\n            }\n        else:\n            tags = set()\n        author = authors_list[entry_idx]\n        quote = quotes_list[entry_idx]\n        futures.append(v_table_partitioned.put_async(\n            partition_id=author,\n            row_id=f\"q_{author}_{entry_idx}\",\n            body_blob=quote,\n            vector=emb_result.embedding,\n            metadata={tag: True for tag in tags},\n        ))\n    #\n    for future in futures:\n        future.result()\n    #\n    print(f\" done ({len(b_emb_results.data)})\")\n\nprint(\"\\nFinished storing entries.\")\n```\n\n    Starting to store entries:\n    B  done (50)\n    B  done (50)\n    B  done (50)\n    B  done (50)\n    B  done (50)\n    B  done (50)\n    B  done (50)\n    B  done (50)\n    B  done (50)\n    \n    Finished storing entries.\n\n\nWith this new table, the similarity search changes accordingly (note the arguments to `ann_search`):"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 1aca468d-bc24-45fc-9de8-1de72112573f
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/cassandra_astradb/Philosophical_Quotes_cassIO.ipynb", "title": "Philosophy with Vector Embeddings, OpenAI and Cassandra / Astra DB through CQL", "tokens": 6051, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"1aca468d-bc24-45fc-9de8-1de72112573f\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/cassandra_astradb/Philosophical_Quotes_cassIO.ipynb\", \"title\": \"Philosophy with Vector Embeddings, OpenAI and Cassandra / Astra DB through CQL\", \"tokens\": 6051, \"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\": \"8938aaa0-39b6-4913-afa3-644dfcdc84cb\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/cassandra_astradb/Philosophical_Quotes_cassIO.ipynb\", \"title\": \"Philosophy with Vector Embeddings, OpenAI and Cassandra / Astra DB through CQL\", \"tokens\": 6051, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"723f825cd19bd5d01794b8111cf19db861b8b27b9247f5207316ec1dc1f05a13\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"efb11482-3ae1-47ee-8975-755de9e7792b\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/cassandra_astradb/Philosophical_Quotes_cassIO.ipynb\", \"title\": \"Philosophy with Vector Embeddings, OpenAI and Cassandra / Astra DB through CQL\", \"tokens\": 6051, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"e9594886c16e10c019bddf58f236ff9c58aebc9c1c421e64605d29d14ebdc121\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 22902, \"end_char_idx\": 26172, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "8938aaa0-39b6-4913-afa3-644dfcdc84cb", "doc_id": "8938aaa0-39b6-4913-afa3-644dfcdc84cb", "ref_doc_id": "8938aaa0-39b6-4913-afa3-644dfcdc84cb", "chroma:document": "With this new table, the similarity search changes accordingly (note the arguments to `ann_search`):\n\n\n```python\ndef find_quote_and_author_p(query_quote, n, author=None, tags=None):\n    query_vector = client.embeddings.create(\n        input=[query_quote],\n        model=embedding_model_name,\n    ).data[0].embedding\n    metadata = {}\n    partition_id = None\n    if author:\n        partition_id = author\n    if tags:\n        for tag in tags:\n            metadata[tag] = True\n    #\n    results = v_table_partitioned.ann_search(\n        query_vector,\n        n=n,\n        partition_id=partition_id,\n        metadata=metadata,\n    )\n    return [\n        (result[\"body_blob\"], result[\"partition_id\"])\n        for result in results\n    ]\n```\n\nThat's it: the new table still supports the \"generic\" similarity searches all right ...\n\n\n```python\nfind_quote_and_author_p(\"We struggle all our life for nothing\", 3)\n```\n\n\n\n\n    [('Life to the great majority is only a constant struggle for mere existence, with the certainty of losing it at last.',\n      'schopenhauer'),\n     ('We give up leisure in order that we may have leisure, just as we go to war in order that we may have peace.',\n      'aristotle'),\n     ('Perhaps the gods are kind to us, by making life more disagreeable as we grow older. In the end death seems less intolerable than the manifold burdens we carry',\n      'freud')]\n\n\n\n... but it's when an author is specified that you would notice a _huge_ performance advantage:\n\n\n```python\nfind_quote_and_author_p(\"We struggle all our life for nothing\", 2, author=\"nietzsche\")\n```\n\n\n\n\n    [('To live is to suffer, to survive is to find some meaning in the suffering.',\n      'nietzsche'),\n     ('What makes us heroic?--Confronting simultaneously our supreme suffering and our supreme hope.',\n      'nietzsche')]\n\n\n\nWell, you _would_ notice a performance gain, if you had a realistic-size dataset. In this demo, with a few tens of entries, there's no noticeable difference -- but you get the idea.\n\n## Conclusion\n\nCongratulations! You have learned how to use OpenAI for vector embeddings and Cassandra / Astra DB through CQL for storage in order to build a sophisticated philosophical search engine and quote generator.\n\nThis example used [CassIO](https://cassio.org) to interface with the Vector Store - but this is not the only choice. Check the [README](https://github.com/openai/openai-cookbook/tree/main/examples/vector_databases/cassandra_astradb) for other options and integration with popular frameworks.\n\nTo find out more on how Astra DB's Vector Search capabilities can be a key ingredient in your ML/GenAI applications, visit [Astra DB](https://docs.datastax.com/en/astra/home/astra.html)'s web page on the topic.\n\n## Cleanup\n\nIf you want to remove all resources used for this demo, run this cell (_warning: this will delete the tables and the data inserted in them!_):\n\n\n```python\n# we peek at CassIO's config to get a direct handle to the DB connection\nsession = cassio.config.resolve_session()\nkeyspace = cassio.config.resolve_keyspace()\n\nsession.execute(f\"DROP TABLE IF EXISTS {keyspace}.philosophers_cassio;\")\nsession.execute(f\"DROP TABLE IF EXISTS {keyspace}.philosophers_cassio_partitioned;\")\n```\n\n\n\n\n    <cassandra.cluster.ResultSet at 0x7fdcc42e8f10>"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 0e39c9ce-ea3b-4de8-8c29-80717d19d8ba
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/cassandra_astradb/README.ipynb", "title": "RAG with Astra DB and Cassandra", "tokens": 669, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"0e39c9ce-ea3b-4de8-8c29-80717d19d8ba\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/cassandra_astradb/README.ipynb\", \"title\": \"RAG with Astra DB and Cassandra\", \"tokens\": 669, \"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\": \"3cf88420-64a3-475f-a53a-07bcf964fd02\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/cassandra_astradb/README.ipynb\", \"title\": \"RAG with Astra DB and Cassandra\", \"tokens\": 669, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"75a90d81b31b38a6276c58f70dec4f8a6484ba5b0f1488314322d7da05d6bcd1\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 0, \"end_char_idx\": 2631, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "3cf88420-64a3-475f-a53a-07bcf964fd02", "doc_id": "3cf88420-64a3-475f-a53a-07bcf964fd02", "ref_doc_id": "3cf88420-64a3-475f-a53a-07bcf964fd02", "chroma:document": "# RAG with Astra DB and Cassandra\n\nThe demos in this directory show how to use the Vector\nSearch capabilities available today in **DataStax Astra DB**, a serverless\nDatabase-as-a-Service built on Apache Cassandra\u00ae.\n\nThese example notebooks demonstrate implementation of\nthe same GenAI standard RAG workload with different libraries and APIs.\n\nTo use [Astra DB](https://docs.datastax.com/en/astra/home/astra.html)\nwith its HTTP API interface, head to the \"AstraPy\" notebook (`astrapy`\nis the Python client to interact with the database).\n\nIf you prefer CQL access to the database (either with\n[Astra DB](https://docs.datastax.com/en/astra-serverless/docs/vector-search/overview.html)\nor a Cassandra cluster\n[supporting vector search](https://cassandra.apache.org/doc/trunk/cassandra/vector-search/overview.html)),\ncheck the \"CQL\" or \"CassIO\" notebooks -- they differ in the level of abstraction you get to work at.\n\nIf you want to know more about Astra DB and its Vector Search capabilities,\nhead over to [datastax.com](https://docs.datastax.com/en/astra/home/astra.html).\n\n### Example notebooks\n\nThe following examples show how easily OpenAI and DataStax Astra DB can\nwork together to power vector-based AI applications. You can run them either\nwith your local Jupyter engine or as Colab notebooks:\n\n| Use case | Target database | Framework | Notebook | Google Colab |\n| -------- | --------------- | --------- | -------- | ------------ |\n| Search/generate quotes | Astra DB | AstraPy | [Notebook](./Philosophical_Quotes_AstraPy.ipynb) | [![Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/openai/openai-cookbook/blob/main/examples/vector_databases/cassandra_astradb/Philosophical_Quotes_AstraPy.ipynb) |\n| Search/generate quotes | Cassandra / Astra DB through CQL | CassIO | [Notebook](./Philosophical_Quotes_cassIO.ipynb) | [![Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/openai/openai-cookbook/blob/main/examples/vector_databases/cassandra_astradb/Philosophical_Quotes_cassIO.ipynb) |\n| Search/generate quotes | Cassandra / Astra DB through CQL | Plain Cassandra language | [Notebook](./Philosophical_Quotes_CQL.ipynb) | [![Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/openai/openai-cookbook/blob/main/examples/vector_databases/cassandra_astradb/Philosophical_Quotes_CQL.ipynb) |\n\n### Vector similarity, visual representation\n\n![3_vector_space](https://user-images.githubusercontent.com/14221764/262321363-c8c625c1-8be9-450e-8c68-b1ed518f990d.png)"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 05004896-9f2e-472f-9a14-3f47bc18bbe0
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/myscale/Using_MyScale_for_embeddings_search.ipynb", "title": "Using MyScale for Embeddings Search", "tokens": 2754, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"05004896-9f2e-472f-9a14-3f47bc18bbe0\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/myscale/Using_MyScale_for_embeddings_search.ipynb\", \"title\": \"Using MyScale for Embeddings Search\", \"tokens\": 2754, \"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\": \"db892807-c113-4bfd-9704-8d93dd9aff1a\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/myscale/Using_MyScale_for_embeddings_search.ipynb\", \"title\": \"Using MyScale for Embeddings Search\", \"tokens\": 2754, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"fd236f6738bea8e07f4ddca6cb76596d7f2c7a3b7052ead7cb5c93156357c356\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"e5626353-aa0f-441a-8d70-f68a4fed54cc\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"de6fcb349e7fc5d729b2ec4d246c9b47eb380869b5124a394c53b81a7a83c9c9\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 0, \"end_char_idx\": 3615, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "db892807-c113-4bfd-9704-8d93dd9aff1a", "doc_id": "db892807-c113-4bfd-9704-8d93dd9aff1a", "ref_doc_id": "db892807-c113-4bfd-9704-8d93dd9aff1a", "chroma:document": "# Using MyScale for Embeddings Search\n\nThis notebook takes you through a simple flow to download some data, embed it, and then index and search it using a selection of vector databases. This is a common requirement for customers who want to store and search our embeddings with their own data in a secure environment to support production use cases such as chatbots, topic modelling and more.\n\n### What is a Vector Database\n\nA vector database is a database made to store, manage and search embedding vectors. The use of embeddings to encode unstructured data (text, audio, video and more) as vectors for consumption by machine-learning models has exploded in recent years, due to the increasing effectiveness of AI in solving use cases involving natural language, image recognition and other unstructured forms of data. Vector databases have emerged as an effective solution for enterprises to deliver and scale these use cases.\n\n### Why use a Vector Database\n\nVector databases enable enterprises to take many of the embeddings use cases we've shared in this repo (question and answering, chatbot and recommendation services, for example), and make use of them in a secure, scalable environment. Many of our customers make embeddings solve their problems at small scale but performance and security hold them back from going into production - we see vector databases as a key component in solving that, and in this guide we'll walk through the basics of embedding text data, storing it in a vector database and using it for semantic search.\n\n\n### Demo Flow\nThe demo flow is:\n- **Setup**: Import packages and set any required variables\n- **Load data**: Load a dataset and embed it using OpenAI embeddings\n- **MyScale**\n    - *Setup*: Set up the MyScale Python client. For more details go [here](https://docs.myscale.com/en/python-client/)\n    - *Index Data*: We'll create a table and index it for __content__.\n    - *Search Data*: Run a few example queries with various goals in mind.\n\nOnce you've run through this notebook you should have a basic understanding of how to setup and use vector databases, and can move on to more complex use cases making use of our embeddings.\n\n## Setup\n\nImport the required libraries and set the embedding model that we'd like to use.\n\n\n```python\n# We'll need to install the MyScale client\n!pip install clickhouse-connect\n\n#Install wget to pull zip file\n!pip install wget\n```\n\n\n```python\nimport openai\n\nfrom typing import List, Iterator\nimport pandas as pd\nimport numpy as np\nimport os\nimport wget\nfrom ast import literal_eval\n\n# MyScale's client library for Python\nimport clickhouse_connect\n\n# I've set this to our new embeddings model, this can be changed to the embedding model of your choice\nEMBEDDING_MODEL = \"text-embedding-3-small\"\n\n# Ignore unclosed SSL socket warnings - optional in case you get these errors\nimport warnings\n\nwarnings.filterwarnings(action=\"ignore\", message=\"unclosed\", category=ResourceWarning)\nwarnings.filterwarnings(\"ignore\", category=DeprecationWarning) \n```\n\n## Load data\n\nIn this section we'll load embedded data that we've prepared previous to this session.\n\n\n```python\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\n```python\nimport zipfile\nwith zipfile.ZipFile(\"vector_database_wikipedia_articles_embedded.zip\",\"r\") as zip_ref:\n    zip_ref.extractall(\"../data\")\n```\n\n\n```python\narticle_df = pd.read_csv('../data/vector_database_wikipedia_articles_embedded.csv')\n```\n\n\n```python\narticle_df.head()\n```"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: e5626353-aa0f-441a-8d70-f68a4fed54cc
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/myscale/Using_MyScale_for_embeddings_search.ipynb", "title": "Using MyScale for Embeddings Search", "tokens": 2754, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"e5626353-aa0f-441a-8d70-f68a4fed54cc\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/myscale/Using_MyScale_for_embeddings_search.ipynb\", \"title\": \"Using MyScale for Embeddings Search\", \"tokens\": 2754, \"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\": \"db892807-c113-4bfd-9704-8d93dd9aff1a\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/myscale/Using_MyScale_for_embeddings_search.ipynb\", \"title\": \"Using MyScale for Embeddings Search\", \"tokens\": 2754, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"fd236f6738bea8e07f4ddca6cb76596d7f2c7a3b7052ead7cb5c93156357c356\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"05004896-9f2e-472f-9a14-3f47bc18bbe0\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/myscale/Using_MyScale_for_embeddings_search.ipynb\", \"title\": \"Using MyScale for Embeddings Search\", \"tokens\": 2754, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"e471cb199bbb6499ed8c87a093f68be47521ee8a5f800c81b13f25d00f7df59b\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"dbc212a8-890c-4a9e-a788-20c4be128fa1\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"55d75d734c6c465942a4bbe99c9e2550ca1dde90d5af183d906f3fc23ae149c3\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 2269, \"end_char_idx\": 4631, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "db892807-c113-4bfd-9704-8d93dd9aff1a", "doc_id": "db892807-c113-4bfd-9704-8d93dd9aff1a", "ref_doc_id": "db892807-c113-4bfd-9704-8d93dd9aff1a", "chroma:document": "```python\n# We'll need to install the MyScale client\n!pip install clickhouse-connect\n\n#Install wget to pull zip file\n!pip install wget\n```\n\n\n```python\nimport openai\n\nfrom typing import List, Iterator\nimport pandas as pd\nimport numpy as np\nimport os\nimport wget\nfrom ast import literal_eval\n\n# MyScale's client library for Python\nimport clickhouse_connect\n\n# I've set this to our new embeddings model, this can be changed to the embedding model of your choice\nEMBEDDING_MODEL = \"text-embedding-3-small\"\n\n# Ignore unclosed SSL socket warnings - optional in case you get these errors\nimport warnings\n\nwarnings.filterwarnings(action=\"ignore\", message=\"unclosed\", category=ResourceWarning)\nwarnings.filterwarnings(\"ignore\", category=DeprecationWarning) \n```\n\n## Load data\n\nIn this section we'll load embedded data that we've prepared previous to this session.\n\n\n```python\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\n```python\nimport zipfile\nwith zipfile.ZipFile(\"vector_database_wikipedia_articles_embedded.zip\",\"r\") as zip_ref:\n    zip_ref.extractall(\"../data\")\n```\n\n\n```python\narticle_df = pd.read_csv('../data/vector_database_wikipedia_articles_embedded.csv')\n```\n\n\n```python\narticle_df.head()\n```\n\n\n\n\n<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>id</th>\n      <th>url</th>\n      <th>title</th>\n      <th>text</th>\n      <th>title_vector</th>\n      <th>content_vector</th>\n      <th>vector_id</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>1</td>\n      <td>https://simple.wikipedia.org/wiki/April</td>\n      <td>April</td>\n      <td>April is the fourth month of the year in the J...</td>\n      <td>[0.001009464613161981, -0.020700545981526375, ...</td>\n      <td>[-0.011253940872848034, -0.013491976074874401,...</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>2</td>\n      <td>https://simple.wikipedia.org/wiki/August</td>\n      <td>August</td>\n      <td>August (Aug.)"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: dbc212a8-890c-4a9e-a788-20c4be128fa1
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/myscale/Using_MyScale_for_embeddings_search.ipynb", "title": "Using MyScale for Embeddings Search", "tokens": 2754, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"dbc212a8-890c-4a9e-a788-20c4be128fa1\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/myscale/Using_MyScale_for_embeddings_search.ipynb\", \"title\": \"Using MyScale for Embeddings Search\", \"tokens\": 2754, \"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\": \"db892807-c113-4bfd-9704-8d93dd9aff1a\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/myscale/Using_MyScale_for_embeddings_search.ipynb\", \"title\": \"Using MyScale for Embeddings Search\", \"tokens\": 2754, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"fd236f6738bea8e07f4ddca6cb76596d7f2c7a3b7052ead7cb5c93156357c356\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"e5626353-aa0f-441a-8d70-f68a4fed54cc\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/myscale/Using_MyScale_for_embeddings_search.ipynb\", \"title\": \"Using MyScale for Embeddings Search\", \"tokens\": 2754, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"a3e97206888675368b528c22d59c7fef64d48483dff473c9ba0afe3b73012aab\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"dd5ce74c-81a2-4c94-8423-776fc1237d32\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"0eb9f1fbcad7c87e0ae1cc80d55f22c888212d66f0901dbcd88725f848899c3c\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 3484, \"end_char_idx\": 5662, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "db892807-c113-4bfd-9704-8d93dd9aff1a", "doc_id": "db892807-c113-4bfd-9704-8d93dd9aff1a", "ref_doc_id": "db892807-c113-4bfd-9704-8d93dd9aff1a", "chroma:document": "```python\narticle_df = pd.read_csv('../data/vector_database_wikipedia_articles_embedded.csv')\n```\n\n\n```python\narticle_df.head()\n```\n\n\n\n\n<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>id</th>\n      <th>url</th>\n      <th>title</th>\n      <th>text</th>\n      <th>title_vector</th>\n      <th>content_vector</th>\n      <th>vector_id</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>1</td>\n      <td>https://simple.wikipedia.org/wiki/April</td>\n      <td>April</td>\n      <td>April is the fourth month of the year in the J...</td>\n      <td>[0.001009464613161981, -0.020700545981526375, ...</td>\n      <td>[-0.011253940872848034, -0.013491976074874401,...</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>2</td>\n      <td>https://simple.wikipedia.org/wiki/August</td>\n      <td>August</td>\n      <td>August (Aug.) is the eighth month of the year ...</td>\n      <td>[0.0009286514250561595, 0.000820168002974242, ...</td>\n      <td>[0.0003609954728744924, 0.007262262050062418, ...</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>6</td>\n      <td>https://simple.wikipedia.org/wiki/Art</td>\n      <td>Art</td>\n      <td>Art is a creative activity that expresses imag...</td>\n      <td>[0.003393713850528002, 0.0061537534929811954, ...</td>\n      <td>[-0.004959689453244209, 0.015772193670272827, ...</td>\n      <td>2</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>8</td>\n      <td>https://simple.wikipedia.org/wiki/A</td>\n      <td>A</td>\n      <td>A or a is the first letter of the English alph...</td>\n      <td>[0.0153952119871974, -0.013759135268628597, 0....</td>\n      <td>[0.024894846603274345, -0.022186409682035446, ...</td>\n      <td>3</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>9</td>\n      <td>https://simple.wikipedia.org/wiki/Air</td>\n      <td>Air</td>\n      <td>Air refers to the Earth's atmosphere."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: dd5ce74c-81a2-4c94-8423-776fc1237d32
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/myscale/Using_MyScale_for_embeddings_search.ipynb", "title": "Using MyScale for Embeddings Search", "tokens": 2754, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"dd5ce74c-81a2-4c94-8423-776fc1237d32\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/myscale/Using_MyScale_for_embeddings_search.ipynb\", \"title\": \"Using MyScale for Embeddings Search\", \"tokens\": 2754, \"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\": \"db892807-c113-4bfd-9704-8d93dd9aff1a\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/myscale/Using_MyScale_for_embeddings_search.ipynb\", \"title\": \"Using MyScale for Embeddings Search\", \"tokens\": 2754, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"fd236f6738bea8e07f4ddca6cb76596d7f2c7a3b7052ead7cb5c93156357c356\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"dbc212a8-890c-4a9e-a788-20c4be128fa1\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/myscale/Using_MyScale_for_embeddings_search.ipynb\", \"title\": \"Using MyScale for Embeddings Search\", \"tokens\": 2754, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"9c2e89c85f6d1531055a4490587a8ee7a4f4b55ba5b4847f5b570539af44ab8b\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"76657275-cb4a-4138-8dc4-4a1363aee852\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"838f0cc3d0ead1c682db56092fdb0a44134572846028a508c3f613d3bf701d6e\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 4632, \"end_char_idx\": 6830, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "db892807-c113-4bfd-9704-8d93dd9aff1a", "doc_id": "db892807-c113-4bfd-9704-8d93dd9aff1a", "ref_doc_id": "db892807-c113-4bfd-9704-8d93dd9aff1a", "chroma:document": "is the eighth month of the year ...</td>\n      <td>[0.0009286514250561595, 0.000820168002974242, ...</td>\n      <td>[0.0003609954728744924, 0.007262262050062418, ...</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>6</td>\n      <td>https://simple.wikipedia.org/wiki/Art</td>\n      <td>Art</td>\n      <td>Art is a creative activity that expresses imag...</td>\n      <td>[0.003393713850528002, 0.0061537534929811954, ...</td>\n      <td>[-0.004959689453244209, 0.015772193670272827, ...</td>\n      <td>2</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>8</td>\n      <td>https://simple.wikipedia.org/wiki/A</td>\n      <td>A</td>\n      <td>A or a is the first letter of the English alph...</td>\n      <td>[0.0153952119871974, -0.013759135268628597, 0....</td>\n      <td>[0.024894846603274345, -0.022186409682035446, ...</td>\n      <td>3</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>9</td>\n      <td>https://simple.wikipedia.org/wiki/Air</td>\n      <td>Air</td>\n      <td>Air refers to the Earth's atmosphere. Air is a...</td>\n      <td>[0.02224554680287838, -0.02044147066771984, -0...</td>\n      <td>[0.021524671465158463, 0.018522677943110466, -...</td>\n      <td>4</td>\n    </tr>\n  </tbody>\n</table>\n</div>\n\n\n\n\n```python\n# Read vectors from strings back into a list\narticle_df['title_vector'] = article_df.title_vector.apply(literal_eval)\narticle_df['content_vector'] = article_df.content_vector.apply(literal_eval)\n\n# Set vector_id to be a string\narticle_df['vector_id'] = article_df['vector_id'].apply(str)\n```\n\n\n```python\narticle_df.info(show_counts=True)\n```\n\n    <class 'pandas.core.frame.DataFrame'>\n    RangeIndex: 25000 entries, 0 to 24999\n    Data columns (total 7 columns):\n     #   Column          Non-Null Count  Dtype \n    ---  ------          --------------  ----- \n     0   id              25000 non-null  int64 \n     1   url             25000 non-null  object\n     2   title           25000 non-null  object\n     3   text            25000 non-null  object\n     4   title_vector    25000 non-null  object\n     5   content_vector  25000 non-null  object\n     6   vector_id       25000 non-null  object\n    dtypes: int64(1), object(6)\n    memory usage: 1.3+ MB"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 76657275-cb4a-4138-8dc4-4a1363aee852
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/myscale/Using_MyScale_for_embeddings_search.ipynb", "title": "Using MyScale for Embeddings Search", "tokens": 2754, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"76657275-cb4a-4138-8dc4-4a1363aee852\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/myscale/Using_MyScale_for_embeddings_search.ipynb\", \"title\": \"Using MyScale for Embeddings Search\", \"tokens\": 2754, \"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\": \"db892807-c113-4bfd-9704-8d93dd9aff1a\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/myscale/Using_MyScale_for_embeddings_search.ipynb\", \"title\": \"Using MyScale for Embeddings Search\", \"tokens\": 2754, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"fd236f6738bea8e07f4ddca6cb76596d7f2c7a3b7052ead7cb5c93156357c356\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"dd5ce74c-81a2-4c94-8423-776fc1237d32\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/myscale/Using_MyScale_for_embeddings_search.ipynb\", \"title\": \"Using MyScale for Embeddings Search\", \"tokens\": 2754, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"a56655af6402a8182db44ddf3b0cebb90c6b748b9983e5bd48449b2e03e07f04\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"09b77a37-4a4f-48d9-b734-f0625cf4434d\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"05f076a3140590c1ce448473600f589e8e8bd58f97fcb49d5f379d071502612b\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 5663, \"end_char_idx\": 8125, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "db892807-c113-4bfd-9704-8d93dd9aff1a", "doc_id": "db892807-c113-4bfd-9704-8d93dd9aff1a", "ref_doc_id": "db892807-c113-4bfd-9704-8d93dd9aff1a", "chroma:document": "Air is a...</td>\n      <td>[0.02224554680287838, -0.02044147066771984, -0...</td>\n      <td>[0.021524671465158463, 0.018522677943110466, -...</td>\n      <td>4</td>\n    </tr>\n  </tbody>\n</table>\n</div>\n\n\n\n\n```python\n# Read vectors from strings back into a list\narticle_df['title_vector'] = article_df.title_vector.apply(literal_eval)\narticle_df['content_vector'] = article_df.content_vector.apply(literal_eval)\n\n# Set vector_id to be a string\narticle_df['vector_id'] = article_df['vector_id'].apply(str)\n```\n\n\n```python\narticle_df.info(show_counts=True)\n```\n\n    <class 'pandas.core.frame.DataFrame'>\n    RangeIndex: 25000 entries, 0 to 24999\n    Data columns (total 7 columns):\n     #   Column          Non-Null Count  Dtype \n    ---  ------          --------------  ----- \n     0   id              25000 non-null  int64 \n     1   url             25000 non-null  object\n     2   title           25000 non-null  object\n     3   text            25000 non-null  object\n     4   title_vector    25000 non-null  object\n     5   content_vector  25000 non-null  object\n     6   vector_id       25000 non-null  object\n    dtypes: int64(1), object(6)\n    memory usage: 1.3+ MB\n\n\n## MyScale\nThe next vector database we'll consider is [MyScale](https://myscale.com).\n\n[MyScale](https://myscale.com) is a database built on Clickhouse that combines vector search and SQL analytics to offer a high-performance, streamlined, and fully managed experience. It's designed to facilitate joint queries and analyses on both structured and vector data, with comprehensive SQL support for all data processing.\n\nDeploy and execute vector search with SQL on your cluster within two minutes by using [MyScale Console](https://console.myscale.com).\n\n### Connect to MyScale\n\nFollow the [connections details](https://docs.myscale.com/en/cluster-management/) section to retrieve the cluster host, username, and password information from the MyScale console, and use it to create a connection to your cluster as shown below:\n\n\n```python\n# initialize client\nclient = clickhouse_connect.get_client(host='YOUR_CLUSTER_HOST', port=8443, username='YOUR_USERNAME', password='YOUR_CLUSTER_PASSWORD')\n```\n\n### Index data\n\nWe will create an SQL table called `articles` in MyScale to store the embeddings data. The table will include a vector index with a cosine distance metric and a constraint for the length of the embeddings. Use the following code to create and insert data into the articles table:"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 09b77a37-4a4f-48d9-b734-f0625cf4434d
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/myscale/Using_MyScale_for_embeddings_search.ipynb", "title": "Using MyScale for Embeddings Search", "tokens": 2754, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"09b77a37-4a4f-48d9-b734-f0625cf4434d\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/myscale/Using_MyScale_for_embeddings_search.ipynb\", \"title\": \"Using MyScale for Embeddings Search\", \"tokens\": 2754, \"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\": \"db892807-c113-4bfd-9704-8d93dd9aff1a\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/myscale/Using_MyScale_for_embeddings_search.ipynb\", \"title\": \"Using MyScale for Embeddings Search\", \"tokens\": 2754, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"fd236f6738bea8e07f4ddca6cb76596d7f2c7a3b7052ead7cb5c93156357c356\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"76657275-cb4a-4138-8dc4-4a1363aee852\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/myscale/Using_MyScale_for_embeddings_search.ipynb\", \"title\": \"Using MyScale for Embeddings Search\", \"tokens\": 2754, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"d47d5c114761eea9fc5e27ae93bb6ec88b57f8abd19c1a53d16afcd3254b4e6a\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"2305173c-947b-49d3-89e1-ecf6bfcc9c49\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"61fa91af72ee4f5fd8778ca60338ac801a3bf99a3055b2aa620ede2d6135e6ef\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 6833, \"end_char_idx\": 9998, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "db892807-c113-4bfd-9704-8d93dd9aff1a", "doc_id": "db892807-c113-4bfd-9704-8d93dd9aff1a", "ref_doc_id": "db892807-c113-4bfd-9704-8d93dd9aff1a", "chroma:document": "## MyScale\nThe next vector database we'll consider is [MyScale](https://myscale.com).\n\n[MyScale](https://myscale.com) is a database built on Clickhouse that combines vector search and SQL analytics to offer a high-performance, streamlined, and fully managed experience. It's designed to facilitate joint queries and analyses on both structured and vector data, with comprehensive SQL support for all data processing.\n\nDeploy and execute vector search with SQL on your cluster within two minutes by using [MyScale Console](https://console.myscale.com).\n\n### Connect to MyScale\n\nFollow the [connections details](https://docs.myscale.com/en/cluster-management/) section to retrieve the cluster host, username, and password information from the MyScale console, and use it to create a connection to your cluster as shown below:\n\n\n```python\n# initialize client\nclient = clickhouse_connect.get_client(host='YOUR_CLUSTER_HOST', port=8443, username='YOUR_USERNAME', password='YOUR_CLUSTER_PASSWORD')\n```\n\n### Index data\n\nWe will create an SQL table called `articles` in MyScale to store the embeddings data. The table will include a vector index with a cosine distance metric and a constraint for the length of the embeddings. Use the following code to create and insert data into the articles table:\n\n\n```python\n# create articles table with vector index\nembedding_len=len(article_df['content_vector'][0]) # 1536\n\nclient.command(f\"\"\"\nCREATE TABLE IF NOT EXISTS default.articles\n(\n    id UInt64,\n    url String,\n    title String,\n    text String,\n    content_vector Array(Float32),\n    CONSTRAINT cons_vector_len CHECK length(content_vector) = {embedding_len},\n    VECTOR INDEX article_content_index content_vector TYPE HNSWFLAT('metric_type=Cosine')\n)\nENGINE = MergeTree ORDER BY id\n\"\"\")\n\n# insert data into the table in batches\nfrom tqdm.auto import tqdm\n\nbatch_size = 100\ntotal_records = len(article_df)\n\n# we only need subset of columns\narticle_df = article_df[['id', 'url', 'title', 'text', 'content_vector']]\n\n# upload data in batches\ndata = article_df.to_records(index=False).tolist()\ncolumn_names = article_df.columns.tolist()\n\nfor i in tqdm(range(0, total_records, batch_size)):\n    i_end = min(i + batch_size, total_records)\n    client.insert(\"default.articles\", data[i:i_end], column_names=column_names)\n```\n\n\n      0%|          | 0/250 [00:00<?, ?it/s]\n\n\nWe need to check the build status of the vector index before proceeding with the search, as it is automatically built in the background.\n\n\n```python\n# check count of inserted data\nprint(f\"articles count: {client.command('SELECT count(*) FROM default.articles')}\")\n\n# check the status of the vector index, make sure vector index is ready with 'Built' status\nget_index_status=\"SELECT status FROM system.vector_indices WHERE name='article_content_index'\"\nprint(f\"index build status: {client.command(get_index_status)}\")\n```\n\n    articles count: 25000\n    index build status: InProgress\n\n\n### Search data\n\nOnce indexed in MyScale, we can perform vector search to find similar content. First, we will use the OpenAI API to generate embeddings for our query. Then, we will perform the vector search using MyScale."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 2305173c-947b-49d3-89e1-ecf6bfcc9c49
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/myscale/Using_MyScale_for_embeddings_search.ipynb", "title": "Using MyScale for Embeddings Search", "tokens": 2754, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"2305173c-947b-49d3-89e1-ecf6bfcc9c49\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/myscale/Using_MyScale_for_embeddings_search.ipynb\", \"title\": \"Using MyScale for Embeddings Search\", \"tokens\": 2754, \"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\": \"db892807-c113-4bfd-9704-8d93dd9aff1a\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/myscale/Using_MyScale_for_embeddings_search.ipynb\", \"title\": \"Using MyScale for Embeddings Search\", \"tokens\": 2754, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"fd236f6738bea8e07f4ddca6cb76596d7f2c7a3b7052ead7cb5c93156357c356\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"09b77a37-4a4f-48d9-b734-f0625cf4434d\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/myscale/Using_MyScale_for_embeddings_search.ipynb\", \"title\": \"Using MyScale for Embeddings Search\", \"tokens\": 2754, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"cfd9467fd965c3588e2a5d9696ed8d394806b2e017ae63e0a64e1470d05d9642\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 9151, \"end_char_idx\": 10771, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "db892807-c113-4bfd-9704-8d93dd9aff1a", "doc_id": "db892807-c113-4bfd-9704-8d93dd9aff1a", "ref_doc_id": "db892807-c113-4bfd-9704-8d93dd9aff1a", "chroma:document": "0%|          | 0/250 [00:00<?, ?it/s]\n\n\nWe need to check the build status of the vector index before proceeding with the search, as it is automatically built in the background.\n\n\n```python\n# check count of inserted data\nprint(f\"articles count: {client.command('SELECT count(*) FROM default.articles')}\")\n\n# check the status of the vector index, make sure vector index is ready with 'Built' status\nget_index_status=\"SELECT status FROM system.vector_indices WHERE name='article_content_index'\"\nprint(f\"index build status: {client.command(get_index_status)}\")\n```\n\n    articles count: 25000\n    index build status: InProgress\n\n\n### Search data\n\nOnce indexed in MyScale, we can perform vector search to find similar content. First, we will use the OpenAI API to generate embeddings for our query. Then, we will perform the vector search using MyScale.\n\n\n```python\nquery = \"Famous battles in Scottish history\"\n\n# creates embedding vector from user query\nembed = openai.Embedding.create(\n    input=query,\n    model=\"text-embedding-3-small\",\n)[\"data\"][0][\"embedding\"]\n\n# query the database to find the top K similar content to the given query\ntop_k = 10\nresults = client.query(f\"\"\"\nSELECT id, url, title, distance(content_vector, {embed}) as dist\nFROM default.articles\nORDER BY dist\nLIMIT {top_k}\n\"\"\")\n\n# display results\nfor i, r in enumerate(results.named_results()):\n    print(i+1, r['title'])\n```\n\n    1 Battle of Bannockburn\n    2 Wars of Scottish Independence\n    3 1651\n    4 First War of Scottish Independence\n    5 Robert I of Scotland\n    6 841\n    7 1716\n    8 1314\n    9 1263\n    10 William Wallace\n\n\n\n```python\n\n```"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: b003fc65-fd93-4c6f-ac2a-785f0ca687a9
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/myscale/Getting_started_with_MyScale_and_OpenAI.ipynb", "title": "Using MyScale as a vector database for OpenAI embeddings", "tokens": 1436, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"b003fc65-fd93-4c6f-ac2a-785f0ca687a9\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/myscale/Getting_started_with_MyScale_and_OpenAI.ipynb\", \"title\": \"Using MyScale as a vector database for OpenAI embeddings\", \"tokens\": 1436, \"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\": \"f3e34571-f8ca-4a99-b961-b408dfc39dcc\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/myscale/Getting_started_with_MyScale_and_OpenAI.ipynb\", \"title\": \"Using MyScale as a vector database for OpenAI embeddings\", \"tokens\": 1436, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"b632e784f373b0fcc7ae9a4af37d40088bd2c40a65431319bd4b3f20aa87cfb8\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"fddb1dc3-2a22-4e44-b400-0286e5aad4eb\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"8a76c3a6e64bd14b5ccee4ff2e05899e0b53e7a20c7c6b09d8dbd1d6b8eec0f0\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 0, \"end_char_idx\": 3102, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "f3e34571-f8ca-4a99-b961-b408dfc39dcc", "doc_id": "f3e34571-f8ca-4a99-b961-b408dfc39dcc", "ref_doc_id": "f3e34571-f8ca-4a99-b961-b408dfc39dcc", "chroma:document": "# Using MyScale as a vector database for OpenAI embeddings\n\nThis notebook provides a step-by-step guide on using MyScale as a vector database for OpenAI embeddings. The process includes:\n\n1. Utilizing precomputed embeddings generated by OpenAI API.\n2. Storing these embeddings in a cloud instance of MyScale.\n3. Converting raw text query to an embedding using OpenAI API.\n4. Leveraging MyScale to perform nearest neighbor search within the created collection.\n\n### What is MyScale\n\n[MyScale](https://myscale.com) is a database built on Clickhouse that combines vector search and SQL analytics to offer a high-performance, streamlined, and fully managed experience. It's designed to facilitate joint queries and analyses on both structured and vector data, with comprehensive SQL support for all data processing.\n\n\n### Deployment options\n\n- Deploy and execute vector search with SQL on your cluster within two minutes by using [MyScale Console](https://console.myscale.com).\n\n\n## Prerequisites\n\nTo follow this guide, you will need to have the following:\n\n1. A MyScale cluster deployed by following the [quickstart guide](https://docs.myscale.com/en/quickstart/).\n2. The 'clickhouse-connect' library to interact with MyScale.\n3. An [OpenAI API key](https://beta.openai.com/account/api-keys) for vectorization of queries.\n\n### Install requirements\n\nThis notebook requires the `openai`, `clickhouse-connect`, as well as some other dependencies. Use the following command to install them:\n\n\n```python\n! pip install openai clickhouse-connect wget pandas\n```\n\n### Prepare your OpenAI API key\n\nTo use the OpenAI API, you'll need to set up an API key. If you don't have one already, you can obtain it from [OpenAI](https://platform.openai.com/account/api-keys).\n\n\n```python\nimport openai\n\n# get API key from on OpenAI website\nopenai.api_key = \"OPENAI_API_KEY\"\n\n# check we have authenticated\nopenai.Engine.list()\n```\n\n## Connect to MyScale\n\nFollow the [connections details](https://docs.myscale.com/en/cluster-management/) section to retrieve the cluster host, username, and password information from the MyScale console, and use it to create a connection to your cluster as shown below:\n\n\n```python\nimport clickhouse_connect\n\n# initialize client\nclient = clickhouse_connect.get_client(host='YOUR_CLUSTER_HOST', port=8443, username='YOUR_USERNAME', password='YOUR_CLUSTER_PASSWORD')\n```\n\n## Load data\n\nWe need to load the dataset of precomputed vector embeddings for Wikipedia articles provided by OpenAI. Use the `wget` package to download the dataset.\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\nAfter the download is complete, extract the file using the `zipfile` package:\n\n\n```python\nimport zipfile\n\nwith zipfile.ZipFile(\"vector_database_wikipedia_articles_embedded.zip\", \"r\") as zip_ref:\n    zip_ref.extractall(\"../data\")\n```\n\nNow, we can load the data from `vector_database_wikipedia_articles_embedded.csv` into a Pandas DataFrame:"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: fddb1dc3-2a22-4e44-b400-0286e5aad4eb
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/myscale/Getting_started_with_MyScale_and_OpenAI.ipynb", "title": "Using MyScale as a vector database for OpenAI embeddings", "tokens": 1436, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"fddb1dc3-2a22-4e44-b400-0286e5aad4eb\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/myscale/Getting_started_with_MyScale_and_OpenAI.ipynb\", \"title\": \"Using MyScale as a vector database for OpenAI embeddings\", \"tokens\": 1436, \"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\": \"f3e34571-f8ca-4a99-b961-b408dfc39dcc\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/myscale/Getting_started_with_MyScale_and_OpenAI.ipynb\", \"title\": \"Using MyScale as a vector database for OpenAI embeddings\", \"tokens\": 1436, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"b632e784f373b0fcc7ae9a4af37d40088bd2c40a65431319bd4b3f20aa87cfb8\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"b003fc65-fd93-4c6f-ac2a-785f0ca687a9\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/myscale/Getting_started_with_MyScale_and_OpenAI.ipynb\", \"title\": \"Using MyScale as a vector database for OpenAI embeddings\", \"tokens\": 1436, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"f33a141bc23a2733bfc6ef917a21145de72bc70eb786f9e0bf3d430e8425c106\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"0dbab7de-5272-45d5-ad41-e65cdd88881f\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"6b2f834918e39c5a8b4a72408f93ee070cbc9cf14f0ad2e37a9a14582618fc74\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 1486, \"end_char_idx\": 4833, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "f3e34571-f8ca-4a99-b961-b408dfc39dcc", "doc_id": "f3e34571-f8ca-4a99-b961-b408dfc39dcc", "ref_doc_id": "f3e34571-f8ca-4a99-b961-b408dfc39dcc", "chroma:document": "```python\n! pip install openai clickhouse-connect wget pandas\n```\n\n### Prepare your OpenAI API key\n\nTo use the OpenAI API, you'll need to set up an API key. If you don't have one already, you can obtain it from [OpenAI](https://platform.openai.com/account/api-keys).\n\n\n```python\nimport openai\n\n# get API key from on OpenAI website\nopenai.api_key = \"OPENAI_API_KEY\"\n\n# check we have authenticated\nopenai.Engine.list()\n```\n\n## Connect to MyScale\n\nFollow the [connections details](https://docs.myscale.com/en/cluster-management/) section to retrieve the cluster host, username, and password information from the MyScale console, and use it to create a connection to your cluster as shown below:\n\n\n```python\nimport clickhouse_connect\n\n# initialize client\nclient = clickhouse_connect.get_client(host='YOUR_CLUSTER_HOST', port=8443, username='YOUR_USERNAME', password='YOUR_CLUSTER_PASSWORD')\n```\n\n## Load data\n\nWe need to load the dataset of precomputed vector embeddings for Wikipedia articles provided by OpenAI. Use the `wget` package to download the dataset.\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\nAfter the download is complete, extract the file using the `zipfile` package:\n\n\n```python\nimport zipfile\n\nwith zipfile.ZipFile(\"vector_database_wikipedia_articles_embedded.zip\", \"r\") as zip_ref:\n    zip_ref.extractall(\"../data\")\n```\n\nNow, we can load the data from `vector_database_wikipedia_articles_embedded.csv` into a Pandas DataFrame:\n\n\n```python\nimport pandas as pd\n\nfrom ast import literal_eval\n\n# read data from csv\narticle_df = pd.read_csv('../data/vector_database_wikipedia_articles_embedded.csv')\narticle_df = article_df[['id', 'url', 'title', 'text', 'content_vector']]\n\n# read vectors from strings back into a list\narticle_df[\"content_vector\"] = article_df.content_vector.apply(literal_eval)\narticle_df.head()\n```\n\n## Index data\n\nWe will create an SQL table called `articles` in MyScale to store the embeddings data. The table will include a vector index with a cosine distance metric and a constraint for the length of the embeddings. Use the following code to create and insert data into the articles table:\n\n\n```python\n# create articles table with vector index\nembedding_len=len(article_df['content_vector'][0]) # 1536\n\nclient.command(f\"\"\"\nCREATE TABLE IF NOT EXISTS default.articles\n(\n    id UInt64,\n    url String,\n    title String,\n    text String,\n    content_vector Array(Float32),\n    CONSTRAINT cons_vector_len CHECK length(content_vector) = {embedding_len},\n    VECTOR INDEX article_content_index content_vector TYPE HNSWFLAT('metric_type=Cosine')\n)\nENGINE = MergeTree ORDER BY id\n\"\"\")\n\n# insert data into the table in batches\nfrom tqdm.auto import tqdm\n\nbatch_size = 100\ntotal_records = len(article_df)\n\n# upload data in batches\ndata = article_df.to_records(index=False).tolist()\ncolumn_names = article_df.columns.tolist() \n\nfor i in tqdm(range(0, total_records, batch_size)):\n    i_end = min(i + batch_size, total_records)\n    client.insert(\"default.articles\", data[i:i_end], column_names=column_names)\n```\n\nWe need to check the build status of the vector index before proceeding with the search, as it is automatically built in the background."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 0dbab7de-5272-45d5-ad41-e65cdd88881f
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/myscale/Getting_started_with_MyScale_and_OpenAI.ipynb", "title": "Using MyScale as a vector database for OpenAI embeddings", "tokens": 1436, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"0dbab7de-5272-45d5-ad41-e65cdd88881f\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/myscale/Getting_started_with_MyScale_and_OpenAI.ipynb\", \"title\": \"Using MyScale as a vector database for OpenAI embeddings\", \"tokens\": 1436, \"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\": \"f3e34571-f8ca-4a99-b961-b408dfc39dcc\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/myscale/Getting_started_with_MyScale_and_OpenAI.ipynb\", \"title\": \"Using MyScale as a vector database for OpenAI embeddings\", \"tokens\": 1436, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"b632e784f373b0fcc7ae9a4af37d40088bd2c40a65431319bd4b3f20aa87cfb8\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"fddb1dc3-2a22-4e44-b400-0286e5aad4eb\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/myscale/Getting_started_with_MyScale_and_OpenAI.ipynb\", \"title\": \"Using MyScale as a vector database for OpenAI embeddings\", \"tokens\": 1436, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"21498eff6a29b2ceeca6a0f120bb954b1a15c391662db77734e59ce4e4f1239b\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 3105, \"end_char_idx\": 6286, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "f3e34571-f8ca-4a99-b961-b408dfc39dcc", "doc_id": "f3e34571-f8ca-4a99-b961-b408dfc39dcc", "ref_doc_id": "f3e34571-f8ca-4a99-b961-b408dfc39dcc", "chroma:document": "```python\nimport pandas as pd\n\nfrom ast import literal_eval\n\n# read data from csv\narticle_df = pd.read_csv('../data/vector_database_wikipedia_articles_embedded.csv')\narticle_df = article_df[['id', 'url', 'title', 'text', 'content_vector']]\n\n# read vectors from strings back into a list\narticle_df[\"content_vector\"] = article_df.content_vector.apply(literal_eval)\narticle_df.head()\n```\n\n## Index data\n\nWe will create an SQL table called `articles` in MyScale to store the embeddings data. The table will include a vector index with a cosine distance metric and a constraint for the length of the embeddings. Use the following code to create and insert data into the articles table:\n\n\n```python\n# create articles table with vector index\nembedding_len=len(article_df['content_vector'][0]) # 1536\n\nclient.command(f\"\"\"\nCREATE TABLE IF NOT EXISTS default.articles\n(\n    id UInt64,\n    url String,\n    title String,\n    text String,\n    content_vector Array(Float32),\n    CONSTRAINT cons_vector_len CHECK length(content_vector) = {embedding_len},\n    VECTOR INDEX article_content_index content_vector TYPE HNSWFLAT('metric_type=Cosine')\n)\nENGINE = MergeTree ORDER BY id\n\"\"\")\n\n# insert data into the table in batches\nfrom tqdm.auto import tqdm\n\nbatch_size = 100\ntotal_records = len(article_df)\n\n# upload data in batches\ndata = article_df.to_records(index=False).tolist()\ncolumn_names = article_df.columns.tolist() \n\nfor i in tqdm(range(0, total_records, batch_size)):\n    i_end = min(i + batch_size, total_records)\n    client.insert(\"default.articles\", data[i:i_end], column_names=column_names)\n```\n\nWe need to check the build status of the vector index before proceeding with the search, as it is automatically built in the background.\n\n\n```python\n# check count of inserted data\nprint(f\"articles count: {client.command('SELECT count(*) FROM default.articles')}\")\n\n# check the status of the vector index, make sure vector index is ready with 'Built' status\nget_index_status=\"SELECT status FROM system.vector_indices WHERE name='article_content_index'\"\nprint(f\"index build status: {client.command(get_index_status)}\")\n```\n\n    articles count: 25000\n    index build status: Built\n\n\n## Search data\n\nOnce indexed in MyScale, we can perform vector search to find similar content. First, we will use the OpenAI API to generate embeddings for our query. Then, we will perform the vector search using MyScale.\n\n\n```python\nimport openai\n\nquery = \"Famous battles in Scottish history\"\n\n# creates embedding vector from user query\nembed = openai.Embedding.create(\n    input=query,\n    model=\"text-embedding-3-small\",\n)[\"data\"][0][\"embedding\"]\n\n# query the database to find the top K similar content to the given query\ntop_k = 10\nresults = client.query(f\"\"\"\nSELECT id, url, title, distance(content_vector, {embed}) as dist\nFROM default.articles\nORDER BY dist\nLIMIT {top_k}\n\"\"\")\n\n# display results\nfor i, r in enumerate(results.named_results()):\n    print(i+1, r['title'])\n```\n\n    1 Battle of Bannockburn\n    2 Wars of Scottish Independence\n    3 1651\n    4 First War of Scottish Independence\n    5 Robert I of Scotland\n    6 841\n    7 1716\n    8 1314\n    9 1263\n    10 William Wallace\n\n\n\n```python\n\n```"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 183a08f5-cf64-4c67-96c9-e672864361b8
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb", "title": "Getting Started with Zilliz and OpenAI", "tokens": 5622, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"183a08f5-cf64-4c67-96c9-e672864361b8\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Getting Started with Zilliz and OpenAI\", \"tokens\": 5622, \"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\": \"82976ccf-0844-46c4-bf27-ab24c7c51718\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Getting Started with Zilliz and OpenAI\", \"tokens\": 5622, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"b6c5f2c6d1fb2f4a10d0884c8ce3c2f5bff33cf9a04dcde31e91b606e959845a\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"3ea895ac-b9bf-464d-bdb1-6a428eab38a9\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"94393d94dbf96973f2a08f44bb33ee84468dd8905e7524ff1ae7a5c76f79ab3b\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 0, \"end_char_idx\": 2545, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "82976ccf-0844-46c4-bf27-ab24c7c51718", "doc_id": "82976ccf-0844-46c4-bf27-ab24c7c51718", "ref_doc_id": "82976ccf-0844-46c4-bf27-ab24c7c51718", "chroma:document": "# Getting Started with Zilliz and OpenAI\n### Finding your next book\n\nIn this notebook we will be going over generating embeddings of book descriptions with OpenAI and using those embeddings within Zilliz to find relevant books. The dataset in this example is sourced from HuggingFace datasets, and contains a little over 1 million title-description pairs.\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 Zilliz instance\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\n    Looking in indexes: https://pypi.org/simple, https://pypi.ngc.nvidia.com\n    Requirement already satisfied: openai in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (0.27.2)\n    Requirement already satisfied: pymilvus in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (2.2.2)\n    Requirement already satisfied: datasets in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (2.10.1)\n    Requirement already satisfied: tqdm in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (4.64.1)\n    Requirement already satisfied: requests>=2.20 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from openai) (2.28.2)\n    Requirement already satisfied: aiohttp in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from openai) (3.8.4)\n    Requirement already satisfied: ujson<=5.4.0,>=2.0.0 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from pymilvus) (5.1.0)\n    Requirement already satisfied: grpcio-tools<=1.48.0,>=1.47.0 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from pymilvus) (1.47.2)\n    Requirement already satisfied: grpcio<=1.48.0,>=1.47.0 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from pymilvus) (1.47.2)\n    Requirement already satisfied: mmh3<=3.0.0,>=2.0 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from pymilvus) (3.0.0)\n    Requirement already satisfied: pandas>=1.2.4 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from pymilvus) (1.5.3)\n    Requirement already satisfied: numpy>=1.17 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from datasets) (1.23."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 3ea895ac-b9bf-464d-bdb1-6a428eab38a9
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb", "title": "Getting Started with Zilliz and OpenAI", "tokens": 5622, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"3ea895ac-b9bf-464d-bdb1-6a428eab38a9\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Getting Started with Zilliz and OpenAI\", \"tokens\": 5622, \"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\": \"82976ccf-0844-46c4-bf27-ab24c7c51718\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Getting Started with Zilliz and OpenAI\", \"tokens\": 5622, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"b6c5f2c6d1fb2f4a10d0884c8ce3c2f5bff33cf9a04dcde31e91b606e959845a\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"183a08f5-cf64-4c67-96c9-e672864361b8\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Getting Started with Zilliz and OpenAI\", \"tokens\": 5622, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"acf9e7fed1517ea47eb2d8d4e7bbc02e1edc7ec037a8499def13d609157bdffb\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"ac49cf29-ba02-44c4-a96b-f69e9ec1b18e\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"793c1173d057a697c7b7b16d1877283157031865aa64b7da6ce53cd3487f6780\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 1422, \"end_char_idx\": 3680, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "82976ccf-0844-46c4-bf27-ab24c7c51718", "doc_id": "82976ccf-0844-46c4-bf27-ab24c7c51718", "ref_doc_id": "82976ccf-0844-46c4-bf27-ab24c7c51718", "chroma:document": "9/site-packages (from openai) (2.28.2)\n    Requirement already satisfied: aiohttp in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from openai) (3.8.4)\n    Requirement already satisfied: ujson<=5.4.0,>=2.0.0 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from pymilvus) (5.1.0)\n    Requirement already satisfied: grpcio-tools<=1.48.0,>=1.47.0 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from pymilvus) (1.47.2)\n    Requirement already satisfied: grpcio<=1.48.0,>=1.47.0 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from pymilvus) (1.47.2)\n    Requirement already satisfied: mmh3<=3.0.0,>=2.0 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from pymilvus) (3.0.0)\n    Requirement already satisfied: pandas>=1.2.4 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from pymilvus) (1.5.3)\n    Requirement already satisfied: numpy>=1.17 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from datasets) (1.23.5)\n    Requirement already satisfied: xxhash in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from datasets) (3.2.0)\n    Requirement already satisfied: responses<0.19 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from datasets) (0.18.0)\n    Requirement already satisfied: dill<0.3.7,>=0.3.0 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from datasets) (0.3.6)\n    Requirement already satisfied: huggingface-hub<1.0.0,>=0.2.0 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from datasets) (0.12.1)\n    Requirement already satisfied: pyarrow>=6.0.0 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from datasets) (10.0.1)\n    Requirement already satisfied: multiprocess in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from datasets) (0.70.14)\n    Requirement already satisfied: pyyaml>=5.1 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from datasets) (5.4.1)\n    Requirement already satisfied: fsspec[http]>=2021.11."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: ac49cf29-ba02-44c4-a96b-f69e9ec1b18e
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb", "title": "Getting Started with Zilliz and OpenAI", "tokens": 5622, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"ac49cf29-ba02-44c4-a96b-f69e9ec1b18e\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Getting Started with Zilliz and OpenAI\", \"tokens\": 5622, \"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\": \"82976ccf-0844-46c4-bf27-ab24c7c51718\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Getting Started with Zilliz and OpenAI\", \"tokens\": 5622, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"b6c5f2c6d1fb2f4a10d0884c8ce3c2f5bff33cf9a04dcde31e91b606e959845a\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"3ea895ac-b9bf-464d-bdb1-6a428eab38a9\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Getting Started with Zilliz and OpenAI\", \"tokens\": 5622, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"ac7b42538ae6baa8b0a5410a6c47ec16faa159d891e112e7d4abda375e9a29cc\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"f37cdeab-9bd7-4280-9310-554f35733af9\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"b38132ee4c7934debc6ef3b4d91632fe3f883876a8c25bef4fe996afcfa643c3\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 2442, \"end_char_idx\": 4804, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "82976ccf-0844-46c4-bf27-ab24c7c51718", "doc_id": "82976ccf-0844-46c4-bf27-ab24c7c51718", "ref_doc_id": "82976ccf-0844-46c4-bf27-ab24c7c51718", "chroma:document": "17 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from datasets) (1.23.5)\n    Requirement already satisfied: xxhash in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from datasets) (3.2.0)\n    Requirement already satisfied: responses<0.19 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from datasets) (0.18.0)\n    Requirement already satisfied: dill<0.3.7,>=0.3.0 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from datasets) (0.3.6)\n    Requirement already satisfied: huggingface-hub<1.0.0,>=0.2.0 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from datasets) (0.12.1)\n    Requirement already satisfied: pyarrow>=6.0.0 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from datasets) (10.0.1)\n    Requirement already satisfied: multiprocess in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from datasets) (0.70.14)\n    Requirement already satisfied: pyyaml>=5.1 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from datasets) (5.4.1)\n    Requirement already satisfied: fsspec[http]>=2021.11.1 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from datasets) (2023.1.0)\n    Requirement already satisfied: packaging in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from datasets) (23.0)\n    Requirement already satisfied: frozenlist>=1.1.1 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from aiohttp->openai) (1.3.3)\n    Requirement already satisfied: async-timeout<5.0,>=4.0.0a3 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from aiohttp->openai) (4.0.2)\n    Requirement already satisfied: aiosignal>=1.1.2 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from aiohttp->openai) (1.3.1)\n    Requirement already satisfied: attrs>=17.3.0 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from aiohttp->openai) (22.2.0)\n    Requirement already satisfied: charset-normalizer<4.0,>=2.0 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from aiohttp->openai) (3.0.1)\n    Requirement already satisfied: yarl<2.0,"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: f37cdeab-9bd7-4280-9310-554f35733af9
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb", "title": "Getting Started with Zilliz and OpenAI", "tokens": 5622, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"f37cdeab-9bd7-4280-9310-554f35733af9\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Getting Started with Zilliz and OpenAI\", \"tokens\": 5622, \"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\": \"82976ccf-0844-46c4-bf27-ab24c7c51718\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Getting Started with Zilliz and OpenAI\", \"tokens\": 5622, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"b6c5f2c6d1fb2f4a10d0884c8ce3c2f5bff33cf9a04dcde31e91b606e959845a\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"ac49cf29-ba02-44c4-a96b-f69e9ec1b18e\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Getting Started with Zilliz and OpenAI\", \"tokens\": 5622, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"a57ab2c1e9cb75fd97f5f25b6f71b7585a6a65c5182a99479d5909c2d254406e\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"fca21344-8502-40b3-86dc-c0809cbcc646\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"86ee24fa828472193a329b5d1293c42eed72a0982f37a71454a210f8f4c3a8cb\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 3583, \"end_char_idx\": 5805, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "82976ccf-0844-46c4-bf27-ab24c7c51718", "doc_id": "82976ccf-0844-46c4-bf27-ab24c7c51718", "ref_doc_id": "82976ccf-0844-46c4-bf27-ab24c7c51718", "chroma:document": "9/site-packages (from datasets) (5.4.1)\n    Requirement already satisfied: fsspec[http]>=2021.11.1 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from datasets) (2023.1.0)\n    Requirement already satisfied: packaging in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from datasets) (23.0)\n    Requirement already satisfied: frozenlist>=1.1.1 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from aiohttp->openai) (1.3.3)\n    Requirement already satisfied: async-timeout<5.0,>=4.0.0a3 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from aiohttp->openai) (4.0.2)\n    Requirement already satisfied: aiosignal>=1.1.2 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from aiohttp->openai) (1.3.1)\n    Requirement already satisfied: attrs>=17.3.0 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from aiohttp->openai) (22.2.0)\n    Requirement already satisfied: charset-normalizer<4.0,>=2.0 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from aiohttp->openai) (3.0.1)\n    Requirement already satisfied: yarl<2.0,>=1.0 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from aiohttp->openai) (1.8.2)\n    Requirement already satisfied: multidict<7.0,>=4.5 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from aiohttp->openai) (6.0.4)\n    Requirement already satisfied: six>=1.5.2 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from grpcio<=1.48.0,>=1.47.0->pymilvus) (1.16.0)\n    Requirement already satisfied: protobuf<4.0dev,>=3.12.0 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from grpcio-tools<=1.48.0,>=1.47.0->pymilvus) (3.20.1)\n    Requirement already satisfied: setuptools in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from grpcio-tools<=1.48.0,>=1.47.0->pymilvus) (65.6.3)\n    Requirement already satisfied: typing-extensions>=3.7.4.3 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from huggingface-hub<1.0.0,>=0.2."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: fca21344-8502-40b3-86dc-c0809cbcc646
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb", "title": "Getting Started with Zilliz and OpenAI", "tokens": 5622, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"fca21344-8502-40b3-86dc-c0809cbcc646\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Getting Started with Zilliz and OpenAI\", \"tokens\": 5622, \"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\": \"82976ccf-0844-46c4-bf27-ab24c7c51718\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Getting Started with Zilliz and OpenAI\", \"tokens\": 5622, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"b6c5f2c6d1fb2f4a10d0884c8ce3c2f5bff33cf9a04dcde31e91b606e959845a\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"f37cdeab-9bd7-4280-9310-554f35733af9\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Getting Started with Zilliz and OpenAI\", \"tokens\": 5622, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"5f71d277c5719a9d2b93766401ca64f86f9aa3bc64bf00f9e06e29288437a415\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"9c7fe386-48d0-4a33-8ef8-96d0aebbf422\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"57939f9c9a9f8dba31243cd8861a5cc10c2daee5cb239cf4c2188d4daf93ab76\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 4713, \"end_char_idx\": 6854, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "82976ccf-0844-46c4-bf27-ab24c7c51718", "doc_id": "82976ccf-0844-46c4-bf27-ab24c7c51718", "ref_doc_id": "82976ccf-0844-46c4-bf27-ab24c7c51718", "chroma:document": "9/site-packages (from aiohttp->openai) (3.0.1)\n    Requirement already satisfied: yarl<2.0,>=1.0 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from aiohttp->openai) (1.8.2)\n    Requirement already satisfied: multidict<7.0,>=4.5 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from aiohttp->openai) (6.0.4)\n    Requirement already satisfied: six>=1.5.2 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from grpcio<=1.48.0,>=1.47.0->pymilvus) (1.16.0)\n    Requirement already satisfied: protobuf<4.0dev,>=3.12.0 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from grpcio-tools<=1.48.0,>=1.47.0->pymilvus) (3.20.1)\n    Requirement already satisfied: setuptools in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from grpcio-tools<=1.48.0,>=1.47.0->pymilvus) (65.6.3)\n    Requirement already satisfied: typing-extensions>=3.7.4.3 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from huggingface-hub<1.0.0,>=0.2.0->datasets) (4.5.0)\n    Requirement already satisfied: filelock in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from huggingface-hub<1.0.0,>=0.2.0->datasets) (3.9.0)\n    Requirement already satisfied: python-dateutil>=2.8.1 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from pandas>=1.2.4->pymilvus) (2.8.2)\n    Requirement already satisfied: pytz>=2020.1 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from pandas>=1.2.4->pymilvus) (2022.7.1)\n    Requirement already satisfied: urllib3<1.27,>=1.21.1 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from requests>=2.20->openai) (1.26.14)\n    Requirement already satisfied: idna<4,>=2.5 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from requests>=2.20->openai) (3.4)\n    Requirement already satisfied: certifi>=2017.4.17 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from requests>=2.20->openai) (2022.12."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 9c7fe386-48d0-4a33-8ef8-96d0aebbf422
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb", "title": "Getting Started with Zilliz and OpenAI", "tokens": 5622, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"9c7fe386-48d0-4a33-8ef8-96d0aebbf422\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Getting Started with Zilliz and OpenAI\", \"tokens\": 5622, \"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\": \"82976ccf-0844-46c4-bf27-ab24c7c51718\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Getting Started with Zilliz and OpenAI\", \"tokens\": 5622, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"b6c5f2c6d1fb2f4a10d0884c8ce3c2f5bff33cf9a04dcde31e91b606e959845a\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"fca21344-8502-40b3-86dc-c0809cbcc646\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Getting Started with Zilliz and OpenAI\", \"tokens\": 5622, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"928535087a30fa5d4401c38142b0894aeb6dfe0ceb6c52e010b473073171a03b\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"ad5b77fa-247a-4809-b93a-ab45a32aa30c\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"522f0f87a1b2028b2c7c178f4b0e20f9999c6b94114c7d38e9052b39684d96ad\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 5755, \"end_char_idx\": 8209, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "82976ccf-0844-46c4-bf27-ab24c7c51718", "doc_id": "82976ccf-0844-46c4-bf27-ab24c7c51718", "ref_doc_id": "82976ccf-0844-46c4-bf27-ab24c7c51718", "chroma:document": "9/site-packages (from huggingface-hub<1.0.0,>=0.2.0->datasets) (4.5.0)\n    Requirement already satisfied: filelock in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from huggingface-hub<1.0.0,>=0.2.0->datasets) (3.9.0)\n    Requirement already satisfied: python-dateutil>=2.8.1 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from pandas>=1.2.4->pymilvus) (2.8.2)\n    Requirement already satisfied: pytz>=2020.1 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from pandas>=1.2.4->pymilvus) (2022.7.1)\n    Requirement already satisfied: urllib3<1.27,>=1.21.1 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from requests>=2.20->openai) (1.26.14)\n    Requirement already satisfied: idna<4,>=2.5 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from requests>=2.20->openai) (3.4)\n    Requirement already satisfied: certifi>=2017.4.17 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from requests>=2.20->openai) (2022.12.7)\n\n\nTo get Zilliz up and running take a look [here](https://zilliz.com/doc/quick_start). With your account and database set up, proceed to set the following values:\n- URI: The URI your database is running on\n- USER: Your database username\n- PASSWORD: Your database password\n- COLLECTION_NAME: What to name the collection within Zilliz\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 texts to embed and insert at once\n\n\n```python\nimport openai\n\nURI = 'your_uri'\nTOKEN = 'your_token' # TOKEN == user:password or api_key\nCOLLECTION_NAME = 'book_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':\"AUTOINDEX\",\n    'params':{}\n}\n\nQUERY_PARAM = {\n    \"metric_type\": \"L2\",\n    \"params\": {},\n}\n\nBATCH_SIZE = 1000\n```\n\n## Zilliz\nThis segment deals with Zilliz and setting up the database for this use case. Within Zilliz we need to setup a collection and index it.\n\n\n```python\nfrom pymilvus import connections, utility, FieldSchema, Collection, CollectionSchema, DataType\n\n# Connect to Zilliz Database\nconnections.connect(uri=URI, token=TOKEN)\n```"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: ad5b77fa-247a-4809-b93a-ab45a32aa30c
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb", "title": "Getting Started with Zilliz and OpenAI", "tokens": 5622, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"ad5b77fa-247a-4809-b93a-ab45a32aa30c\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Getting Started with Zilliz and OpenAI\", \"tokens\": 5622, \"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\": \"82976ccf-0844-46c4-bf27-ab24c7c51718\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Getting Started with Zilliz and OpenAI\", \"tokens\": 5622, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"b6c5f2c6d1fb2f4a10d0884c8ce3c2f5bff33cf9a04dcde31e91b606e959845a\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"9c7fe386-48d0-4a33-8ef8-96d0aebbf422\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Getting Started with Zilliz and OpenAI\", \"tokens\": 5622, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"1e317fac7235ba2ad3b5ae617dfb0685762c58a84f847ef69b202e1a81dc9e97\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"7765b3da-4c39-4f0d-b5e6-c174d5c8d0a9\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"f22d726b9ef6cee8ebf19bf63ec633a4cf9dac904383b68174236ca0c3e623c4\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 6732, \"end_char_idx\": 9384, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "82976ccf-0844-46c4-bf27-ab24c7c51718", "doc_id": "82976ccf-0844-46c4-bf27-ab24c7c51718", "ref_doc_id": "82976ccf-0844-46c4-bf27-ab24c7c51718", "chroma:document": "4.17 in /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages (from requests>=2.20->openai) (2022.12.7)\n\n\nTo get Zilliz up and running take a look [here](https://zilliz.com/doc/quick_start). With your account and database set up, proceed to set the following values:\n- URI: The URI your database is running on\n- USER: Your database username\n- PASSWORD: Your database password\n- COLLECTION_NAME: What to name the collection within Zilliz\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 texts to embed and insert at once\n\n\n```python\nimport openai\n\nURI = 'your_uri'\nTOKEN = 'your_token' # TOKEN == user:password or api_key\nCOLLECTION_NAME = 'book_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':\"AUTOINDEX\",\n    'params':{}\n}\n\nQUERY_PARAM = {\n    \"metric_type\": \"L2\",\n    \"params\": {},\n}\n\nBATCH_SIZE = 1000\n```\n\n## Zilliz\nThis segment deals with Zilliz and setting up the database for this use case. Within Zilliz we need to setup a collection and index it.\n\n\n```python\nfrom pymilvus import connections, utility, FieldSchema, Collection, CollectionSchema, DataType\n\n# Connect to Zilliz Database\nconnections.connect(uri=URI, token=TOKEN)\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='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 Zilliz 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 Skelebor's book dataset. This dataset contains title-description pairs for over 1 million books. We are going to embed each description and store it within Zilliz along with its title."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 7765b3da-4c39-4f0d-b5e6-c174d5c8d0a9
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb", "title": "Getting Started with Zilliz and OpenAI", "tokens": 5622, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"7765b3da-4c39-4f0d-b5e6-c174d5c8d0a9\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Getting Started with Zilliz and OpenAI\", \"tokens\": 5622, \"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\": \"82976ccf-0844-46c4-bf27-ab24c7c51718\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Getting Started with Zilliz and OpenAI\", \"tokens\": 5622, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"b6c5f2c6d1fb2f4a10d0884c8ce3c2f5bff33cf9a04dcde31e91b606e959845a\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"ad5b77fa-247a-4809-b93a-ab45a32aa30c\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Getting Started with Zilliz and OpenAI\", \"tokens\": 5622, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"cd1ef2bb697a5a9a54ad66d7746e1477f9bf6b2cdcaba543d9e100dc6ba1989c\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"62a9303b-d27a-4532-8b98-7ca3066e4138\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"7e32e021cb43564c9d7db39cffb1dc1bdce380941588321cef36d0d6a183688e\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 8029, \"end_char_idx\": 10865, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "82976ccf-0844-46c4-bf27-ab24c7c51718", "doc_id": "82976ccf-0844-46c4-bf27-ab24c7c51718", "ref_doc_id": "82976ccf-0844-46c4-bf27-ab24c7c51718", "chroma:document": "```python\nfrom pymilvus import connections, utility, FieldSchema, Collection, CollectionSchema, DataType\n\n# Connect to Zilliz Database\nconnections.connect(uri=URI, token=TOKEN)\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='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 Zilliz 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 Skelebor's book dataset. This dataset contains title-description pairs for over 1 million books. We are going to embed each description and store it within Zilliz along with its title.\n\n\n```python\nimport datasets\n\n# Download the dataset and only use the `train` portion (file is around 800Mb)\ndataset = datasets.load_dataset('Skelebor/book_titles_and_descriptions_en_clean', split='train')\n```\n\n    /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages/tqdm/auto.py:22: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n      from .autonotebook import tqdm as notebook_tqdm\n    Found cached dataset parquet (/Users/filiphaltmayer/.cache/huggingface/datasets/Skelebor___parquet/Skelebor--book_titles_and_descriptions_en_clean-3596935b1d8a7747/0.0.0/2a3b91fbd88a2c90d1dbbb32b460cf621d31bd5b05b934492fdef7d8d6f236ec)\n\n\n## Insert the Data\nNow that we have our data on our machine we can begin embedding it and inserting it into Zilliz. 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. Due to having so many datapoints, if you want to immediately 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."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 62a9303b-d27a-4532-8b98-7ca3066e4138
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb", "title": "Getting Started with Zilliz and OpenAI", "tokens": 5622, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"62a9303b-d27a-4532-8b98-7ca3066e4138\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Getting Started with Zilliz and OpenAI\", \"tokens\": 5622, \"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\": \"82976ccf-0844-46c4-bf27-ab24c7c51718\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Getting Started with Zilliz and OpenAI\", \"tokens\": 5622, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"b6c5f2c6d1fb2f4a10d0884c8ce3c2f5bff33cf9a04dcde31e91b606e959845a\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"7765b3da-4c39-4f0d-b5e6-c174d5c8d0a9\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Getting Started with Zilliz and OpenAI\", \"tokens\": 5622, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"6a216533def6b31b3162179683aad1e56edc1d23239a115d730358e607c2831b\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"fcc7c584-24b2-4986-9137-b9c798c7002b\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"742f91e58dcf19a4db25e3f50037b18c0f8b68482423e20deeaff18718ff21a5\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 9387, \"end_char_idx\": 11852, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "82976ccf-0844-46c4-bf27-ab24c7c51718", "doc_id": "82976ccf-0844-46c4-bf27-ab24c7c51718", "ref_doc_id": "82976ccf-0844-46c4-bf27-ab24c7c51718", "chroma:document": "```python\nimport datasets\n\n# Download the dataset and only use the `train` portion (file is around 800Mb)\ndataset = datasets.load_dataset('Skelebor/book_titles_and_descriptions_en_clean', split='train')\n```\n\n    /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages/tqdm/auto.py:22: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n      from .autonotebook import tqdm as notebook_tqdm\n    Found cached dataset parquet (/Users/filiphaltmayer/.cache/huggingface/datasets/Skelebor___parquet/Skelebor--book_titles_and_descriptions_en_clean-3596935b1d8a7747/0.0.0/2a3b91fbd88a2c90d1dbbb32b460cf621d31bd5b05b934492fdef7d8d6f236ec)\n\n\n## Insert the Data\nNow that we have our data on our machine we can begin embedding it and inserting it into Zilliz. 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. Due to having so many datapoints, if you want to immediately 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%|          | 2999/1032335 [00:19<1:49:30, 156.66it/s]\n\n\n\n    ---------------------------------------------------------------------------\n\n    KeyboardInterrupt                         Traceback (most recent call last)\n\n    Cell In[10], line 14\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         17 # Embed and insert the remainder"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: fcc7c584-24b2-4986-9137-b9c798c7002b
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb", "title": "Getting Started with Zilliz and OpenAI", "tokens": 5622, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"fcc7c584-24b2-4986-9137-b9c798c7002b\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Getting Started with Zilliz and OpenAI\", \"tokens\": 5622, \"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\": \"82976ccf-0844-46c4-bf27-ab24c7c51718\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Getting Started with Zilliz and OpenAI\", \"tokens\": 5622, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"b6c5f2c6d1fb2f4a10d0884c8ce3c2f5bff33cf9a04dcde31e91b606e959845a\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"62a9303b-d27a-4532-8b98-7ca3066e4138\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Getting Started with Zilliz and OpenAI\", \"tokens\": 5622, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"0c524b21667ce6a15cfd6da8b6b2ac0c814db9eb93a49c09de289c92089a3283\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"6013faef-6501-4699-bbe6-6b3347c408bc\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"4d2e5cfe3a0819a852554f9530ee7b0906b71dc9572645ca59703f21d5bc8f51\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 10325, \"end_char_idx\": 13105, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "82976ccf-0844-46c4-bf27-ab24c7c51718", "doc_id": "82976ccf-0844-46c4-bf27-ab24c7c51718", "ref_doc_id": "82976ccf-0844-46c4-bf27-ab24c7c51718", "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 immediately 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%|          | 2999/1032335 [00:19<1:49:30, 156.66it/s]\n\n\n\n    ---------------------------------------------------------------------------\n\n    KeyboardInterrupt                         Traceback (most recent call last)\n\n    Cell In[10], line 14\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         17 # Embed and insert the remainder \n\n\n    File ~/miniconda3/envs/haystack/lib/python3.9/site-packages/pymilvus/orm/collection.py:430, in Collection.insert(self, data, partition_name, timeout, **kwargs)\n        427 entities = Prepare.prepare_insert_data(data, self._schema)\n        429 conn = self._get_connection()\n    --> 430 res = conn.batch_insert(self._name, entities, partition_name,\n        431                         timeout=timeout, schema=self._schema_dict, **kwargs)\n        433 if kwargs.get(\"_async\", False):\n        434     return MutationFuture(res)\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"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 6013faef-6501-4699-bbe6-6b3347c408bc
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb", "title": "Getting Started with Zilliz and OpenAI", "tokens": 5622, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"6013faef-6501-4699-bbe6-6b3347c408bc\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Getting Started with Zilliz and OpenAI\", \"tokens\": 5622, \"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\": \"82976ccf-0844-46c4-bf27-ab24c7c51718\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Getting Started with Zilliz and OpenAI\", \"tokens\": 5622, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"b6c5f2c6d1fb2f4a10d0884c8ce3c2f5bff33cf9a04dcde31e91b606e959845a\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"fcc7c584-24b2-4986-9137-b9c798c7002b\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Getting Started with Zilliz and OpenAI\", \"tokens\": 5622, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"c49403231652a2d90380782417a821323b4e2fda7eb780d97f689992e3569e60\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"8b6d4e64-0006-42df-b1df-b31818ffedbb\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"6767872afd7037435e62778bcd115e3866e6674730df2c9595788366ee9913ca\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 11860, \"end_char_idx\": 14841, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "82976ccf-0844-46c4-bf27-ab24c7c51718", "doc_id": "82976ccf-0844-46c4-bf27-ab24c7c51718", "ref_doc_id": "82976ccf-0844-46c4-bf27-ab24c7c51718", "chroma:document": "File ~/miniconda3/envs/haystack/lib/python3.9/site-packages/pymilvus/orm/collection.py:430, in Collection.insert(self, data, partition_name, timeout, **kwargs)\n        427 entities = Prepare.prepare_insert_data(data, self._schema)\n        429 conn = self._get_connection()\n    --> 430 res = conn.batch_insert(self._name, entities, partition_name,\n        431                         timeout=timeout, schema=self._schema_dict, **kwargs)\n        433 if kwargs.get(\"_async\", False):\n        434     return MutationFuture(res)\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: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:378, in GrpcHandler.batch_insert(self, collection_name, entities, partition_name, timeout, **kwargs)\n        375     f.add_callback(ts_utils.update_ts_on_mutation(collection_name))\n        376     return f\n    --> 378 response = rf.result()\n        379 if response.status.error_code == 0:\n        380     m = MutationResult(response)\n\n\n    File ~/miniconda3/envs/haystack/lib/python3.9/site-packages/grpc/_channel.py:733, in _MultiThreadedRendezvous.result(self, timeout)\n        728 \"\"\"Returns the result of the computation or raises its exception.\n        729 \n        730 See grpc.Future.result for the full API contract.\n        731 \"\"\"\n        732 with self._state.condition:\n    --> 733     timed_out = _common.wait(self._state.condition.wait,\n        734                              self._is_complete,\n        735                              timeout=timeout)\n        736     if timed_out:\n        737         raise grpc.FutureTimeoutError()"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 8b6d4e64-0006-42df-b1df-b31818ffedbb
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb", "title": "Getting Started with Zilliz and OpenAI", "tokens": 5622, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"8b6d4e64-0006-42df-b1df-b31818ffedbb\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Getting Started with Zilliz and OpenAI\", \"tokens\": 5622, \"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\": \"82976ccf-0844-46c4-bf27-ab24c7c51718\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Getting Started with Zilliz and OpenAI\", \"tokens\": 5622, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"b6c5f2c6d1fb2f4a10d0884c8ce3c2f5bff33cf9a04dcde31e91b606e959845a\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"6013faef-6501-4699-bbe6-6b3347c408bc\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Getting Started with Zilliz and OpenAI\", \"tokens\": 5622, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"a500f5c67d85a5d1c70232d760ab8ec669bb5ecf9fc4fd551fc1aba1fe0312d8\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"95aa88f8-b557-42bf-898f-ef48616428a5\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"7244597802fabfc2c67ceb47db7815fdd92be822f4dd1f6847aaafb29e408955\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 13800, \"end_char_idx\": 16697, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "82976ccf-0844-46c4-bf27-ab24c7c51718", "doc_id": "82976ccf-0844-46c4-bf27-ab24c7c51718", "ref_doc_id": "82976ccf-0844-46c4-bf27-ab24c7c51718", "chroma:document": "File ~/miniconda3/envs/haystack/lib/python3.9/site-packages/pymilvus/client/grpc_handler.py:378, in GrpcHandler.batch_insert(self, collection_name, entities, partition_name, timeout, **kwargs)\n        375     f.add_callback(ts_utils.update_ts_on_mutation(collection_name))\n        376     return f\n    --> 378 response = rf.result()\n        379 if response.status.error_code == 0:\n        380     m = MutationResult(response)\n\n\n    File ~/miniconda3/envs/haystack/lib/python3.9/site-packages/grpc/_channel.py:733, in _MultiThreadedRendezvous.result(self, timeout)\n        728 \"\"\"Returns the result of the computation or raises its exception.\n        729 \n        730 See grpc.Future.result for the full API contract.\n        731 \"\"\"\n        732 with self._state.condition:\n    --> 733     timed_out = _common.wait(self._state.condition.wait,\n        734                              self._is_complete,\n        735                              timeout=timeout)\n        736     if timed_out:\n        737         raise grpc.FutureTimeoutError()\n\n\n    File ~/miniconda3/envs/haystack/lib/python3.9/site-packages/grpc/_common.py:141, in wait(wait_fn, wait_complete_fn, timeout, spin_cb)\n        139 if timeout is None:\n        140     while not wait_complete_fn():\n    --> 141         _wait_once(wait_fn, MAXIMUM_WAIT_TIMEOUT, spin_cb)\n        142 else:\n        143     end = time.time() + timeout\n\n\n    File ~/miniconda3/envs/haystack/lib/python3.9/site-packages/grpc/_common.py:106, in _wait_once(wait_fn, timeout, spin_cb)\n        105 def _wait_once(wait_fn, timeout, spin_cb):\n    --> 106     wait_fn(timeout=timeout)\n        107     if spin_cb is not None:\n        108         spin_cb()\n\n\n    File ~/miniconda3/envs/haystack/lib/python3.9/threading.py:316, in Condition.wait(self, timeout)\n        314 else:\n        315     if timeout > 0:\n    --> 316         gotit = waiter.acquire(True, timeout)\n        317     else:\n        318         gotit = waiter.acquire(False)\n\n\n    KeyboardInterrupt: \n\n\n## Query the Database\nWith our data safely inserted in Zilliz, we can now perform a query. The query takes in a string or a list of strings and searches them. The results 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-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 95aa88f8-b557-42bf-898f-ef48616428a5
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb", "title": "Getting Started with Zilliz and OpenAI", "tokens": 5622, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"95aa88f8-b557-42bf-898f-ef48616428a5\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Getting Started with Zilliz and OpenAI\", \"tokens\": 5622, \"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\": \"82976ccf-0844-46c4-bf27-ab24c7c51718\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Getting Started with Zilliz and OpenAI\", \"tokens\": 5622, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"b6c5f2c6d1fb2f4a10d0884c8ce3c2f5bff33cf9a04dcde31e91b606e959845a\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"8b6d4e64-0006-42df-b1df-b31818ffedbb\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Getting Started with Zilliz and OpenAI\", \"tokens\": 5622, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"a94d6b4a4ae88434b4592024b806ef13cb652ba4cacb99d1e7280e9ac8bedb0f\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"60dd6255-bd32-4e1d-a39a-3191683b8ded\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"b34ff5d24f9ea8c12c0c6d6cca57060dee9c0292f3dc74eb1c42d8b41eba08a5\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 15199, \"end_char_idx\": 18111, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "82976ccf-0844-46c4-bf27-ab24c7c51718", "doc_id": "82976ccf-0844-46c4-bf27-ab24c7c51718", "ref_doc_id": "82976ccf-0844-46c4-bf27-ab24c7c51718", "chroma:document": "File ~/miniconda3/envs/haystack/lib/python3.9/site-packages/grpc/_common.py:106, in _wait_once(wait_fn, timeout, spin_cb)\n        105 def _wait_once(wait_fn, timeout, spin_cb):\n    --> 106     wait_fn(timeout=timeout)\n        107     if spin_cb is not None:\n        108         spin_cb()\n\n\n    File ~/miniconda3/envs/haystack/lib/python3.9/threading.py:316, in Condition.wait(self, timeout)\n        314 else:\n        315     if timeout > 0:\n    --> 316         gotit = waiter.acquire(True, timeout)\n        317     else:\n        318         gotit = waiter.acquire(False)\n\n\n    KeyboardInterrupt: \n\n\n## Query the Database\nWith our data safely inserted in Zilliz, we can now perform a query. The query takes in a string or a list of strings and searches them. The results 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    Description: Book about a k-9 from europe\n    Results:\n    \tRank: 1 Score: 0.3047754764556885 Title: Bark M For Murder\n    Who let the dogs out? Evildoers beware! Four of mystery fiction's top storytellers are\n    setting the hounds on your trail -- in an incomparable quartet of crime stories with a\n    canine edge. Man's (and woman's) best friends take the lead in this phenomenal\n    collection of tales tense and surprising, humorous and thrilling: New York\n    Timesbestselling author J.A. Jance's spellbinding saga of a scam-busting septuagenarian\n    and her two golden retrievers; Anthony Award winner Virginia Lanier's pureblood thriller\n    featuring bloodhounds and bloody murder; Chassie West's suspenseful stunner about a\n    life-saving German shepherd and a ghastly forgotten crime; rising star Lee Charles\n    Kelley's edge-of-your-seat yarn that pits an ex-cop/kennel owner and a yappy toy poodle\n    against a craven killer.\n    \n    \tRank: 2 Score: 0.3283390402793884 Title: Texas K-9 Unit Christmas: Holiday Hero\\Rescuing Christmas\n    CHRISTMAS COMES WRAPPED IN DANGER Holiday Hero by Shirlee McCoy Emma Fairchild never\n    expected to find trouble in sleepy Sagebrush, Texas. But when she's attacked and left\n    for dead in her own diner, her childhood friend turned K-9 cop Lucas Harwood offers a\n    chance at justice--and love."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 60dd6255-bd32-4e1d-a39a-3191683b8ded
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb", "title": "Getting Started with Zilliz and OpenAI", "tokens": 5622, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"60dd6255-bd32-4e1d-a39a-3191683b8ded\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Getting Started with Zilliz and OpenAI\", \"tokens\": 5622, \"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\": \"82976ccf-0844-46c4-bf27-ab24c7c51718\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Getting Started with Zilliz and OpenAI\", \"tokens\": 5622, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"b6c5f2c6d1fb2f4a10d0884c8ce3c2f5bff33cf9a04dcde31e91b606e959845a\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"95aa88f8-b557-42bf-898f-ef48616428a5\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Getting Started with Zilliz and OpenAI\", \"tokens\": 5622, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"22908863c812d315cafd96e524bd210c76cdffdbdeb593aa84eb2bd4e73a1528\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"21d603a9-631e-42ae-85f1-ad5674d9f99c\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"1032f31ac641bc77c7a1c47e864023e9ab6f983354b3e7c91a6c5029a5e32cab\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 16700, \"end_char_idx\": 19777, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "82976ccf-0844-46c4-bf27-ab24c7c51718", "doc_id": "82976ccf-0844-46c4-bf27-ab24c7c51718", "ref_doc_id": "82976ccf-0844-46c4-bf27-ab24c7c51718", "chroma:document": "```python\nquery('Book about a k-9 from europe')\n```\n\n    Description: Book about a k-9 from europe\n    Results:\n    \tRank: 1 Score: 0.3047754764556885 Title: Bark M For Murder\n    Who let the dogs out? Evildoers beware! Four of mystery fiction's top storytellers are\n    setting the hounds on your trail -- in an incomparable quartet of crime stories with a\n    canine edge. Man's (and woman's) best friends take the lead in this phenomenal\n    collection of tales tense and surprising, humorous and thrilling: New York\n    Timesbestselling author J.A. Jance's spellbinding saga of a scam-busting septuagenarian\n    and her two golden retrievers; Anthony Award winner Virginia Lanier's pureblood thriller\n    featuring bloodhounds and bloody murder; Chassie West's suspenseful stunner about a\n    life-saving German shepherd and a ghastly forgotten crime; rising star Lee Charles\n    Kelley's edge-of-your-seat yarn that pits an ex-cop/kennel owner and a yappy toy poodle\n    against a craven killer.\n    \n    \tRank: 2 Score: 0.3283390402793884 Title: Texas K-9 Unit Christmas: Holiday Hero\\Rescuing Christmas\n    CHRISTMAS COMES WRAPPED IN DANGER Holiday Hero by Shirlee McCoy Emma Fairchild never\n    expected to find trouble in sleepy Sagebrush, Texas. But when she's attacked and left\n    for dead in her own diner, her childhood friend turned K-9 cop Lucas Harwood offers a\n    chance at justice--and love. Rescuing Christmas by Terri Reed She escaped a kidnapper,\n    but now a killer has set his sights on K-9 dog trainer Lily Anderson. When fellow\n    officer Jarrod Evans appoints himself her bodyguard, Lily knows more than her life is at\n    risk--so is her heart. Texas K-9 Unit: These lawmen solve the toughest cases with the\n    help of their brave canine partners\n    \n    \tRank: 3 Score: 0.33899369835853577 Title: Dogs on Duty: Soldiers' Best Friends on the Battlefield and Beyond\n    When the news of the raid on Osama Bin Laden's compound broke, the SEAL team member that\n    stole the show was a highly trained canine companion. Throughout history, dogs have been\n    key contributors to military units. Dorothy Hinshaw Patent follows man's best friend\n    onto the battlefield, showing readers why dogs are uniquely qualified for the job at\n    hand, how they are trained, how they contribute to missions, and what happens when they\n    retire. With full-color photographs throughout and sidebars featuring heroic canines\n    throughout history, Dogs on Duty provides a fascinating look at these exceptional\n    soldiers and companions.\n    \n    \tRank: 4 Score: 0.34207457304000854 Title: Toute Allure: Falling in Love in Rural France\n    After saying goodbye to life as a successful fashion editor in London, Karen Wheeler is\n    now happy in her small village house in rural France. Her idyll is complete when she\n    meets the love of her life - he has shaggy hair, four paws and a wet nose!\n    \n    \tRank: 5 Score: 0.343595951795578 Title: Otherwise Alone (Evan Arden, #1)\n    Librarian's note: This is an alternate cover edition for ASIN: B00AP5NNWC."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 21d603a9-631e-42ae-85f1-ad5674d9f99c
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb", "title": "Getting Started with Zilliz and OpenAI", "tokens": 5622, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"21d603a9-631e-42ae-85f1-ad5674d9f99c\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Getting Started with Zilliz and OpenAI\", \"tokens\": 5622, \"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\": \"82976ccf-0844-46c4-bf27-ab24c7c51718\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Getting Started with Zilliz and OpenAI\", \"tokens\": 5622, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"b6c5f2c6d1fb2f4a10d0884c8ce3c2f5bff33cf9a04dcde31e91b606e959845a\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"60dd6255-bd32-4e1d-a39a-3191683b8ded\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Getting_started_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Getting Started with Zilliz and OpenAI\", \"tokens\": 5622, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"ad833553ddf2fbece188891294282e32c0dcf0ce21bb81e12a010e36dd51b461\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 18244, \"end_char_idx\": 20528, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "82976ccf-0844-46c4-bf27-ab24c7c51718", "doc_id": "82976ccf-0844-46c4-bf27-ab24c7c51718", "ref_doc_id": "82976ccf-0844-46c4-bf27-ab24c7c51718", "chroma:document": "When fellow\n    officer Jarrod Evans appoints himself her bodyguard, Lily knows more than her life is at\n    risk--so is her heart. Texas K-9 Unit: These lawmen solve the toughest cases with the\n    help of their brave canine partners\n    \n    \tRank: 3 Score: 0.33899369835853577 Title: Dogs on Duty: Soldiers' Best Friends on the Battlefield and Beyond\n    When the news of the raid on Osama Bin Laden's compound broke, the SEAL team member that\n    stole the show was a highly trained canine companion. Throughout history, dogs have been\n    key contributors to military units. Dorothy Hinshaw Patent follows man's best friend\n    onto the battlefield, showing readers why dogs are uniquely qualified for the job at\n    hand, how they are trained, how they contribute to missions, and what happens when they\n    retire. With full-color photographs throughout and sidebars featuring heroic canines\n    throughout history, Dogs on Duty provides a fascinating look at these exceptional\n    soldiers and companions.\n    \n    \tRank: 4 Score: 0.34207457304000854 Title: Toute Allure: Falling in Love in Rural France\n    After saying goodbye to life as a successful fashion editor in London, Karen Wheeler is\n    now happy in her small village house in rural France. Her idyll is complete when she\n    meets the love of her life - he has shaggy hair, four paws and a wet nose!\n    \n    \tRank: 5 Score: 0.343595951795578 Title: Otherwise Alone (Evan Arden, #1)\n    Librarian's note: This is an alternate cover edition for ASIN: B00AP5NNWC. Lieutenant\n    Evan Arden sits in a shack in the middle of nowhere, waiting for orders that will send\n    him back home - if he ever gets them. Other than his loyal Great Pyrenees, there's no\n    one around to break up the monotony. The tedium is excruciating, but it is suddenly\n    interrupted when a young woman stumbles up his path. \"It's only 50-something pages, but\n    in that short amount of time, the author's awesome writing packs in a whole lotta\n    character detail. And sets the stage for the series, perfectly.\" -Maryse.net, 4.5 Stars\n    He has two choices - pick her off from a distance with his trusty sniper-rifle, or dare\n    let her approach his cabin and enter his life. Why not? It's been ages, and he is\n    otherwise alone..."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 0b6bd6b3-573d-4cb6-ac9d-15a729b03faa
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Filtered_search_with_Zilliz_and_OpenAI.ipynb", "title": "Filtered Search with Zilliz and OpenAI", "tokens": 2129, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"0b6bd6b3-573d-4cb6-ac9d-15a729b03faa\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Filtered_search_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Filtered Search with Zilliz and OpenAI\", \"tokens\": 2129, \"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\": \"c9d0f0c4-5522-4412-94ab-c7bcdbda0824\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Filtered_search_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Filtered Search with Zilliz and OpenAI\", \"tokens\": 2129, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"d0f85e91114fa67387a09f45e431bf361b2a131fdcb2296fc32a8ec39dcd23d7\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"69cd49ba-c288-47fd-a9aa-04136148f1d3\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"66d256d33eb3c79f27435d94c053e76543a6145910d02f39de86f2b8140f98b1\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 0, \"end_char_idx\": 2882, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "c9d0f0c4-5522-4412-94ab-c7bcdbda0824", "doc_id": "c9d0f0c4-5522-4412-94ab-c7bcdbda0824", "ref_doc_id": "c9d0f0c4-5522-4412-94ab-c7bcdbda0824", "chroma:document": "# Filtered Search with Zilliz 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 Zilliz 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 Zilliz 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\nTo get Zilliz up and running take a look [here](https://zilliz.com/doc/quick_start). With your account and database set up, proceed to set the following values:\n- URI: The URI your database is running on\n- USER: Your database username\n- PASSWORD: Your database password\n- COLLECTION_NAME: What to name the collection within Zilliz\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 texts to embed and insert at once\n\n\n```python\nimport openai\n\nURI = 'your_uri'\nTOKEN = 'your_token' # TOKEN == user:password or api_key\nCOLLECTION_NAME = 'book_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':\"AUTOINDEX\",\n    'params':{}\n}\n\nQUERY_PARAM = {\n    \"metric_type\": \"L2\",\n    \"params\": {},\n}\n\nBATCH_SIZE = 1000\n```\n\n\n```python\nfrom pymilvus import connections, utility, FieldSchema, Collection, CollectionSchema, DataType\n\n# Connect to Zilliz Database\nconnections.connect(uri=URI, token=TOKEN)\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```"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 69cd49ba-c288-47fd-a9aa-04136148f1d3
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Filtered_search_with_Zilliz_and_OpenAI.ipynb", "title": "Filtered Search with Zilliz and OpenAI", "tokens": 2129, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"69cd49ba-c288-47fd-a9aa-04136148f1d3\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Filtered_search_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Filtered Search with Zilliz and OpenAI\", \"tokens\": 2129, \"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\": \"c9d0f0c4-5522-4412-94ab-c7bcdbda0824\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Filtered_search_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Filtered Search with Zilliz and OpenAI\", \"tokens\": 2129, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"d0f85e91114fa67387a09f45e431bf361b2a131fdcb2296fc32a8ec39dcd23d7\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"0b6bd6b3-573d-4cb6-ac9d-15a729b03faa\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Filtered_search_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Filtered Search with Zilliz and OpenAI\", \"tokens\": 2129, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"d0106273a2e5b0e83612017133d48552f8674ca9ad94fd98cde5740f13fbb5a9\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"a1b0eba0-7764-40ff-9afd-463eaefe3ddc\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"23ca51f9dc3af3a89cca8455eb3a1adabb3f17dca4dd50d1f684a27b8455bbc3\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 1447, \"end_char_idx\": 4309, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "c9d0f0c4-5522-4412-94ab-c7bcdbda0824", "doc_id": "c9d0f0c4-5522-4412-94ab-c7bcdbda0824", "ref_doc_id": "c9d0f0c4-5522-4412-94ab-c7bcdbda0824", "chroma:document": "```python\nimport openai\n\nURI = 'your_uri'\nTOKEN = 'your_token' # TOKEN == user:password or api_key\nCOLLECTION_NAME = 'book_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':\"AUTOINDEX\",\n    'params':{}\n}\n\nQUERY_PARAM = {\n    \"metric_type\": \"L2\",\n    \"params\": {},\n}\n\nBATCH_SIZE = 1000\n```\n\n\n```python\nfrom pymilvus import connections, utility, FieldSchema, Collection, CollectionSchema, DataType\n\n# Connect to Zilliz Database\nconnections.connect(uri=URI, token=TOKEN)\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 Zilliz 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 Zilliz 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    /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages/tqdm/auto.py:22: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n      from .autonotebook import tqdm as notebook_tqdm\n    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 Zilliz. The embedding function takes in text and returns the embeddings in a list format."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: a1b0eba0-7764-40ff-9afd-463eaefe3ddc
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Filtered_search_with_Zilliz_and_OpenAI.ipynb", "title": "Filtered Search with Zilliz and OpenAI", "tokens": 2129, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"a1b0eba0-7764-40ff-9afd-463eaefe3ddc\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Filtered_search_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Filtered Search with Zilliz and OpenAI\", \"tokens\": 2129, \"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\": \"c9d0f0c4-5522-4412-94ab-c7bcdbda0824\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Filtered_search_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Filtered Search with Zilliz and OpenAI\", \"tokens\": 2129, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"d0f85e91114fa67387a09f45e431bf361b2a131fdcb2296fc32a8ec39dcd23d7\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"69cd49ba-c288-47fd-a9aa-04136148f1d3\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Filtered_search_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Filtered Search with Zilliz and OpenAI\", \"tokens\": 2129, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"f431ad6c9a065a7bec0794b1c5845332110396fe17f08562a5cf51e08c2ae961\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"4f32c77e-bbb8-4526-bdd6-1a76a4cdd0eb\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"6977b5f65d14be92a5be5b1422a62ce599bc7442852163224dec30fcbf2071f5\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 2885, \"end_char_idx\": 5570, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "c9d0f0c4-5522-4412-94ab-c7bcdbda0824", "doc_id": "c9d0f0c4-5522-4412-94ab-c7bcdbda0824", "ref_doc_id": "c9d0f0c4-5522-4412-94ab-c7bcdbda0824", "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 Zilliz 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 Zilliz 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    /Users/filiphaltmayer/miniconda3/envs/haystack/lib/python3.9/site-packages/tqdm/auto.py:22: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n      from .autonotebook import tqdm as notebook_tqdm\n    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 Zilliz. 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:54<00:00, 162.59it/s]"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 4f32c77e-bbb8-4526-bdd6-1a76a4cdd0eb
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Filtered_search_with_Zilliz_and_OpenAI.ipynb", "title": "Filtered Search with Zilliz and OpenAI", "tokens": 2129, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"4f32c77e-bbb8-4526-bdd6-1a76a4cdd0eb\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Filtered_search_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Filtered Search with Zilliz and OpenAI\", \"tokens\": 2129, \"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\": \"c9d0f0c4-5522-4412-94ab-c7bcdbda0824\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Filtered_search_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Filtered Search with Zilliz and OpenAI\", \"tokens\": 2129, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"d0f85e91114fa67387a09f45e431bf361b2a131fdcb2296fc32a8ec39dcd23d7\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"a1b0eba0-7764-40ff-9afd-463eaefe3ddc\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Filtered_search_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Filtered Search with Zilliz and OpenAI\", \"tokens\": 2129, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"5948435e6e9920d8bf1a070d2ae7eef4900083da62a79e3bec6880150500f441\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"10fb0bc3-a4ed-4ac8-b73b-f76585f5c72a\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"e20f81c66c012596e97af277c1e6bdc1d41643a1307e046504d224a4c55ed57c\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 4112, \"end_char_idx\": 6032, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "c9d0f0c4-5522-4412-94ab-c7bcdbda0824", "doc_id": "c9d0f0c4-5522-4412-94ab-c7bcdbda0824", "ref_doc_id": "c9d0f0c4-5522-4412-94ab-c7bcdbda0824", "chroma:document": "## Insert the Data\nNow that we have our data on our machine we can begin embedding it and inserting it into Zilliz. 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:54<00:00, 162.59it/s]\n\n\n## Query the Database\nWith our data safely inserted into Zilliz, we can now perform a query. The query takes in a tuple of the movie description you are searching for and 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-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 10fb0bc3-a4ed-4ac8-b73b-f76585f5c72a
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Filtered_search_with_Zilliz_and_OpenAI.ipynb", "title": "Filtered Search with Zilliz and OpenAI", "tokens": 2129, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"10fb0bc3-a4ed-4ac8-b73b-f76585f5c72a\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Filtered_search_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Filtered Search with Zilliz and OpenAI\", \"tokens\": 2129, \"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\": \"c9d0f0c4-5522-4412-94ab-c7bcdbda0824\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Filtered_search_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Filtered Search with Zilliz and OpenAI\", \"tokens\": 2129, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"d0f85e91114fa67387a09f45e431bf361b2a131fdcb2296fc32a8ec39dcd23d7\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"4f32c77e-bbb8-4526-bdd6-1a76a4cdd0eb\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/zilliz/Filtered_search_with_Zilliz_and_OpenAI.ipynb\", \"title\": \"Filtered Search with Zilliz and OpenAI\", \"tokens\": 2129, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"cc8670c15140fcc4b75dbf0114574eef60ff2df6a104acc48c7e77184f498605\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 4774, \"end_char_idx\": 8353, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "c9d0f0c4-5522-4412-94ab-c7bcdbda0824", "doc_id": "c9d0f0c4-5522-4412-94ab-c7bcdbda0824", "ref_doc_id": "c9d0f0c4-5522-4412-94ab-c7bcdbda0824", "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:54<00:00, 162.59it/s]\n\n\n## Query the Database\nWith our data safely inserted into Zilliz, we can now perform a query. The query takes in a tuple of the movie description you are searching for and 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.30085673928260803 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.3352621793746948 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.3415083587169647 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: 4 Score: 0.3428957462310791 Title: Open Season 2\n    \t\tType: Movie Release Year: 2008 Rating: PG\n    Elliot the buck and his forest-dwelling cohorts must rescue their dachshund pal from\n    some spoiled pets bent on returning him to domesticity.\n    \n    \tRank: 5 Score: 0.34376364946365356 Title: Stuart Little 2\n    \t\tType: Movie Release Year: 2002 Rating: PG\n    Zany misadventures are in store as lovable city mouse Stuart and his human brother,\n    George, raise the roof in this sequel to the 1999 blockbuster."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: ed87eb49-4d0a-473b-8aa2-c26dccc31d85
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/README.ipynb", "title": "Weaviate <> OpenAI", "tokens": 656, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"ed87eb49-4d0a-473b-8aa2-c26dccc31d85\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/README.ipynb\", \"title\": \"Weaviate <> OpenAI\", \"tokens\": 656, \"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\": \"b32f3766-b2d0-4926-a170-e81dabc98982\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/README.ipynb\", \"title\": \"Weaviate <> OpenAI\", \"tokens\": 656, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"2639cae11e4853760568f45836d92e5458cd5fe2358ca607a2daf8c96401bcac\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 0, \"end_char_idx\": 2427, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "b32f3766-b2d0-4926-a170-e81dabc98982", "doc_id": "b32f3766-b2d0-4926-a170-e81dabc98982", "ref_doc_id": "b32f3766-b2d0-4926-a170-e81dabc98982", "chroma:document": "# Weaviate <> OpenAI\n\n[\u200bWeaviate](https://weaviate.io) is an open-source vector search engine ([docs](https://weaviate.io/developers/weaviate) - [Github](https://github.com/weaviate/weaviate)) that can store and search through OpenAI embeddings _and_ data objects. The database allows you to do similarity search, hybrid search (the combining of multiple search techniques, such as keyword-based and vector search), and generative search (like Q&A). Weaviate also supports a wide variety of OpenAI-based modules (e.g., [`text2vec-openai`](https://weaviate.io/developers/weaviate/modules/retriever-vectorizer-modules/text2vec-openai), [`qna-openai`](https://weaviate.io/developers/weaviate/modules/reader-generator-modules/qna-openai)), allowing you to vectorize and query data fast and efficiently.\n\nYou can run Weaviate (including the OpenAI modules if desired) in three ways:\n\n1. Open source inside a Docker-container ([example](./docker-compose.yml))\n2. Using the Weaviate Cloud Service ([get started](https://weaviate.io/developers/weaviate/quickstart/installation#weaviate-cloud-service))\n3. In a Kubernetes cluster ([learn more](https://weaviate.io/developers/weaviate/installation/kubernetes))\n\n### Examples\n\nThis folder contains a variety of Weaviate and OpenAI examples. \n\n| Name | Description | language | Google Colab |\n| --- | --- | --- | --- |\n| [Getting Started with Weaviate and OpenAI](./getting-started-with-weaviate-and-openai.ipynb) | A simple getting started for *semantic vector search* using the OpenAI vectorization module in Weaviate (`text2vec-openai`) | Python Notebook | [link](https://colab.research.google.com/drive/1RxpDE_ruCnoBB3TfwAZqdjYgHJhtdwhK) |\n| [Hybrid Search with Weaviate and OpenAI](./hybrid-search-with-weaviate-and-openai.ipynb) | A simple getting started for *hybrid search* using the OpenAI vectorization module in Weaviate (`text2vec-openai`) | Python Notebook | [link](https://colab.research.google.com/drive/1E75BALWoKrOjvUhaznJKQO0A-B1QUPZ4) |\n| [Question Answering with Weaviate and OpenAI](./question-answering-with-weaviate-and-openai.ipynb) | A simple getting started for *question answering (Q&A)* using the OpenAI Q&A module in Weaviate (`qna-openai`) | Python Notebook | [link](https://colab.research.google.com/drive/1pUerUZrJaknEboDxDxsuf3giCK0MJJgm) |\n| [Docker-compose example](./docker-compose.yml) | A Docker-compose file with all OpenAI modules enabled | Docker |"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: a9290059-8d12-4e43-a35f-edf803e27379
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/generative-search-with-weaviate-and-openai.ipynb", "title": "Using Weaviate with Generative OpenAI module for Generative Search", "tokens": 1437, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"a9290059-8d12-4e43-a35f-edf803e27379\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/generative-search-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with Generative OpenAI module for Generative Search\", \"tokens\": 1437, \"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\": \"cc97083f-90c7-47bf-8818-1628a9885bd0\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/generative-search-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with Generative OpenAI module for Generative Search\", \"tokens\": 1437, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"c55b140e49ffd8bf154c3993b6cfe9a40882529fed33ac3076de7503e3efa9dc\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"407a9d21-7552-4763-acc4-520d7252deba\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"1ce7d8725919552baff6195ac90683ac0f975634d96a66b9a06ebfd77b453965\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 0, \"end_char_idx\": 2368, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "cc97083f-90c7-47bf-8818-1628a9885bd0", "doc_id": "cc97083f-90c7-47bf-8818-1628a9885bd0", "ref_doc_id": "cc97083f-90c7-47bf-8818-1628a9885bd0", "chroma:document": "# Using Weaviate with Generative OpenAI module for Generative Search\n\nThis notebook is prepared for a scenario where:\n* Your data is already in Weaviate\n* You want to use Weaviate with the Generative OpenAI module ([generative-openai](https://weaviate.io/developers/weaviate/modules/reader-generator-modules/generative-openai)).\n\n\n\n## Prerequisites\n\nThis cookbook only coveres Generative Search examples, however, it doesn't cover the configuration and data imports.\n\nIn order to make the most of this cookbook, please complete the [Getting Started cookbook](./getting-started-with-weaviate-and-openai.ipynb) first, where you will learn the essentials of working with Weaviate and import the demo data.\n\nChecklist:\n* completed [Getting Started cookbook](./getting-started-with-weaviate-and-openai.ipynb),\n* crated a `Weaviate` instance,\n* imported data into your `Weaviate` instance,\n* you have an [OpenAI API key](https://beta.openai.com/account/api-keys)\n\n===========================================================\n## Prepare your OpenAI API key\n\nThe `OpenAI API key` is used for vectorization of your data at import, and for running 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# Export OpenAI API Key\n!export OPENAI_API_KEY=\"your 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\"] = 'your-key-goes-here'\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## Connect to your Weaviate instance\n\nIn this section, we will:\n\n1. test env variable `OPENAI_API_KEY` \u2013 **make sure** you completed the step in [#Prepare-your-OpenAI-API-key](#Prepare-your-OpenAI-API-key)\n2. connect to your Weaviate with your `OpenAI API Key`\n3. and test the client connection\n\n### The client \n\nAfter this step, the `client` object will be used to perform all Weaviate-related operations."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 407a9d21-7552-4763-acc4-520d7252deba
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/generative-search-with-weaviate-and-openai.ipynb", "title": "Using Weaviate with Generative OpenAI module for Generative Search", "tokens": 1437, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"407a9d21-7552-4763-acc4-520d7252deba\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/generative-search-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with Generative OpenAI module for Generative Search\", \"tokens\": 1437, \"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\": \"cc97083f-90c7-47bf-8818-1628a9885bd0\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/generative-search-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with Generative OpenAI module for Generative Search\", \"tokens\": 1437, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"c55b140e49ffd8bf154c3993b6cfe9a40882529fed33ac3076de7503e3efa9dc\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"a9290059-8d12-4e43-a35f-edf803e27379\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/generative-search-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with Generative OpenAI module for Generative Search\", \"tokens\": 1437, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"572f9a73fab59d392e2bbf4c6d9a0eab855991a8e10b57b65525409004299e81\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"301d8f48-8816-4c5e-85cd-c7aa8d4d25e5\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"b453ba6928b02ba5269a64dcce6593340e8a21704980a8bf8e42d928f3c77b32\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 1382, \"end_char_idx\": 3993, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "cc97083f-90c7-47bf-8818-1628a9885bd0", "doc_id": "cc97083f-90c7-47bf-8818-1628a9885bd0", "ref_doc_id": "cc97083f-90c7-47bf-8818-1628a9885bd0", "chroma:document": "```python\n# Export OpenAI API Key\n!export OPENAI_API_KEY=\"your 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\"] = 'your-key-goes-here'\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## Connect to your Weaviate instance\n\nIn this section, we will:\n\n1. test env variable `OPENAI_API_KEY` \u2013 **make sure** you completed the step in [#Prepare-your-OpenAI-API-key](#Prepare-your-OpenAI-API-key)\n2. connect to your Weaviate with your `OpenAI API Key`\n3. and test the client connection\n\n### The client \n\nAfter this step, the `client` object will be used to perform all Weaviate-related operations.\n\n\n```python\nimport weaviate\nfrom datasets import load_dataset\nimport os\n\n# Connect to your Weaviate instance\nclient = weaviate.Client(\n    url=\"https://your-wcs-instance-name.weaviate.network/\",\n    # url=\"http://localhost:8080/\",\n    auth_client_secret=weaviate.auth.AuthApiKey(api_key=\"<YOUR-WEAVIATE-API-KEY>\"), # comment out this line if you are not using authentication for your Weaviate instance (i.e. for locally deployed instances)\n    additional_headers={\n        \"X-OpenAI-Api-Key\": os.getenv(\"OPENAI_API_KEY\")\n    }\n)\n\n# Check if your instance is live and ready\n# This should return `True`\nclient.is_ready()\n```\n\n## Generative Search\nWeaviate offers a [Generative Search OpenAI](https://weaviate.io/developers/weaviate/modules/reader-generator-modules/generative-openai) module, which generates responses based on the data stored in your Weaviate instance.\n\nThe way you construct a generative search query is very similar to a standard semantic search query in Weaviate. \n\nFor example:\n* search in \"Articles\", \n* return \"title\", \"content\", \"url\"\n* look for objects related to \"football clubs\"\n* limit results to 5 objects\n\n```\n    result = (\n        client.query\n        .get(\"Articles\", [\"title\", \"content\", \"url\"])\n        .with_near_text(\"concepts\": \"football clubs\")\n        .with_limit(5)\n        # generative query will go here\n        .do()\n    )\n```\n\nNow, you can add `with_generate()` function to apply generative transformation. `with_generate` takes either:\n- `single_prompt` - to generate a response for each returned object,\n- `grouped_task` \u2013 to generate a single response from all returned objects."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 301d8f48-8816-4c5e-85cd-c7aa8d4d25e5
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/generative-search-with-weaviate-and-openai.ipynb", "title": "Using Weaviate with Generative OpenAI module for Generative Search", "tokens": 1437, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"301d8f48-8816-4c5e-85cd-c7aa8d4d25e5\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/generative-search-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with Generative OpenAI module for Generative Search\", \"tokens\": 1437, \"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\": \"cc97083f-90c7-47bf-8818-1628a9885bd0\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/generative-search-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with Generative OpenAI module for Generative Search\", \"tokens\": 1437, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"c55b140e49ffd8bf154c3993b6cfe9a40882529fed33ac3076de7503e3efa9dc\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"407a9d21-7552-4763-acc4-520d7252deba\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/generative-search-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with Generative OpenAI module for Generative Search\", \"tokens\": 1437, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"6ce400a82648f2b0c97c27824001e9fc526b0ef4e1491504ac58148f945cd628\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"894d3c34-a6f5-47b5-9a31-e4377a10ce06\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"1a56001b4b2cb993978ef2b2bbe89365ccc57984f685c4eade9cfeec3ed1e028\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 2371, \"end_char_idx\": 4989, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "cc97083f-90c7-47bf-8818-1628a9885bd0", "doc_id": "cc97083f-90c7-47bf-8818-1628a9885bd0", "ref_doc_id": "cc97083f-90c7-47bf-8818-1628a9885bd0", "chroma:document": "```python\nimport weaviate\nfrom datasets import load_dataset\nimport os\n\n# Connect to your Weaviate instance\nclient = weaviate.Client(\n    url=\"https://your-wcs-instance-name.weaviate.network/\",\n    # url=\"http://localhost:8080/\",\n    auth_client_secret=weaviate.auth.AuthApiKey(api_key=\"<YOUR-WEAVIATE-API-KEY>\"), # comment out this line if you are not using authentication for your Weaviate instance (i.e. for locally deployed instances)\n    additional_headers={\n        \"X-OpenAI-Api-Key\": os.getenv(\"OPENAI_API_KEY\")\n    }\n)\n\n# Check if your instance is live and ready\n# This should return `True`\nclient.is_ready()\n```\n\n## Generative Search\nWeaviate offers a [Generative Search OpenAI](https://weaviate.io/developers/weaviate/modules/reader-generator-modules/generative-openai) module, which generates responses based on the data stored in your Weaviate instance.\n\nThe way you construct a generative search query is very similar to a standard semantic search query in Weaviate. \n\nFor example:\n* search in \"Articles\", \n* return \"title\", \"content\", \"url\"\n* look for objects related to \"football clubs\"\n* limit results to 5 objects\n\n```\n    result = (\n        client.query\n        .get(\"Articles\", [\"title\", \"content\", \"url\"])\n        .with_near_text(\"concepts\": \"football clubs\")\n        .with_limit(5)\n        # generative query will go here\n        .do()\n    )\n```\n\nNow, you can add `with_generate()` function to apply generative transformation. `with_generate` takes either:\n- `single_prompt` - to generate a response for each returned object,\n- `grouped_task` \u2013 to generate a single response from all returned objects.\n\n\n\n```python\ndef generative_search_per_item(query, collection_name):\n    prompt = \"Summarize in a short tweet the following content: {content}\"\n\n    result = (\n        client.query\n        .get(collection_name, [\"title\", \"content\", \"url\"])\n        .with_near_text({ \"concepts\": [query], \"distance\": 0.7 })\n        .with_limit(5)\n        .with_generate(single_prompt=prompt)\n        .do()\n    )\n    \n    # Check for errors\n    if (\"errors\" in result):\n        print (\"\\033[91mYou probably have run out of OpenAI API calls for the current minute \u2013 the limit is set at 60 per minute.\")\n        raise Exception(result[\"errors\"][0]['message'])\n    \n    return result[\"data\"][\"Get\"][collection_name]\n```\n\n\n```python\nquery_result = generative_search_per_item(\"football clubs\", \"Article\")\n\nfor i, article in enumerate(query_result):\n    print(f\"{i+1}. { article['title']}\")\n    print(article['_additional']['generate']['singleResult']) # print generated response\n    print(\"-----------------------\")\n```"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 894d3c34-a6f5-47b5-9a31-e4377a10ce06
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/generative-search-with-weaviate-and-openai.ipynb", "title": "Using Weaviate with Generative OpenAI module for Generative Search", "tokens": 1437, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"894d3c34-a6f5-47b5-9a31-e4377a10ce06\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/generative-search-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with Generative OpenAI module for Generative Search\", \"tokens\": 1437, \"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\": \"cc97083f-90c7-47bf-8818-1628a9885bd0\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/generative-search-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with Generative OpenAI module for Generative Search\", \"tokens\": 1437, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"c55b140e49ffd8bf154c3993b6cfe9a40882529fed33ac3076de7503e3efa9dc\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"301d8f48-8816-4c5e-85cd-c7aa8d4d25e5\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/generative-search-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with Generative OpenAI module for Generative Search\", \"tokens\": 1437, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"8026485fae1a9630ba4d4d03fe29dce0ed600f2d3612cb1440c39cd68fa2f822\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 3997, \"end_char_idx\": 6062, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "cc97083f-90c7-47bf-8818-1628a9885bd0", "doc_id": "cc97083f-90c7-47bf-8818-1628a9885bd0", "ref_doc_id": "cc97083f-90c7-47bf-8818-1628a9885bd0", "chroma:document": "```python\ndef generative_search_per_item(query, collection_name):\n    prompt = \"Summarize in a short tweet the following content: {content}\"\n\n    result = (\n        client.query\n        .get(collection_name, [\"title\", \"content\", \"url\"])\n        .with_near_text({ \"concepts\": [query], \"distance\": 0.7 })\n        .with_limit(5)\n        .with_generate(single_prompt=prompt)\n        .do()\n    )\n    \n    # Check for errors\n    if (\"errors\" in result):\n        print (\"\\033[91mYou probably have run out of OpenAI API calls for the current minute \u2013 the limit is set at 60 per minute.\")\n        raise Exception(result[\"errors\"][0]['message'])\n    \n    return result[\"data\"][\"Get\"][collection_name]\n```\n\n\n```python\nquery_result = generative_search_per_item(\"football clubs\", \"Article\")\n\nfor i, article in enumerate(query_result):\n    print(f\"{i+1}. { article['title']}\")\n    print(article['_additional']['generate']['singleResult']) # print generated response\n    print(\"-----------------------\")\n```\n\n\n```python\ndef generative_search_group(query, collection_name):\n    generateTask = \"Explain what these have in common\"\n\n    result = (\n        client.query\n        .get(collection_name, [\"title\", \"content\", \"url\"])\n        .with_near_text({ \"concepts\": [query], \"distance\": 0.7 })\n        .with_generate(grouped_task=generateTask)\n        .with_limit(5)\n        .do()\n    )\n    \n    # Check for errors\n    if (\"errors\" in result):\n        print (\"\\033[91mYou probably have run out of OpenAI API calls for the current minute \u2013 the limit is set at 60 per minute.\")\n        raise Exception(result[\"errors\"][0]['message'])\n    \n    return result[\"data\"][\"Get\"][collection_name]\n```\n\n\n```python\nquery_result = generative_search_group(\"football clubs\", \"Article\")\n\nprint (query_result[0]['_additional']['generate']['groupedResult'])\n```\n\nThanks for following along, you're now equipped to set up your own vector databases and use embeddings to do all kinds of cool things - enjoy! For more complex use cases please continue to work through other cookbook examples in this repo."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: d90ad18e-ed91-4beb-8058-54e538dd8442
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/hybrid-search-with-weaviate-and-openai.ipynb", "title": "Using Weaviate with OpenAI vectorize module for Hybrid Search", "tokens": 3544, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"d90ad18e-ed91-4beb-8058-54e538dd8442\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/hybrid-search-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Hybrid Search\", \"tokens\": 3544, \"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\": \"d546cc36-3cb0-4b97-b112-2d55137b6e70\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/hybrid-search-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Hybrid Search\", \"tokens\": 3544, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"2cea98b33f97d6f94b1d07489015308121dd5728643bf82174fff9a506d8893a\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"ca13af90-c0d5-4167-aa39-905883a46317\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"d603f0f3e3cd1bab94ec3b0fc9295d0056729ecb95964e818bedd7a285afe1aa\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 0, \"end_char_idx\": 2501, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "d546cc36-3cb0-4b97-b112-2d55137b6e70", "doc_id": "d546cc36-3cb0-4b97-b112-2d55137b6e70", "ref_doc_id": "d546cc36-3cb0-4b97-b112-2d55137b6e70", "chroma:document": "# Using Weaviate with OpenAI vectorize module for Hybrid Search\n\nThis notebook is prepared for a scenario where:\n* Your data is not vectorized\n* You want to run Hybrid Search ([learn more](https://weaviate.io/blog/hybrid-search-explained)) on your data\n* You want to use Weaviate with the OpenAI module ([text2vec-openai](https://weaviate.io/developers/weaviate/modules/retriever-vectorizer-modules/text2vec-openai)), to generate vector embeddings for you.\n\nThis notebook takes you through a simple flow to set up a Weaviate instance, connect to it (with OpenAI API key), configure data schema, import data (which will automatically generate vector embeddings for your data), and run hybrid search (mixing of vector and BM25 search).\n\nThis is a common requirement for customers who want to store and search our embeddings with their own data in a secure environment to support production use cases such as chatbots, topic modelling and more.\n\n## What is Weaviate\n\nWeaviate is an open-source vector search engine that stores data objects together with their vectors. This allows for combining vector search with structured filtering.\n\nWeaviate uses KNN algorithms to create an vector-optimized index, which allows your queries to run extremely fast. Learn more [here](https://weaviate.io/blog/why-is-vector-search-so-fast).\n\nWeaviate let you use your favorite ML-models, and scale seamlessly into billions of data objects.\n\n### Deployment options\n\nWhatever your scenario or production setup, Weaviate has an option for you. You can deploy Weaviate in the following setups:\n* Self-hosted \u2013 you can deploy Weaviate with docker locally, or any server you want.\n* SaaS \u2013 you can use [Weaviate Cloud Service (WCS)](https://console.weaviate.io/) to host your Weaviate instances.\n* Hybrid-SaaS \u2013 you can deploy Weaviate in your own private Cloud Service \n\n### Programming languages\n\nWeaviate offers four [client libraries](https://weaviate.io/developers/weaviate/client-libraries), which allow you to communicate from your apps:\n* [Python](https://weaviate.io/developers/weaviate/client-libraries/python)\n* [JavaScript](https://weaviate.io/developers/weaviate/client-libraries/javascript)\n* [Java](https://weaviate.io/developers/weaviate/client-libraries/java)\n* [Go](https://weaviate.io/developers/weaviate/client-libraries/go)\n\nAdditionally, Weaviate has a [REST layer](https://weaviate.io/developers/weaviate/api/rest/objects). Basically you can call Weaviate from any language that supports REST requests."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: ca13af90-c0d5-4167-aa39-905883a46317
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/hybrid-search-with-weaviate-and-openai.ipynb", "title": "Using Weaviate with OpenAI vectorize module for Hybrid Search", "tokens": 3544, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"ca13af90-c0d5-4167-aa39-905883a46317\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/hybrid-search-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Hybrid Search\", \"tokens\": 3544, \"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\": \"d546cc36-3cb0-4b97-b112-2d55137b6e70\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/hybrid-search-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Hybrid Search\", \"tokens\": 3544, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"2cea98b33f97d6f94b1d07489015308121dd5728643bf82174fff9a506d8893a\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"d90ad18e-ed91-4beb-8058-54e538dd8442\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/hybrid-search-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Hybrid Search\", \"tokens\": 3544, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"8c8ccd5d803f1e80586b0e474dff027cec9950c540df3499f7080a0962897705\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"2ae2f2c1-3df4-4695-a620-c60d8f0cc4e9\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"e9e14de57b1163a11ac517d604cc2b7989120d0b88ff7e048f8015b486c07521\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 943, \"end_char_idx\": 4103, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "d546cc36-3cb0-4b97-b112-2d55137b6e70", "doc_id": "d546cc36-3cb0-4b97-b112-2d55137b6e70", "ref_doc_id": "d546cc36-3cb0-4b97-b112-2d55137b6e70", "chroma:document": "## What is Weaviate\n\nWeaviate is an open-source vector search engine that stores data objects together with their vectors. This allows for combining vector search with structured filtering.\n\nWeaviate uses KNN algorithms to create an vector-optimized index, which allows your queries to run extremely fast. Learn more [here](https://weaviate.io/blog/why-is-vector-search-so-fast).\n\nWeaviate let you use your favorite ML-models, and scale seamlessly into billions of data objects.\n\n### Deployment options\n\nWhatever your scenario or production setup, Weaviate has an option for you. You can deploy Weaviate in the following setups:\n* Self-hosted \u2013 you can deploy Weaviate with docker locally, or any server you want.\n* SaaS \u2013 you can use [Weaviate Cloud Service (WCS)](https://console.weaviate.io/) to host your Weaviate instances.\n* Hybrid-SaaS \u2013 you can deploy Weaviate in your own private Cloud Service \n\n### Programming languages\n\nWeaviate offers four [client libraries](https://weaviate.io/developers/weaviate/client-libraries), which allow you to communicate from your apps:\n* [Python](https://weaviate.io/developers/weaviate/client-libraries/python)\n* [JavaScript](https://weaviate.io/developers/weaviate/client-libraries/javascript)\n* [Java](https://weaviate.io/developers/weaviate/client-libraries/java)\n* [Go](https://weaviate.io/developers/weaviate/client-libraries/go)\n\nAdditionally, Weaviate has a [REST layer](https://weaviate.io/developers/weaviate/api/rest/objects). Basically you can call Weaviate from any language that supports REST requests.\n\n## Demo Flow\nThe demo flow is:\n- **Prerequisites Setup**: Create a Weaviate instance and install required libraries\n- **Connect**: Connect to your Weaviate instance \n- **Schema Configuration**: Configure the schema of your data\n    - *Note*: Here we can define which OpenAI Embedding Model to use\n    - *Note*: Here we can configure which properties to index\n- **Import data**: Load a demo dataset and import it into Weaviate\n    - *Note*: The import process will automatically index your data - based on the configuration in the schema\n    - *Note*: You don't need to explicitly vectorize your data, Weaviate will communicate with OpenAI to do it for you\n- **Run Queries**: Query \n    - *Note*: You don't need to explicitly vectorize your queries, Weaviate will communicate with OpenAI to do it for you\n\nOnce you've run through this notebook you should have a basic understanding of how to setup and use vector databases, and can move on to more complex use cases making use of our embeddings.\n\n## OpenAI Module in Weaviate\nAll Weaviate instances come equipped with the [text2vec-openai](https://weaviate.io/developers/weaviate/modules/retriever-vectorizer-modules/text2vec-openai) module.\n\nThis module is responsible for handling vectorization during import (or any CRUD operations) and when you run a query.\n\n### No need to manually vectorize data\nThis is great news for you. With [text2vec-openai](https://weaviate.io/developers/weaviate/modules/retriever-vectorizer-modules/text2vec-openai) you don't need to manually vectorize your data, as Weaviate will call OpenAI for you whenever necessary."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 2ae2f2c1-3df4-4695-a620-c60d8f0cc4e9
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/hybrid-search-with-weaviate-and-openai.ipynb", "title": "Using Weaviate with OpenAI vectorize module for Hybrid Search", "tokens": 3544, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"2ae2f2c1-3df4-4695-a620-c60d8f0cc4e9\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/hybrid-search-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Hybrid Search\", \"tokens\": 3544, \"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\": \"d546cc36-3cb0-4b97-b112-2d55137b6e70\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/hybrid-search-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Hybrid Search\", \"tokens\": 3544, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"2cea98b33f97d6f94b1d07489015308121dd5728643bf82174fff9a506d8893a\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"ca13af90-c0d5-4167-aa39-905883a46317\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/hybrid-search-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Hybrid Search\", \"tokens\": 3544, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"d5968fdd60f56879354d352bdb074f5128715a456f0d40c9087b5e150ae93686\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"d6cb9acd-c9f0-4845-aedf-d0f31db097d6\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"914020a4f805cf6e0c1e7d53e8af89e270260391245b35f78f20f83f7eb9f703\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 2423, \"end_char_idx\": 5476, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "d546cc36-3cb0-4b97-b112-2d55137b6e70", "doc_id": "d546cc36-3cb0-4b97-b112-2d55137b6e70", "ref_doc_id": "d546cc36-3cb0-4b97-b112-2d55137b6e70", "chroma:document": "Basically you can call Weaviate from any language that supports REST requests.\n\n## Demo Flow\nThe demo flow is:\n- **Prerequisites Setup**: Create a Weaviate instance and install required libraries\n- **Connect**: Connect to your Weaviate instance \n- **Schema Configuration**: Configure the schema of your data\n    - *Note*: Here we can define which OpenAI Embedding Model to use\n    - *Note*: Here we can configure which properties to index\n- **Import data**: Load a demo dataset and import it into Weaviate\n    - *Note*: The import process will automatically index your data - based on the configuration in the schema\n    - *Note*: You don't need to explicitly vectorize your data, Weaviate will communicate with OpenAI to do it for you\n- **Run Queries**: Query \n    - *Note*: You don't need to explicitly vectorize your queries, Weaviate will communicate with OpenAI to do it for you\n\nOnce you've run through this notebook you should have a basic understanding of how to setup and use vector databases, and can move on to more complex use cases making use of our embeddings.\n\n## OpenAI Module in Weaviate\nAll Weaviate instances come equipped with the [text2vec-openai](https://weaviate.io/developers/weaviate/modules/retriever-vectorizer-modules/text2vec-openai) module.\n\nThis module is responsible for handling vectorization during import (or any CRUD operations) and when you run a query.\n\n### No need to manually vectorize data\nThis is great news for you. With [text2vec-openai](https://weaviate.io/developers/weaviate/modules/retriever-vectorizer-modules/text2vec-openai) you don't need to manually vectorize your data, as Weaviate will call OpenAI for you whenever necessary.\n\nAll you need to do is:\n1. provide your OpenAI API Key \u2013 when you connected to the Weaviate Client\n2. define which OpenAI vectorizer to use in your Schema\n\n## Prerequisites\n\nBefore we start this project, we need setup the following:\n\n* create a `Weaviate` instance\n* install libraries\n    * `weaviate-client`\n    * `datasets`\n    * `apache-beam`\n* get your [OpenAI API key](https://beta.openai.com/account/api-keys)\n\n===========================================================\n### Create a Weaviate instance\n\nTo create a Weaviate instance we have 2 options:\n\n1. (Recommended path) [Weaviate Cloud Service](https://console.weaviate.io/) \u2013 to host your Weaviate instance in the cloud. The free sandbox should be more than enough for this cookbook.\n2. Install and run Weaviate locally with Docker.\n\n#### Option 1 \u2013 WCS Installation Steps\n\nUse [Weaviate Cloud Service](https://console.weaviate.io/) (WCS) to create a free Weaviate cluster.\n1. create a free account and/or login to [WCS](https://console.weaviate.io/)\n2. create a `Weaviate Cluster` with the following settings:\n    * Sandbox: `Sandbox Free`\n    * Weaviate Version: Use default (latest)\n    * OIDC Authentication: `Disabled`\n3. your instance should be ready in a minute or two\n4. make a note of the `Cluster Id`. The link will take you to the full path of your cluster (you will need it later to connect to it)."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: d6cb9acd-c9f0-4845-aedf-d0f31db097d6
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/hybrid-search-with-weaviate-and-openai.ipynb", "title": "Using Weaviate with OpenAI vectorize module for Hybrid Search", "tokens": 3544, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"d6cb9acd-c9f0-4845-aedf-d0f31db097d6\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/hybrid-search-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Hybrid Search\", \"tokens\": 3544, \"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\": \"d546cc36-3cb0-4b97-b112-2d55137b6e70\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/hybrid-search-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Hybrid Search\", \"tokens\": 3544, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"2cea98b33f97d6f94b1d07489015308121dd5728643bf82174fff9a506d8893a\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"2ae2f2c1-3df4-4695-a620-c60d8f0cc4e9\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/hybrid-search-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Hybrid Search\", \"tokens\": 3544, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"2c97351177c17abc6cecb8aef3b44cc39dbdfb047c579f11e1be943bae536309\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"4d2c3649-aa60-4c5a-9730-6f6681cf3ce2\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"0f67a17142f8df7346f11f04c1fe1c199dc9ae6e932dbc53902ebb7b407f029f\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 4105, \"end_char_idx\": 7308, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "d546cc36-3cb0-4b97-b112-2d55137b6e70", "doc_id": "d546cc36-3cb0-4b97-b112-2d55137b6e70", "ref_doc_id": "d546cc36-3cb0-4b97-b112-2d55137b6e70", "chroma:document": "All you need to do is:\n1. provide your OpenAI API Key \u2013 when you connected to the Weaviate Client\n2. define which OpenAI vectorizer to use in your Schema\n\n## Prerequisites\n\nBefore we start this project, we need setup the following:\n\n* create a `Weaviate` instance\n* install libraries\n    * `weaviate-client`\n    * `datasets`\n    * `apache-beam`\n* get your [OpenAI API key](https://beta.openai.com/account/api-keys)\n\n===========================================================\n### Create a Weaviate instance\n\nTo create a Weaviate instance we have 2 options:\n\n1. (Recommended path) [Weaviate Cloud Service](https://console.weaviate.io/) \u2013 to host your Weaviate instance in the cloud. The free sandbox should be more than enough for this cookbook.\n2. Install and run Weaviate locally with Docker.\n\n#### Option 1 \u2013 WCS Installation Steps\n\nUse [Weaviate Cloud Service](https://console.weaviate.io/) (WCS) to create a free Weaviate cluster.\n1. create a free account and/or login to [WCS](https://console.weaviate.io/)\n2. create a `Weaviate Cluster` with the following settings:\n    * Sandbox: `Sandbox Free`\n    * Weaviate Version: Use default (latest)\n    * OIDC Authentication: `Disabled`\n3. your instance should be ready in a minute or two\n4. make a note of the `Cluster Id`. The link will take you to the full path of your cluster (you will need it later to connect to it). It should be something like: `https://your-project-name.weaviate.network` \n\n#### Option 2 \u2013 local Weaviate instance with Docker\n\nInstall and run Weaviate locally with Docker.\n1. Download the [./docker-compose.yml](./docker-compose.yml) file\n2. Then open your terminal, navigate to where your docker-compose.yml file is located, and start docker with: `docker-compose up -d`\n3. Once this is ready, your instance should be available at [http://localhost:8080](http://localhost:8080)\n\nNote. To shut down your docker instance you can call: `docker-compose down`\n\n##### Learn more\nTo learn more, about using Weaviate with Docker see the [installation documentation](https://weaviate.io/developers/weaviate/installation/docker-compose).\n\n===========================================================    \n## Install required libraries\n\nBefore running this project make sure to have the following libraries:\n\n### Weaviate Python client\n\nThe [Weaviate Python client](https://weaviate.io/developers/weaviate/client-libraries/python) allows you to communicate with your Weaviate instance from your Python project.\n\n### datasets & apache-beam\n\nTo load sample data, you need the `datasets` library and its' dependency `apache-beam`.\n\n\n```python\n# Install the Weaviate client for Python\n!pip install weaviate-client>3.11.0\n\n# Install datasets and apache-beam to load the sample datasets\n!pip install datasets apache-beam\n```\n\n===========================================================\n## Prepare your OpenAI API key\n\nThe `OpenAI API key` is used for vectorization of your data at import, and for running 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`."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 4d2c3649-aa60-4c5a-9730-6f6681cf3ce2
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/hybrid-search-with-weaviate-and-openai.ipynb", "title": "Using Weaviate with OpenAI vectorize module for Hybrid Search", "tokens": 3544, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"4d2c3649-aa60-4c5a-9730-6f6681cf3ce2\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/hybrid-search-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Hybrid Search\", \"tokens\": 3544, \"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\": \"d546cc36-3cb0-4b97-b112-2d55137b6e70\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/hybrid-search-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Hybrid Search\", \"tokens\": 3544, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"2cea98b33f97d6f94b1d07489015308121dd5728643bf82174fff9a506d8893a\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"d6cb9acd-c9f0-4845-aedf-d0f31db097d6\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/hybrid-search-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Hybrid Search\", \"tokens\": 3544, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"2bec301bd576fe5c6910f08391bf9324c31d98bb2880686ac34ccda2dbcac14b\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"1fdd736f-7847-4751-a923-c1c0947a35e9\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"509856b015946197b089046edafeacd7d5815dd72cffb2e1a5e1db1b7ce35bb3\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 5652, \"end_char_idx\": 8292, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "d546cc36-3cb0-4b97-b112-2d55137b6e70", "doc_id": "d546cc36-3cb0-4b97-b112-2d55137b6e70", "ref_doc_id": "d546cc36-3cb0-4b97-b112-2d55137b6e70", "chroma:document": "1. Download the [./docker-compose.yml](./docker-compose.yml) file\n2. Then open your terminal, navigate to where your docker-compose.yml file is located, and start docker with: `docker-compose up -d`\n3. Once this is ready, your instance should be available at [http://localhost:8080](http://localhost:8080)\n\nNote. To shut down your docker instance you can call: `docker-compose down`\n\n##### Learn more\nTo learn more, about using Weaviate with Docker see the [installation documentation](https://weaviate.io/developers/weaviate/installation/docker-compose).\n\n===========================================================    \n## Install required libraries\n\nBefore running this project make sure to have the following libraries:\n\n### Weaviate Python client\n\nThe [Weaviate Python client](https://weaviate.io/developers/weaviate/client-libraries/python) allows you to communicate with your Weaviate instance from your Python project.\n\n### datasets & apache-beam\n\nTo load sample data, you need the `datasets` library and its' dependency `apache-beam`.\n\n\n```python\n# Install the Weaviate client for Python\n!pip install weaviate-client>3.11.0\n\n# Install datasets and apache-beam to load the sample datasets\n!pip install datasets apache-beam\n```\n\n===========================================================\n## Prepare your OpenAI API key\n\nThe `OpenAI API key` is used for vectorization of your data at import, and for running 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# Export OpenAI API Key\n!export OPENAI_API_KEY=\"your 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'] = 'your-key-goes-here'\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## Connect to your Weaviate instance\n\nIn this section, we will:\n\n1. test env variable `OPENAI_API_KEY` \u2013 **make sure** you completed the step in [#Prepare-your-OpenAI-API-key](#Prepare-your-OpenAI-API-key)\n2. connect to your Weaviate your `OpenAI API Key`\n3. and test the client connection\n\n### The client \n\nAfter this step, the `client` object will be used to perform all Weaviate-related operations."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 1fdd736f-7847-4751-a923-c1c0947a35e9
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/hybrid-search-with-weaviate-and-openai.ipynb", "title": "Using Weaviate with OpenAI vectorize module for Hybrid Search", "tokens": 3544, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"1fdd736f-7847-4751-a923-c1c0947a35e9\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/hybrid-search-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Hybrid Search\", \"tokens\": 3544, \"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\": \"d546cc36-3cb0-4b97-b112-2d55137b6e70\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/hybrid-search-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Hybrid Search\", \"tokens\": 3544, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"2cea98b33f97d6f94b1d07489015308121dd5728643bf82174fff9a506d8893a\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"4d2c3649-aa60-4c5a-9730-6f6681cf3ce2\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/hybrid-search-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Hybrid Search\", \"tokens\": 3544, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"4080ca34e04657bf53552de36309b68fde7e3f62c736896aa2503959e24889a9\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"8535306a-44d1-4348-9805-39a3c1f7b9a9\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"7dd05b88a771409019501c297fa54b8586656eb118e2be5f24f062c3d1027c76\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 6697, \"end_char_idx\": 9779, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "d546cc36-3cb0-4b97-b112-2d55137b6e70", "doc_id": "d546cc36-3cb0-4b97-b112-2d55137b6e70", "ref_doc_id": "d546cc36-3cb0-4b97-b112-2d55137b6e70", "chroma:document": "```python\n# Install the Weaviate client for Python\n!pip install weaviate-client>3.11.0\n\n# Install datasets and apache-beam to load the sample datasets\n!pip install datasets apache-beam\n```\n\n===========================================================\n## Prepare your OpenAI API key\n\nThe `OpenAI API key` is used for vectorization of your data at import, and for running 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# Export OpenAI API Key\n!export OPENAI_API_KEY=\"your 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'] = 'your-key-goes-here'\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## Connect to your Weaviate instance\n\nIn this section, we will:\n\n1. test env variable `OPENAI_API_KEY` \u2013 **make sure** you completed the step in [#Prepare-your-OpenAI-API-key](#Prepare-your-OpenAI-API-key)\n2. connect to your Weaviate your `OpenAI API Key`\n3. and test the client connection\n\n### The client \n\nAfter this step, the `client` object will be used to perform all Weaviate-related operations.\n\n\n```python\nimport weaviate\nfrom datasets import load_dataset\nimport os\n\n# Connect to your Weaviate instance\nclient = weaviate.Client(\n    url=\"https://your-wcs-instance-name.weaviate.network/\",\n#   url=\"http://localhost:8080/\",\n    auth_client_secret=weaviate.auth.AuthApiKey(api_key=\"<YOUR-WEAVIATE-API-KEY>\"), # comment out this line if you are not using authentication for your Weaviate instance (i.e. for locally deployed instances)\n    additional_headers={\n        \"X-OpenAI-Api-Key\": os.getenv(\"OPENAI_API_KEY\")\n    }\n)\n\n# Check if your instance is live and ready\n# This should return `True`\nclient.is_ready()\n```\n\n# Schema\n\nIn this section, we will:\n1. configure the data schema for your data\n2. select OpenAI module\n\n> This is the second and final step, which requires OpenAI specific configuration.\n> After this step, the rest of instructions wlll only touch on Weaviate, as the OpenAI tasks will be handled automatically.\n\n\n## What is a schema\n\nIn Weaviate you create __schemas__ to capture each of the entities you will be searching.\n\nA schema is how you tell Weaviate:\n* what embedding model should be used to vectorize the data\n* what your data is made of (property names and types)\n* which properties should be vectorized and indexed\n\nIn this cookbook we will use a dataset for `Articles`, which contains:\n* `title`\n* `content`\n* `url`\n\nWe want to vectorize `title` and `content`, but not the `url`.\n\nTo vectorize and query the data, we will use `text-embedding-3-small`."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 8535306a-44d1-4348-9805-39a3c1f7b9a9
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/hybrid-search-with-weaviate-and-openai.ipynb", "title": "Using Weaviate with OpenAI vectorize module for Hybrid Search", "tokens": 3544, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"8535306a-44d1-4348-9805-39a3c1f7b9a9\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/hybrid-search-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Hybrid Search\", \"tokens\": 3544, \"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\": \"d546cc36-3cb0-4b97-b112-2d55137b6e70\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/hybrid-search-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Hybrid Search\", \"tokens\": 3544, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"2cea98b33f97d6f94b1d07489015308121dd5728643bf82174fff9a506d8893a\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"1fdd736f-7847-4751-a923-c1c0947a35e9\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/hybrid-search-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Hybrid Search\", \"tokens\": 3544, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"fd148de5c55e6e9476caae1430681e92804e9a1021f7af290c5aaa71bd63c47d\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"a69960d9-8228-4413-9ec3-4c72cbff718d\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"a1f48ce52b5853c71c290635b828a01c4627bb0c89fdad704cfadb21bef7981b\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 8295, \"end_char_idx\": 11261, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "d546cc36-3cb0-4b97-b112-2d55137b6e70", "doc_id": "d546cc36-3cb0-4b97-b112-2d55137b6e70", "ref_doc_id": "d546cc36-3cb0-4b97-b112-2d55137b6e70", "chroma:document": "```python\nimport weaviate\nfrom datasets import load_dataset\nimport os\n\n# Connect to your Weaviate instance\nclient = weaviate.Client(\n    url=\"https://your-wcs-instance-name.weaviate.network/\",\n#   url=\"http://localhost:8080/\",\n    auth_client_secret=weaviate.auth.AuthApiKey(api_key=\"<YOUR-WEAVIATE-API-KEY>\"), # comment out this line if you are not using authentication for your Weaviate instance (i.e. for locally deployed instances)\n    additional_headers={\n        \"X-OpenAI-Api-Key\": os.getenv(\"OPENAI_API_KEY\")\n    }\n)\n\n# Check if your instance is live and ready\n# This should return `True`\nclient.is_ready()\n```\n\n# Schema\n\nIn this section, we will:\n1. configure the data schema for your data\n2. select OpenAI module\n\n> This is the second and final step, which requires OpenAI specific configuration.\n> After this step, the rest of instructions wlll only touch on Weaviate, as the OpenAI tasks will be handled automatically.\n\n\n## What is a schema\n\nIn Weaviate you create __schemas__ to capture each of the entities you will be searching.\n\nA schema is how you tell Weaviate:\n* what embedding model should be used to vectorize the data\n* what your data is made of (property names and types)\n* which properties should be vectorized and indexed\n\nIn this cookbook we will use a dataset for `Articles`, which contains:\n* `title`\n* `content`\n* `url`\n\nWe want to vectorize `title` and `content`, but not the `url`.\n\nTo vectorize and query the data, we will use `text-embedding-3-small`.\n\n\n```python\n# Clear up the schema, so that we can recreate it\nclient.schema.delete_all()\nclient.schema.get()\n\n# Define the Schema object to use `text-embedding-3-small` on `title` and `content`, but skip it for `url`\narticle_schema = {\n    \"class\": \"Article\",\n    \"description\": \"A collection of articles\",\n    \"vectorizer\": \"text2vec-openai\",\n    \"moduleConfig\": {\n        \"text2vec-openai\": {\n          \"model\": \"ada\",\n          \"modelVersion\": \"002\",\n          \"type\": \"text\"\n        }\n    },\n    \"properties\": [{\n        \"name\": \"title\",\n        \"description\": \"Title of the article\",\n        \"dataType\": [\"string\"]\n    },\n    {\n        \"name\": \"content\",\n        \"description\": \"Contents of the article\",\n        \"dataType\": [\"text\"]\n    },\n    {\n        \"name\": \"url\",\n        \"description\": \"URL to the article\",\n        \"dataType\": [\"string\"],\n        \"moduleConfig\": { \"text2vec-openai\": { \"skip\": True } }\n    }]\n}\n\n# add the Article schema\nclient.schema.create_class(article_schema)\n\n# get the schema to make sure it worked\nclient.schema.get()\n```\n\n## Import data\n\nIn this section we will:\n1. load the Simple Wikipedia dataset\n2. configure Weaviate Batch import (to make the import more efficient)\n3. import the data into Weaviate\n\n> Note: <br/>\n> Like mentioned before. We don't need to manually vectorize the data.<br/>\n> The [text2vec-openai](https://weaviate.io/developers/weaviate/modules/retriever-vectorizer-modules/text2vec-openai) module will take care of that."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: a69960d9-8228-4413-9ec3-4c72cbff718d
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/hybrid-search-with-weaviate-and-openai.ipynb", "title": "Using Weaviate with OpenAI vectorize module for Hybrid Search", "tokens": 3544, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"a69960d9-8228-4413-9ec3-4c72cbff718d\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/hybrid-search-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Hybrid Search\", \"tokens\": 3544, \"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\": \"d546cc36-3cb0-4b97-b112-2d55137b6e70\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/hybrid-search-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Hybrid Search\", \"tokens\": 3544, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"2cea98b33f97d6f94b1d07489015308121dd5728643bf82174fff9a506d8893a\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"8535306a-44d1-4348-9805-39a3c1f7b9a9\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/hybrid-search-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Hybrid Search\", \"tokens\": 3544, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"0c2ef8d31f31e9e2230201ff4183465536d55823fa1a4170df8c0237ee762c2f\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"abb7e479-1a06-4a51-ac3e-d3bce5c76d42\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"bd52c142d903f5d4f49c2dcef340cb0228ae08a4910a138e08d9f063452ebe3a\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 9782, \"end_char_idx\": 12815, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "d546cc36-3cb0-4b97-b112-2d55137b6e70", "doc_id": "d546cc36-3cb0-4b97-b112-2d55137b6e70", "ref_doc_id": "d546cc36-3cb0-4b97-b112-2d55137b6e70", "chroma:document": "```python\n# Clear up the schema, so that we can recreate it\nclient.schema.delete_all()\nclient.schema.get()\n\n# Define the Schema object to use `text-embedding-3-small` on `title` and `content`, but skip it for `url`\narticle_schema = {\n    \"class\": \"Article\",\n    \"description\": \"A collection of articles\",\n    \"vectorizer\": \"text2vec-openai\",\n    \"moduleConfig\": {\n        \"text2vec-openai\": {\n          \"model\": \"ada\",\n          \"modelVersion\": \"002\",\n          \"type\": \"text\"\n        }\n    },\n    \"properties\": [{\n        \"name\": \"title\",\n        \"description\": \"Title of the article\",\n        \"dataType\": [\"string\"]\n    },\n    {\n        \"name\": \"content\",\n        \"description\": \"Contents of the article\",\n        \"dataType\": [\"text\"]\n    },\n    {\n        \"name\": \"url\",\n        \"description\": \"URL to the article\",\n        \"dataType\": [\"string\"],\n        \"moduleConfig\": { \"text2vec-openai\": { \"skip\": True } }\n    }]\n}\n\n# add the Article schema\nclient.schema.create_class(article_schema)\n\n# get the schema to make sure it worked\nclient.schema.get()\n```\n\n## Import data\n\nIn this section we will:\n1. load the Simple Wikipedia dataset\n2. configure Weaviate Batch import (to make the import more efficient)\n3. import the data into Weaviate\n\n> Note: <br/>\n> Like mentioned before. We don't need to manually vectorize the data.<br/>\n> The [text2vec-openai](https://weaviate.io/developers/weaviate/modules/retriever-vectorizer-modules/text2vec-openai) module will take care of that.\n\n\n```python\n### STEP 1 - load the dataset\n\nfrom datasets import load_dataset\nfrom typing import List, Iterator\n\n# We'll use the datasets library to pull the Simple Wikipedia dataset for embedding\ndataset = list(load_dataset(\"wikipedia\", \"20220301.simple\")[\"train\"])\n\n# For testing, limited to 2.5k articles for demo purposes\ndataset = dataset[:2_500]\n\n# Limited to 25k articles for larger demo purposes\n# dataset = dataset[:25_000]\n\n# for free OpenAI acounts, you can use 50 objects\n# dataset = dataset[:50]\n```\n\n\n```python\n### Step 2 - configure Weaviate Batch, with\n# - starting batch size of 100\n# - dynamically increase/decrease based on performance\n# - add timeout retries if something goes wrong\n\nclient.batch.configure(\n    batch_size=10, \n    dynamic=True,\n    timeout_retries=3,\n#   callback=None,\n)\n```\n\n\n```python\n### Step 3 - import data\n\nprint(\"Importing Articles\")\n\ncounter=0\n\nwith client.batch as batch:\n    for article in dataset:\n        if (counter %10 == 0):\n            print(f\"Import {counter} / {len(dataset)} \")\n\n        properties = {\n            \"title\": article[\"title\"],\n            \"content\": article[\"text\"],\n            \"url\": article[\"url\"]\n        }\n        \n        batch.add_data_object(properties, \"Article\")\n        counter = counter+1\n\nprint(\"Importing Articles complete\")       \n```\n\n\n```python\n# Test that all data has loaded \u2013 get object count\nresult = (\n    client.query.aggregate(\"Article\")\n    .with_fields(\"meta { count }\")\n    .do()\n)\nprint(\"Object count: \", result[\"data\"][\"Aggregate\"][\"Article\"], \"\\n\")\n```"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: abb7e479-1a06-4a51-ac3e-d3bce5c76d42
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/hybrid-search-with-weaviate-and-openai.ipynb", "title": "Using Weaviate with OpenAI vectorize module for Hybrid Search", "tokens": 3544, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"abb7e479-1a06-4a51-ac3e-d3bce5c76d42\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/hybrid-search-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Hybrid Search\", \"tokens\": 3544, \"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\": \"d546cc36-3cb0-4b97-b112-2d55137b6e70\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/hybrid-search-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Hybrid Search\", \"tokens\": 3544, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"2cea98b33f97d6f94b1d07489015308121dd5728643bf82174fff9a506d8893a\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"a69960d9-8228-4413-9ec3-4c72cbff718d\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/hybrid-search-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Hybrid Search\", \"tokens\": 3544, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"62d6bd0529c35692ecb62f8efe791012a4300fb053ab7187b6736fdfef6285e8\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"6b334884-13a2-40ec-9bd7-fdfa18966982\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"d945252274c65e9f4dd3d0419f1fa9359c7b1ed41db97618bf6174f834c44516\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 11264, \"end_char_idx\": 14327, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "d546cc36-3cb0-4b97-b112-2d55137b6e70", "doc_id": "d546cc36-3cb0-4b97-b112-2d55137b6e70", "ref_doc_id": "d546cc36-3cb0-4b97-b112-2d55137b6e70", "chroma:document": "```python\n### STEP 1 - load the dataset\n\nfrom datasets import load_dataset\nfrom typing import List, Iterator\n\n# We'll use the datasets library to pull the Simple Wikipedia dataset for embedding\ndataset = list(load_dataset(\"wikipedia\", \"20220301.simple\")[\"train\"])\n\n# For testing, limited to 2.5k articles for demo purposes\ndataset = dataset[:2_500]\n\n# Limited to 25k articles for larger demo purposes\n# dataset = dataset[:25_000]\n\n# for free OpenAI acounts, you can use 50 objects\n# dataset = dataset[:50]\n```\n\n\n```python\n### Step 2 - configure Weaviate Batch, with\n# - starting batch size of 100\n# - dynamically increase/decrease based on performance\n# - add timeout retries if something goes wrong\n\nclient.batch.configure(\n    batch_size=10, \n    dynamic=True,\n    timeout_retries=3,\n#   callback=None,\n)\n```\n\n\n```python\n### Step 3 - import data\n\nprint(\"Importing Articles\")\n\ncounter=0\n\nwith client.batch as batch:\n    for article in dataset:\n        if (counter %10 == 0):\n            print(f\"Import {counter} / {len(dataset)} \")\n\n        properties = {\n            \"title\": article[\"title\"],\n            \"content\": article[\"text\"],\n            \"url\": article[\"url\"]\n        }\n        \n        batch.add_data_object(properties, \"Article\")\n        counter = counter+1\n\nprint(\"Importing Articles complete\")       \n```\n\n\n```python\n# Test that all data has loaded \u2013 get object count\nresult = (\n    client.query.aggregate(\"Article\")\n    .with_fields(\"meta { count }\")\n    .do()\n)\nprint(\"Object count: \", result[\"data\"][\"Aggregate\"][\"Article\"], \"\\n\")\n```\n\n\n```python\n# Test one article has worked by checking one object\ntest_article = (\n    client.query\n    .get(\"Article\", [\"title\", \"url\", \"content\"])\n    .with_limit(1)\n    .do()\n)[\"data\"][\"Get\"][\"Article\"][0]\n\nprint(test_article['title'])\nprint(test_article['url'])\nprint(test_article['content'])\n```\n\n### Search Data\n\nAs above, we'll fire some queries at our new Index and get back results based on the closeness to our existing vectors\n\nLearn more about the `alpha` setting [here](https://weaviate.io/developers/weaviate/api/graphql/vector-search-parameters#hybrid)\n\n\n```python\ndef hybrid_query_weaviate(query, collection_name, alpha_val):\n    \n    nearText = {\n        \"concepts\": [query],\n        \"distance\": 0.7,\n    }\n\n    properties = [\n        \"title\", \"content\", \"url\",\n        \"_additional { score }\"\n    ]\n\n    result = (\n        client.query\n        .get(collection_name, properties)\n        .with_hybrid(nearText, alpha=alpha_val)\n        .with_limit(10)\n        .do()\n    )\n    \n    # Check for errors\n    if (\"errors\" in result):\n        print (\"\\033[91mYou probably have run out of OpenAI API calls for the current minute \u2013 the limit is set at 60 per minute.\")\n        raise Exception(result[\"errors\"][0]['message'])\n    \n    return result[\"data\"][\"Get\"][collection_name]\n```\n\n\n```python\nquery_result = hybrid_query_weaviate(\"modern art in Europe\", \"Article\", 0.5)\n\nfor i, article in enumerate(query_result):\n    print(f\"{i+1}. { article['title']} (Score: {article['_additional']['score']})\")\n```"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 6b334884-13a2-40ec-9bd7-fdfa18966982
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/hybrid-search-with-weaviate-and-openai.ipynb", "title": "Using Weaviate with OpenAI vectorize module for Hybrid Search", "tokens": 3544, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"6b334884-13a2-40ec-9bd7-fdfa18966982\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/hybrid-search-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Hybrid Search\", \"tokens\": 3544, \"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\": \"d546cc36-3cb0-4b97-b112-2d55137b6e70\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/hybrid-search-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Hybrid Search\", \"tokens\": 3544, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"2cea98b33f97d6f94b1d07489015308121dd5728643bf82174fff9a506d8893a\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"abb7e479-1a06-4a51-ac3e-d3bce5c76d42\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/hybrid-search-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Hybrid Search\", \"tokens\": 3544, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"d78df84e8e414622da549d10ae3dce5d171298b3f39d3e57be0c72c0207ff310\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 12818, \"end_char_idx\": 14803, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "d546cc36-3cb0-4b97-b112-2d55137b6e70", "doc_id": "d546cc36-3cb0-4b97-b112-2d55137b6e70", "ref_doc_id": "d546cc36-3cb0-4b97-b112-2d55137b6e70", "chroma:document": "```python\n# Test one article has worked by checking one object\ntest_article = (\n    client.query\n    .get(\"Article\", [\"title\", \"url\", \"content\"])\n    .with_limit(1)\n    .do()\n)[\"data\"][\"Get\"][\"Article\"][0]\n\nprint(test_article['title'])\nprint(test_article['url'])\nprint(test_article['content'])\n```\n\n### Search Data\n\nAs above, we'll fire some queries at our new Index and get back results based on the closeness to our existing vectors\n\nLearn more about the `alpha` setting [here](https://weaviate.io/developers/weaviate/api/graphql/vector-search-parameters#hybrid)\n\n\n```python\ndef hybrid_query_weaviate(query, collection_name, alpha_val):\n    \n    nearText = {\n        \"concepts\": [query],\n        \"distance\": 0.7,\n    }\n\n    properties = [\n        \"title\", \"content\", \"url\",\n        \"_additional { score }\"\n    ]\n\n    result = (\n        client.query\n        .get(collection_name, properties)\n        .with_hybrid(nearText, alpha=alpha_val)\n        .with_limit(10)\n        .do()\n    )\n    \n    # Check for errors\n    if (\"errors\" in result):\n        print (\"\\033[91mYou probably have run out of OpenAI API calls for the current minute \u2013 the limit is set at 60 per minute.\")\n        raise Exception(result[\"errors\"][0]['message'])\n    \n    return result[\"data\"][\"Get\"][collection_name]\n```\n\n\n```python\nquery_result = hybrid_query_weaviate(\"modern art in Europe\", \"Article\", 0.5)\n\nfor i, article in enumerate(query_result):\n    print(f\"{i+1}. { article['title']} (Score: {article['_additional']['score']})\")\n```\n\n\n```python\nquery_result = hybrid_query_weaviate(\"Famous battles in Scottish history\", \"Article\", 0.5)\n\nfor i, article in enumerate(query_result):\n    print(f\"{i+1}. { article['title']} (Score: {article['_additional']['score']})\")\n```\n\nThanks for following along, you're now equipped to set up your own vector databases and use embeddings to do all kinds of cool things - enjoy! For more complex use cases please continue to work through other cookbook examples in this repo."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: df973c06-c675-47fa-a971-0721ada05b1b
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/getting-started-with-weaviate-and-openai.ipynb", "title": "Using Weaviate with OpenAI vectorize module for Embeddings Search", "tokens": 3475, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"df973c06-c675-47fa-a971-0721ada05b1b\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/getting-started-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Embeddings Search\", \"tokens\": 3475, \"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\": \"5c43259c-d8fe-4f22-8c64-b59f6cbd4b72\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/getting-started-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Embeddings Search\", \"tokens\": 3475, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"991bca91f9d90b969f92ab9705826a1252f072df241beb79d175e5a8ac376966\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"d2ed3058-c95b-47ac-9cde-7b91950e067c\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"5f42683117a6882ddfb0c1fe03a12a35edf18df643f375084ed63d3e1f80a4e1\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 0, \"end_char_idx\": 2407, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "5c43259c-d8fe-4f22-8c64-b59f6cbd4b72", "doc_id": "5c43259c-d8fe-4f22-8c64-b59f6cbd4b72", "ref_doc_id": "5c43259c-d8fe-4f22-8c64-b59f6cbd4b72", "chroma:document": "# Using Weaviate with OpenAI vectorize module for Embeddings Search\n\nThis notebook is prepared for a scenario where:\n* Your data is not vectorized\n* You want to run Vector Search on your data\n* You want to use Weaviate with the OpenAI module ([text2vec-openai](https://weaviate.io/developers/weaviate/modules/retriever-vectorizer-modules/text2vec-openai)), to generate vector embeddings for you.\n\nThis notebook takes you through a simple flow to set up a Weaviate instance, connect to it (with OpenAI API key), configure data schema, import data (which will automatically generate vector embeddings for your data), and run semantic search.\n\nThis is a common requirement for customers who want to store and search our embeddings with their own data in a secure environment to support production use cases such as chatbots, topic modelling and more.\n\n## What is Weaviate\n\nWeaviate is an open-source vector search engine that stores data objects together with their vectors. This allows for combining vector search with structured filtering.\n\nWeaviate uses KNN algorithms to create an vector-optimized index, which allows your queries to run extremely fast. Learn more [here](https://weaviate.io/blog/why-is-vector-search-so-fast).\n\nWeaviate let you use your favorite ML-models, and scale seamlessly into billions of data objects.\n\n### Deployment options\n\nWhatever your scenario or production setup, Weaviate has an option for you. You can deploy Weaviate in the following setups:\n* Self-hosted \u2013 you can deploy Weaviate with docker locally, or any server you want.\n* SaaS \u2013 you can use [Weaviate Cloud Service (WCS)](https://console.weaviate.io/) to host your Weaviate instances.\n* Hybrid-SaaS \u2013 you can deploy Weaviate in your own private Cloud Service.\n\n### Programming languages\n\nWeaviate offers four [client libraries](https://weaviate.io/developers/weaviate/client-libraries), which allow you to communicate from your apps:\n* [Python](https://weaviate.io/developers/weaviate/client-libraries/python)\n* [JavaScript](https://weaviate.io/developers/weaviate/client-libraries/javascript)\n* [Java](https://weaviate.io/developers/weaviate/client-libraries/java)\n* [Go](https://weaviate.io/developers/weaviate/client-libraries/go)\n\nAdditionally, Weaviate has a [REST layer](https://weaviate.io/developers/weaviate/api/rest/objects). Basically you can call Weaviate from any language that supports REST requests."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: d2ed3058-c95b-47ac-9cde-7b91950e067c
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/getting-started-with-weaviate-and-openai.ipynb", "title": "Using Weaviate with OpenAI vectorize module for Embeddings Search", "tokens": 3475, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"d2ed3058-c95b-47ac-9cde-7b91950e067c\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/getting-started-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Embeddings Search\", \"tokens\": 3475, \"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\": \"5c43259c-d8fe-4f22-8c64-b59f6cbd4b72\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/getting-started-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Embeddings Search\", \"tokens\": 3475, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"991bca91f9d90b969f92ab9705826a1252f072df241beb79d175e5a8ac376966\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"df973c06-c675-47fa-a971-0721ada05b1b\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/getting-started-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Embeddings Search\", \"tokens\": 3475, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"07d332f1dc607db67c7b906eb0b44ab27abfaa4a48b8bb23d519ae8582444c07\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"2a38bb43-64f6-427c-b625-e4c1fbc708f5\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"91e24283b44225b5528d7257722b3aab3d33708477e2e4aac032f4ad58933a12\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 849, \"end_char_idx\": 4013, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "5c43259c-d8fe-4f22-8c64-b59f6cbd4b72", "doc_id": "5c43259c-d8fe-4f22-8c64-b59f6cbd4b72", "ref_doc_id": "5c43259c-d8fe-4f22-8c64-b59f6cbd4b72", "chroma:document": "## What is Weaviate\n\nWeaviate is an open-source vector search engine that stores data objects together with their vectors. This allows for combining vector search with structured filtering.\n\nWeaviate uses KNN algorithms to create an vector-optimized index, which allows your queries to run extremely fast. Learn more [here](https://weaviate.io/blog/why-is-vector-search-so-fast).\n\nWeaviate let you use your favorite ML-models, and scale seamlessly into billions of data objects.\n\n### Deployment options\n\nWhatever your scenario or production setup, Weaviate has an option for you. You can deploy Weaviate in the following setups:\n* Self-hosted \u2013 you can deploy Weaviate with docker locally, or any server you want.\n* SaaS \u2013 you can use [Weaviate Cloud Service (WCS)](https://console.weaviate.io/) to host your Weaviate instances.\n* Hybrid-SaaS \u2013 you can deploy Weaviate in your own private Cloud Service.\n\n### Programming languages\n\nWeaviate offers four [client libraries](https://weaviate.io/developers/weaviate/client-libraries), which allow you to communicate from your apps:\n* [Python](https://weaviate.io/developers/weaviate/client-libraries/python)\n* [JavaScript](https://weaviate.io/developers/weaviate/client-libraries/javascript)\n* [Java](https://weaviate.io/developers/weaviate/client-libraries/java)\n* [Go](https://weaviate.io/developers/weaviate/client-libraries/go)\n\nAdditionally, Weaviate has a [REST layer](https://weaviate.io/developers/weaviate/api/rest/objects). Basically you can call Weaviate from any language that supports REST requests.\n\n## Demo Flow\nThe demo flow is:\n- **Prerequisites Setup**: Create a Weaviate instance and install the required libraries\n- **Connect**: Connect to your Weaviate instance \n- **Schema Configuration**: Configure the schema of your data\n    - *Note*: Here we can define which OpenAI Embedding Model to use\n    - *Note*: Here we can configure which properties to index\n- **Import data**: Load a demo dataset and import it into Weaviate\n    - *Note*: The import process will automatically index your data - based on the configuration in the schema\n    - *Note*: You don't need to explicitly vectorize your data, Weaviate will communicate with OpenAI to do it for you\n- **Run Queries**: Query \n    - *Note*: You don't need to explicitly vectorize your queries, Weaviate will communicate with OpenAI to do it for you\n\nOnce you've run through this notebook you should have a basic understanding of how to setup and use vector databases, and can move on to more complex use cases making use of our embeddings.\n\n## OpenAI Module in Weaviate\nAll Weaviate instances come equipped with the [text2vec-openai](https://weaviate.io/developers/weaviate/modules/retriever-vectorizer-modules/text2vec-openai) module.\n\nThis module is responsible for handling vectorization during import (or any CRUD operations) and when you run a query.\n\n### No need to manually vectorize data\nThis is great news for you. With [text2vec-openai](https://weaviate.io/developers/weaviate/modules/retriever-vectorizer-modules/text2vec-openai) you don't need to manually vectorize your data, as Weaviate will call OpenAI for you whenever necessary."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 2a38bb43-64f6-427c-b625-e4c1fbc708f5
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/getting-started-with-weaviate-and-openai.ipynb", "title": "Using Weaviate with OpenAI vectorize module for Embeddings Search", "tokens": 3475, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"2a38bb43-64f6-427c-b625-e4c1fbc708f5\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/getting-started-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Embeddings Search\", \"tokens\": 3475, \"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\": \"5c43259c-d8fe-4f22-8c64-b59f6cbd4b72\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/getting-started-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Embeddings Search\", \"tokens\": 3475, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"991bca91f9d90b969f92ab9705826a1252f072df241beb79d175e5a8ac376966\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"d2ed3058-c95b-47ac-9cde-7b91950e067c\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/getting-started-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Embeddings Search\", \"tokens\": 3475, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"3bdae287b4cd5045df99877f477d6c6f1bd019aa36c8b37aa9c41ee7014bb40c\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"eb6a8088-3972-4866-a889-c53f73d43077\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"4c24e0a97e6fa87af6f52ae729261b8a382095973148c261c75712da4c640237\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 2329, \"end_char_idx\": 5386, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "5c43259c-d8fe-4f22-8c64-b59f6cbd4b72", "doc_id": "5c43259c-d8fe-4f22-8c64-b59f6cbd4b72", "ref_doc_id": "5c43259c-d8fe-4f22-8c64-b59f6cbd4b72", "chroma:document": "Basically you can call Weaviate from any language that supports REST requests.\n\n## Demo Flow\nThe demo flow is:\n- **Prerequisites Setup**: Create a Weaviate instance and install the required libraries\n- **Connect**: Connect to your Weaviate instance \n- **Schema Configuration**: Configure the schema of your data\n    - *Note*: Here we can define which OpenAI Embedding Model to use\n    - *Note*: Here we can configure which properties to index\n- **Import data**: Load a demo dataset and import it into Weaviate\n    - *Note*: The import process will automatically index your data - based on the configuration in the schema\n    - *Note*: You don't need to explicitly vectorize your data, Weaviate will communicate with OpenAI to do it for you\n- **Run Queries**: Query \n    - *Note*: You don't need to explicitly vectorize your queries, Weaviate will communicate with OpenAI to do it for you\n\nOnce you've run through this notebook you should have a basic understanding of how to setup and use vector databases, and can move on to more complex use cases making use of our embeddings.\n\n## OpenAI Module in Weaviate\nAll Weaviate instances come equipped with the [text2vec-openai](https://weaviate.io/developers/weaviate/modules/retriever-vectorizer-modules/text2vec-openai) module.\n\nThis module is responsible for handling vectorization during import (or any CRUD operations) and when you run a query.\n\n### No need to manually vectorize data\nThis is great news for you. With [text2vec-openai](https://weaviate.io/developers/weaviate/modules/retriever-vectorizer-modules/text2vec-openai) you don't need to manually vectorize your data, as Weaviate will call OpenAI for you whenever necessary.\n\nAll you need to do is:\n1. provide your OpenAI API Key \u2013 when you connected to the Weaviate Client\n2. define which OpenAI vectorizer to use in your Schema\n\n## Prerequisites\n\nBefore we start this project, we need setup the following:\n\n* create a `Weaviate` instance\n* install libraries\n    * `weaviate-client`\n    * `datasets`\n    * `apache-beam`\n* get your [OpenAI API key](https://beta.openai.com/account/api-keys)\n\n===========================================================\n### Create a Weaviate instance\n\nTo create a Weaviate instance we have 2 options:\n\n1. (Recommended path) [Weaviate Cloud Service](https://console.weaviate.io/) \u2013 to host your Weaviate instance in the cloud. The free sandbox should be more than enough for this cookbook.\n2. Install and run Weaviate locally with Docker.\n\n#### Option 1 \u2013 WCS Installation Steps\n\nUse [Weaviate Cloud Service](https://console.weaviate.io/) (WCS) to create a free Weaviate cluster.\n1. create a free account and/or login to [WCS](https://console.weaviate.io/)\n2. create a `Weaviate Cluster` with the following settings:\n    * Sandbox: `Sandbox Free`\n    * Weaviate Version: Use default (latest)\n    * OIDC Authentication: `Disabled`\n3. your instance should be ready in a minute or two\n4. make a note of the `Cluster Id`. The link will take you to the full path of your cluster (you will need it later to connect to it)."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: eb6a8088-3972-4866-a889-c53f73d43077
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/getting-started-with-weaviate-and-openai.ipynb", "title": "Using Weaviate with OpenAI vectorize module for Embeddings Search", "tokens": 3475, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"eb6a8088-3972-4866-a889-c53f73d43077\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/getting-started-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Embeddings Search\", \"tokens\": 3475, \"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\": \"5c43259c-d8fe-4f22-8c64-b59f6cbd4b72\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/getting-started-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Embeddings Search\", \"tokens\": 3475, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"991bca91f9d90b969f92ab9705826a1252f072df241beb79d175e5a8ac376966\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"2a38bb43-64f6-427c-b625-e4c1fbc708f5\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/getting-started-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Embeddings Search\", \"tokens\": 3475, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"68318732e0f68e624f7838d88d280e8075e47c55c4984aedc4577e1352e83614\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"31a25d77-c405-4111-ac0f-cc0c0f172fbf\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"9fc0c29ae9da2787f6e42fcc65f01d10a280af533d1481233c659dd7ec018426\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 4015, \"end_char_idx\": 7218, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "5c43259c-d8fe-4f22-8c64-b59f6cbd4b72", "doc_id": "5c43259c-d8fe-4f22-8c64-b59f6cbd4b72", "ref_doc_id": "5c43259c-d8fe-4f22-8c64-b59f6cbd4b72", "chroma:document": "All you need to do is:\n1. provide your OpenAI API Key \u2013 when you connected to the Weaviate Client\n2. define which OpenAI vectorizer to use in your Schema\n\n## Prerequisites\n\nBefore we start this project, we need setup the following:\n\n* create a `Weaviate` instance\n* install libraries\n    * `weaviate-client`\n    * `datasets`\n    * `apache-beam`\n* get your [OpenAI API key](https://beta.openai.com/account/api-keys)\n\n===========================================================\n### Create a Weaviate instance\n\nTo create a Weaviate instance we have 2 options:\n\n1. (Recommended path) [Weaviate Cloud Service](https://console.weaviate.io/) \u2013 to host your Weaviate instance in the cloud. The free sandbox should be more than enough for this cookbook.\n2. Install and run Weaviate locally with Docker.\n\n#### Option 1 \u2013 WCS Installation Steps\n\nUse [Weaviate Cloud Service](https://console.weaviate.io/) (WCS) to create a free Weaviate cluster.\n1. create a free account and/or login to [WCS](https://console.weaviate.io/)\n2. create a `Weaviate Cluster` with the following settings:\n    * Sandbox: `Sandbox Free`\n    * Weaviate Version: Use default (latest)\n    * OIDC Authentication: `Disabled`\n3. your instance should be ready in a minute or two\n4. make a note of the `Cluster Id`. The link will take you to the full path of your cluster (you will need it later to connect to it). It should be something like: `https://your-project-name.weaviate.network` \n\n#### Option 2 \u2013 local Weaviate instance with Docker\n\nInstall and run Weaviate locally with Docker.\n1. Download the [./docker-compose.yml](./docker-compose.yml) file\n2. Then open your terminal, navigate to where your docker-compose.yml file is located, and start docker with: `docker-compose up -d`\n3. Once this is ready, your instance should be available at [http://localhost:8080](http://localhost:8080)\n\nNote. To shut down your docker instance you can call: `docker-compose down`\n\n##### Learn more\nTo learn more, about using Weaviate with Docker see the [installation documentation](https://weaviate.io/developers/weaviate/installation/docker-compose).\n\n===========================================================    \n## Install required libraries\n\nBefore running this project make sure to have the following libraries:\n\n### Weaviate Python client\n\nThe [Weaviate Python client](https://weaviate.io/developers/weaviate/client-libraries/python) allows you to communicate with your Weaviate instance from your Python project.\n\n### datasets & apache-beam\n\nTo load sample data, you need the `datasets` library and its dependency `apache-beam`.\n\n\n```python\n# Install the Weaviate client for Python\n!pip install weaviate-client>=3.11.0\n\n# Install datasets and apache-beam to load the sample datasets\n!pip install datasets apache-beam\n```\n\n===========================================================\n## Prepare your OpenAI API key\n\nThe `OpenAI API key` is used for vectorization of your data at import, and for running 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`."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 31a25d77-c405-4111-ac0f-cc0c0f172fbf
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/getting-started-with-weaviate-and-openai.ipynb", "title": "Using Weaviate with OpenAI vectorize module for Embeddings Search", "tokens": 3475, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"31a25d77-c405-4111-ac0f-cc0c0f172fbf\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/getting-started-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Embeddings Search\", \"tokens\": 3475, \"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\": \"5c43259c-d8fe-4f22-8c64-b59f6cbd4b72\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/getting-started-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Embeddings Search\", \"tokens\": 3475, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"991bca91f9d90b969f92ab9705826a1252f072df241beb79d175e5a8ac376966\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"eb6a8088-3972-4866-a889-c53f73d43077\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/getting-started-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Embeddings Search\", \"tokens\": 3475, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"5df42f8960e2462514758ead1f88b7786e9877f90df7210bafd55522a7ccf32a\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"8ad38bcb-2064-4dcd-b52b-e15b6433a275\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"e6127a721c83a5f23e7175dcaa40d0529657321f96e63bb58772853cb2a5afaa\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 5562, \"end_char_idx\": 8207, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "5c43259c-d8fe-4f22-8c64-b59f6cbd4b72", "doc_id": "5c43259c-d8fe-4f22-8c64-b59f6cbd4b72", "ref_doc_id": "5c43259c-d8fe-4f22-8c64-b59f6cbd4b72", "chroma:document": "1. Download the [./docker-compose.yml](./docker-compose.yml) file\n2. Then open your terminal, navigate to where your docker-compose.yml file is located, and start docker with: `docker-compose up -d`\n3. Once this is ready, your instance should be available at [http://localhost:8080](http://localhost:8080)\n\nNote. To shut down your docker instance you can call: `docker-compose down`\n\n##### Learn more\nTo learn more, about using Weaviate with Docker see the [installation documentation](https://weaviate.io/developers/weaviate/installation/docker-compose).\n\n===========================================================    \n## Install required libraries\n\nBefore running this project make sure to have the following libraries:\n\n### Weaviate Python client\n\nThe [Weaviate Python client](https://weaviate.io/developers/weaviate/client-libraries/python) allows you to communicate with your Weaviate instance from your Python project.\n\n### datasets & apache-beam\n\nTo load sample data, you need the `datasets` library and its dependency `apache-beam`.\n\n\n```python\n# Install the Weaviate client for Python\n!pip install weaviate-client>=3.11.0\n\n# Install datasets and apache-beam to load the sample datasets\n!pip install datasets apache-beam\n```\n\n===========================================================\n## Prepare your OpenAI API key\n\nThe `OpenAI API key` is used for vectorization of your data at import, and for running 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# Export OpenAI API Key\n!export OPENAI_API_KEY=\"your 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\"] = 'your-key-goes-here'\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## Connect to your Weaviate instance\n\nIn this section, we will:\n\n1. test env variable `OPENAI_API_KEY` \u2013 **make sure** you completed the step in [#Prepare-your-OpenAI-API-key](#Prepare-your-OpenAI-API-key)\n2. connect to your Weaviate with your `OpenAI API Key`\n3. and test the client connection\n\n### The client \n\nAfter this step, the `client` object will be used to perform all Weaviate-related operations."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 8ad38bcb-2064-4dcd-b52b-e15b6433a275
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/getting-started-with-weaviate-and-openai.ipynb", "title": "Using Weaviate with OpenAI vectorize module for Embeddings Search", "tokens": 3475, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"8ad38bcb-2064-4dcd-b52b-e15b6433a275\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/getting-started-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Embeddings Search\", \"tokens\": 3475, \"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\": \"5c43259c-d8fe-4f22-8c64-b59f6cbd4b72\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/getting-started-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Embeddings Search\", \"tokens\": 3475, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"991bca91f9d90b969f92ab9705826a1252f072df241beb79d175e5a8ac376966\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"31a25d77-c405-4111-ac0f-cc0c0f172fbf\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/getting-started-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Embeddings Search\", \"tokens\": 3475, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"b3c99bec20674073ab3b4cd78b957f191d5f2108e4d7e7de0a61940de6c6255d\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"cba0d9c2-0f3f-49b5-939e-69cbfe0bb4fc\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"e1850fb6310398320760051daae4cd5d30ac778e8caba3f319dd260a2e97e4df\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 6606, \"end_char_idx\": 9696, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "5c43259c-d8fe-4f22-8c64-b59f6cbd4b72", "doc_id": "5c43259c-d8fe-4f22-8c64-b59f6cbd4b72", "ref_doc_id": "5c43259c-d8fe-4f22-8c64-b59f6cbd4b72", "chroma:document": "```python\n# Install the Weaviate client for Python\n!pip install weaviate-client>=3.11.0\n\n# Install datasets and apache-beam to load the sample datasets\n!pip install datasets apache-beam\n```\n\n===========================================================\n## Prepare your OpenAI API key\n\nThe `OpenAI API key` is used for vectorization of your data at import, and for running 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# Export OpenAI API Key\n!export OPENAI_API_KEY=\"your 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\"] = 'your-key-goes-here'\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## Connect to your Weaviate instance\n\nIn this section, we will:\n\n1. test env variable `OPENAI_API_KEY` \u2013 **make sure** you completed the step in [#Prepare-your-OpenAI-API-key](#Prepare-your-OpenAI-API-key)\n2. connect to your Weaviate with your `OpenAI API Key`\n3. and test the client connection\n\n### The client \n\nAfter this step, the `client` object will be used to perform all Weaviate-related operations.\n\n\n```python\nimport weaviate\nfrom datasets import load_dataset\nimport os\n\n# Connect to your Weaviate instance\nclient = weaviate.Client(\n    url=\"https://your-wcs-instance-name.weaviate.network/\",\n    # url=\"http://localhost:8080/\",\n    auth_client_secret=weaviate.auth.AuthApiKey(api_key=\"<YOUR-WEAVIATE-API-KEY>\"), # comment out this line if you are not using authentication for your Weaviate instance (i.e. for locally deployed instances)\n    additional_headers={\n        \"X-OpenAI-Api-Key\": os.getenv(\"OPENAI_API_KEY\")\n    }\n)\n\n# Check if your instance is live and ready\n# This should return `True`\nclient.is_ready()\n```\n\n# Schema\n\nIn this section, we will:\n1. configure the data schema for your data\n2. select OpenAI module\n\n> This is the second and final step, which requires OpenAI specific configuration.\n> After this step, the rest of instructions wlll only touch on Weaviate, as the OpenAI tasks will be handled automatically.\n\n\n## What is a schema\n\nIn Weaviate you create __schemas__ to capture each of the entities you will be searching.\n\nA schema is how you tell Weaviate:\n* what embedding model should be used to vectorize the data\n* what your data is made of (property names and types)\n* which properties should be vectorized and indexed\n\nIn this cookbook we will use a dataset for `Articles`, which contains:\n* `title`\n* `content`\n* `url`\n\nWe want to vectorize `title` and `content`, but not the `url`.\n\nTo vectorize and query the data, we will use `text-embedding-3-small`."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: cba0d9c2-0f3f-49b5-939e-69cbfe0bb4fc
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/getting-started-with-weaviate-and-openai.ipynb", "title": "Using Weaviate with OpenAI vectorize module for Embeddings Search", "tokens": 3475, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"cba0d9c2-0f3f-49b5-939e-69cbfe0bb4fc\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/getting-started-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Embeddings Search\", \"tokens\": 3475, \"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\": \"5c43259c-d8fe-4f22-8c64-b59f6cbd4b72\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/getting-started-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Embeddings Search\", \"tokens\": 3475, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"991bca91f9d90b969f92ab9705826a1252f072df241beb79d175e5a8ac376966\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"8ad38bcb-2064-4dcd-b52b-e15b6433a275\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/getting-started-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Embeddings Search\", \"tokens\": 3475, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"7a707e17d1aa49da414720c29a253410cb1dcc52b7b83066107a44c8b674bc62\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"7854ac72-6431-4d77-8535-16948b689042\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"a1f48ce52b5853c71c290635b828a01c4627bb0c89fdad704cfadb21bef7981b\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 8210, \"end_char_idx\": 11178, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "5c43259c-d8fe-4f22-8c64-b59f6cbd4b72", "doc_id": "5c43259c-d8fe-4f22-8c64-b59f6cbd4b72", "ref_doc_id": "5c43259c-d8fe-4f22-8c64-b59f6cbd4b72", "chroma:document": "```python\nimport weaviate\nfrom datasets import load_dataset\nimport os\n\n# Connect to your Weaviate instance\nclient = weaviate.Client(\n    url=\"https://your-wcs-instance-name.weaviate.network/\",\n    # url=\"http://localhost:8080/\",\n    auth_client_secret=weaviate.auth.AuthApiKey(api_key=\"<YOUR-WEAVIATE-API-KEY>\"), # comment out this line if you are not using authentication for your Weaviate instance (i.e. for locally deployed instances)\n    additional_headers={\n        \"X-OpenAI-Api-Key\": os.getenv(\"OPENAI_API_KEY\")\n    }\n)\n\n# Check if your instance is live and ready\n# This should return `True`\nclient.is_ready()\n```\n\n# Schema\n\nIn this section, we will:\n1. configure the data schema for your data\n2. select OpenAI module\n\n> This is the second and final step, which requires OpenAI specific configuration.\n> After this step, the rest of instructions wlll only touch on Weaviate, as the OpenAI tasks will be handled automatically.\n\n\n## What is a schema\n\nIn Weaviate you create __schemas__ to capture each of the entities you will be searching.\n\nA schema is how you tell Weaviate:\n* what embedding model should be used to vectorize the data\n* what your data is made of (property names and types)\n* which properties should be vectorized and indexed\n\nIn this cookbook we will use a dataset for `Articles`, which contains:\n* `title`\n* `content`\n* `url`\n\nWe want to vectorize `title` and `content`, but not the `url`.\n\nTo vectorize and query the data, we will use `text-embedding-3-small`.\n\n\n```python\n# Clear up the schema, so that we can recreate it\nclient.schema.delete_all()\nclient.schema.get()\n\n# Define the Schema object to use `text-embedding-3-small` on `title` and `content`, but skip it for `url`\narticle_schema = {\n    \"class\": \"Article\",\n    \"description\": \"A collection of articles\",\n    \"vectorizer\": \"text2vec-openai\",\n    \"moduleConfig\": {\n        \"text2vec-openai\": {\n          \"model\": \"ada\",\n          \"modelVersion\": \"002\",\n          \"type\": \"text\"\n        }\n    },\n    \"properties\": [{\n        \"name\": \"title\",\n        \"description\": \"Title of the article\",\n        \"dataType\": [\"string\"]\n    },\n    {\n        \"name\": \"content\",\n        \"description\": \"Contents of the article\",\n        \"dataType\": [\"text\"]\n    },\n    {\n        \"name\": \"url\",\n        \"description\": \"URL to the article\",\n        \"dataType\": [\"string\"],\n        \"moduleConfig\": { \"text2vec-openai\": { \"skip\": True } }\n    }]\n}\n\n# add the Article schema\nclient.schema.create_class(article_schema)\n\n# get the schema to make sure it worked\nclient.schema.get()\n```\n\n## Import data\n\nIn this section we will:\n1. load the Simple Wikipedia dataset\n2. configure Weaviate Batch import (to make the import more efficient)\n3. import the data into Weaviate\n\n> Note: <br/>\n> Like mentioned before. We don't need to manually vectorize the data.<br/>\n> The [text2vec-openai](https://weaviate.io/developers/weaviate/modules/retriever-vectorizer-modules/text2vec-openai) module will take care of that."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 7854ac72-6431-4d77-8535-16948b689042
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/getting-started-with-weaviate-and-openai.ipynb", "title": "Using Weaviate with OpenAI vectorize module for Embeddings Search", "tokens": 3475, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"7854ac72-6431-4d77-8535-16948b689042\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/getting-started-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Embeddings Search\", \"tokens\": 3475, \"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\": \"5c43259c-d8fe-4f22-8c64-b59f6cbd4b72\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/getting-started-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Embeddings Search\", \"tokens\": 3475, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"991bca91f9d90b969f92ab9705826a1252f072df241beb79d175e5a8ac376966\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"cba0d9c2-0f3f-49b5-939e-69cbfe0bb4fc\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/getting-started-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Embeddings Search\", \"tokens\": 3475, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"2fd6d2ac4702bca3f4485e6ebf54ca040487d7f9aad837d338d0ba15f077cebd\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"073843ec-cfef-49f8-a21e-cb0131b59690\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"9f2b67e6cb5a1ec3cbeebe42850a2d75b0af30299e32337e52da40c3c1269f48\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 9699, \"end_char_idx\": 12732, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "5c43259c-d8fe-4f22-8c64-b59f6cbd4b72", "doc_id": "5c43259c-d8fe-4f22-8c64-b59f6cbd4b72", "ref_doc_id": "5c43259c-d8fe-4f22-8c64-b59f6cbd4b72", "chroma:document": "```python\n# Clear up the schema, so that we can recreate it\nclient.schema.delete_all()\nclient.schema.get()\n\n# Define the Schema object to use `text-embedding-3-small` on `title` and `content`, but skip it for `url`\narticle_schema = {\n    \"class\": \"Article\",\n    \"description\": \"A collection of articles\",\n    \"vectorizer\": \"text2vec-openai\",\n    \"moduleConfig\": {\n        \"text2vec-openai\": {\n          \"model\": \"ada\",\n          \"modelVersion\": \"002\",\n          \"type\": \"text\"\n        }\n    },\n    \"properties\": [{\n        \"name\": \"title\",\n        \"description\": \"Title of the article\",\n        \"dataType\": [\"string\"]\n    },\n    {\n        \"name\": \"content\",\n        \"description\": \"Contents of the article\",\n        \"dataType\": [\"text\"]\n    },\n    {\n        \"name\": \"url\",\n        \"description\": \"URL to the article\",\n        \"dataType\": [\"string\"],\n        \"moduleConfig\": { \"text2vec-openai\": { \"skip\": True } }\n    }]\n}\n\n# add the Article schema\nclient.schema.create_class(article_schema)\n\n# get the schema to make sure it worked\nclient.schema.get()\n```\n\n## Import data\n\nIn this section we will:\n1. load the Simple Wikipedia dataset\n2. configure Weaviate Batch import (to make the import more efficient)\n3. import the data into Weaviate\n\n> Note: <br/>\n> Like mentioned before. We don't need to manually vectorize the data.<br/>\n> The [text2vec-openai](https://weaviate.io/developers/weaviate/modules/retriever-vectorizer-modules/text2vec-openai) module will take care of that.\n\n\n```python\n### STEP 1 - load the dataset\n\nfrom datasets import load_dataset\nfrom typing import List, Iterator\n\n# We'll use the datasets library to pull the Simple Wikipedia dataset for embedding\ndataset = list(load_dataset(\"wikipedia\", \"20220301.simple\")[\"train\"])\n\n# For testing, limited to 2.5k articles for demo purposes\ndataset = dataset[:2_500]\n\n# Limited to 25k articles for larger demo purposes\n# dataset = dataset[:25_000]\n\n# for free OpenAI acounts, you can use 50 objects\n# dataset = dataset[:50]\n```\n\n\n```python\n### Step 2 - configure Weaviate Batch, with\n# - starting batch size of 100\n# - dynamically increase/decrease based on performance\n# - add timeout retries if something goes wrong\n\nclient.batch.configure(\n    batch_size=10, \n    dynamic=True,\n    timeout_retries=3,\n#   callback=None,\n)\n```\n\n\n```python\n### Step 3 - import data\n\nprint(\"Importing Articles\")\n\ncounter=0\n\nwith client.batch as batch:\n    for article in dataset:\n        if (counter %10 == 0):\n            print(f\"Import {counter} / {len(dataset)} \")\n\n        properties = {\n            \"title\": article[\"title\"],\n            \"content\": article[\"text\"],\n            \"url\": article[\"url\"]\n        }\n        \n        batch.add_data_object(properties, \"Article\")\n        counter = counter+1\n\nprint(\"Importing Articles complete\")       \n```\n\n\n```python\n# Test that all data has loaded \u2013 get object count\nresult = (\n    client.query.aggregate(\"Article\")\n    .with_fields(\"meta { count }\")\n    .do()\n)\nprint(\"Object count: \", result[\"data\"][\"Aggregate\"][\"Article\"], \"\\n\")\n```"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 073843ec-cfef-49f8-a21e-cb0131b59690
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/getting-started-with-weaviate-and-openai.ipynb", "title": "Using Weaviate with OpenAI vectorize module for Embeddings Search", "tokens": 3475, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"073843ec-cfef-49f8-a21e-cb0131b59690\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/getting-started-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Embeddings Search\", \"tokens\": 3475, \"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\": \"5c43259c-d8fe-4f22-8c64-b59f6cbd4b72\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/getting-started-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Embeddings Search\", \"tokens\": 3475, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"991bca91f9d90b969f92ab9705826a1252f072df241beb79d175e5a8ac376966\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"7854ac72-6431-4d77-8535-16948b689042\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/getting-started-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Embeddings Search\", \"tokens\": 3475, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"76a231381198a8fb1f1e1e65a88c63faef76fa3d291e46a837aaa0a9a7e8f5a6\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"b0d21866-68c3-4ced-8949-6e1f6acfdc2c\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"1f9e449e149d81370862abe9ae406b159c3e90a9b8ed34797995edff92c82a07\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 11181, \"end_char_idx\": 14095, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "5c43259c-d8fe-4f22-8c64-b59f6cbd4b72", "doc_id": "5c43259c-d8fe-4f22-8c64-b59f6cbd4b72", "ref_doc_id": "5c43259c-d8fe-4f22-8c64-b59f6cbd4b72", "chroma:document": "```python\n### STEP 1 - load the dataset\n\nfrom datasets import load_dataset\nfrom typing import List, Iterator\n\n# We'll use the datasets library to pull the Simple Wikipedia dataset for embedding\ndataset = list(load_dataset(\"wikipedia\", \"20220301.simple\")[\"train\"])\n\n# For testing, limited to 2.5k articles for demo purposes\ndataset = dataset[:2_500]\n\n# Limited to 25k articles for larger demo purposes\n# dataset = dataset[:25_000]\n\n# for free OpenAI acounts, you can use 50 objects\n# dataset = dataset[:50]\n```\n\n\n```python\n### Step 2 - configure Weaviate Batch, with\n# - starting batch size of 100\n# - dynamically increase/decrease based on performance\n# - add timeout retries if something goes wrong\n\nclient.batch.configure(\n    batch_size=10, \n    dynamic=True,\n    timeout_retries=3,\n#   callback=None,\n)\n```\n\n\n```python\n### Step 3 - import data\n\nprint(\"Importing Articles\")\n\ncounter=0\n\nwith client.batch as batch:\n    for article in dataset:\n        if (counter %10 == 0):\n            print(f\"Import {counter} / {len(dataset)} \")\n\n        properties = {\n            \"title\": article[\"title\"],\n            \"content\": article[\"text\"],\n            \"url\": article[\"url\"]\n        }\n        \n        batch.add_data_object(properties, \"Article\")\n        counter = counter+1\n\nprint(\"Importing Articles complete\")       \n```\n\n\n```python\n# Test that all data has loaded \u2013 get object count\nresult = (\n    client.query.aggregate(\"Article\")\n    .with_fields(\"meta { count }\")\n    .do()\n)\nprint(\"Object count: \", result[\"data\"][\"Aggregate\"][\"Article\"], \"\\n\")\n```\n\n\n```python\n# Test one article has worked by checking one object\ntest_article = (\n    client.query\n    .get(\"Article\", [\"title\", \"url\", \"content\"])\n    .with_limit(1)\n    .do()\n)[\"data\"][\"Get\"][\"Article\"][0]\n\nprint(test_article['title'])\nprint(test_article['url'])\nprint(test_article['content'])\n```\n\n### Search Data\n\nAs above, we'll fire some queries at our new Index and get back results based on the closeness to our existing vectors\n\n\n```python\ndef query_weaviate(query, collection_name):\n    \n    nearText = {\n        \"concepts\": [query],\n        \"distance\": 0.7,\n    }\n\n    properties = [\n        \"title\", \"content\", \"url\",\n        \"_additional {certainty distance}\"\n    ]\n\n    result = (\n        client.query\n        .get(collection_name, properties)\n        .with_near_text(nearText)\n        .with_limit(10)\n        .do()\n    )\n    \n    # Check for errors\n    if (\"errors\" in result):\n        print (\"\\033[91mYou probably have run out of OpenAI API calls for the current minute \u2013 the limit is set at 60 per minute.\")\n        raise Exception(result[\"errors\"][0]['message'])\n    \n    return result[\"data\"][\"Get\"][collection_name]\n```\n\n\n```python\nquery_result = query_weaviate(\"modern art in Europe\", \"Article\")\n\nfor i, article in enumerate(query_result):\n    print(f\"{i+1}. { article['title']} (Score: {round(article['_additional']['certainty'],3) })\")\n```"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: b0d21866-68c3-4ced-8949-6e1f6acfdc2c
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/getting-started-with-weaviate-and-openai.ipynb", "title": "Using Weaviate with OpenAI vectorize module for Embeddings Search", "tokens": 3475, "retrieve_doc": true, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"b0d21866-68c3-4ced-8949-6e1f6acfdc2c\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/getting-started-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Embeddings Search\", \"tokens\": 3475, \"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\": \"5c43259c-d8fe-4f22-8c64-b59f6cbd4b72\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/getting-started-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Embeddings Search\", \"tokens\": 3475, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"991bca91f9d90b969f92ab9705826a1252f072df241beb79d175e5a8ac376966\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"073843ec-cfef-49f8-a21e-cb0131b59690\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/getting-started-with-weaviate-and-openai.ipynb\", \"title\": \"Using Weaviate with OpenAI vectorize module for Embeddings Search\", \"tokens\": 3475, \"retrieve_doc\": true, \"source\": \"openai_cookbooks\"}, \"hash\": \"2936d2f49008e5a4a0f8b6ccafb6260e35dcc549958fc5a2355a673a66a05334\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 12502, \"end_char_idx\": 14573, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "5c43259c-d8fe-4f22-8c64-b59f6cbd4b72", "doc_id": "5c43259c-d8fe-4f22-8c64-b59f6cbd4b72", "ref_doc_id": "5c43259c-d8fe-4f22-8c64-b59f6cbd4b72", "chroma:document": "```python\n# Test that all data has loaded \u2013 get object count\nresult = (\n    client.query.aggregate(\"Article\")\n    .with_fields(\"meta { count }\")\n    .do()\n)\nprint(\"Object count: \", result[\"data\"][\"Aggregate\"][\"Article\"], \"\\n\")\n```\n\n\n```python\n# Test one article has worked by checking one object\ntest_article = (\n    client.query\n    .get(\"Article\", [\"title\", \"url\", \"content\"])\n    .with_limit(1)\n    .do()\n)[\"data\"][\"Get\"][\"Article\"][0]\n\nprint(test_article['title'])\nprint(test_article['url'])\nprint(test_article['content'])\n```\n\n### Search Data\n\nAs above, we'll fire some queries at our new Index and get back results based on the closeness to our existing vectors\n\n\n```python\ndef query_weaviate(query, collection_name):\n    \n    nearText = {\n        \"concepts\": [query],\n        \"distance\": 0.7,\n    }\n\n    properties = [\n        \"title\", \"content\", \"url\",\n        \"_additional {certainty distance}\"\n    ]\n\n    result = (\n        client.query\n        .get(collection_name, properties)\n        .with_near_text(nearText)\n        .with_limit(10)\n        .do()\n    )\n    \n    # Check for errors\n    if (\"errors\" in result):\n        print (\"\\033[91mYou probably have run out of OpenAI API calls for the current minute \u2013 the limit is set at 60 per minute.\")\n        raise Exception(result[\"errors\"][0]['message'])\n    \n    return result[\"data\"][\"Get\"][collection_name]\n```\n\n\n```python\nquery_result = query_weaviate(\"modern art in Europe\", \"Article\")\n\nfor i, article in enumerate(query_result):\n    print(f\"{i+1}. { article['title']} (Score: {round(article['_additional']['certainty'],3) })\")\n```\n\n\n```python\nquery_result = query_weaviate(\"Famous battles in Scottish history\", \"Article\")\n\nfor i, article in enumerate(query_result):\n    print(f\"{i+1}. { article['title']} (Score: {round(article['_additional']['certainty'],3) })\")\n```\n\nThanks for following along, you're now equipped to set up your own vector databases and use embeddings to do all kinds of cool things - enjoy! For more complex use cases please continue to work through other cookbook examples in this repo."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 46f7b4ec-d57d-4ffd-87c0-09246f2a0cdc
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/Using_Weaviate_for_embeddings_search.ipynb", "title": "Using Weaviate for Embeddings Search", "tokens": 8799, "retrieve_doc": false, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"46f7b4ec-d57d-4ffd-87c0-09246f2a0cdc\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/Using_Weaviate_for_embeddings_search.ipynb\", \"title\": \"Using Weaviate for Embeddings Search\", \"tokens\": 8799, \"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\": \"105ad3e7-dd4e-4fc3-ad89-828cb68fd275\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/Using_Weaviate_for_embeddings_search.ipynb\", \"title\": \"Using Weaviate for Embeddings Search\", \"tokens\": 8799, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"f1e50e0a23cbd05a6303dce4eadd3e2a409b3265e3110a49323df38bcf426110\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"88541259-ca10-4629-945a-9a4f7289b4be\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"ea33eec6ce7fe9964cdec82a5a01d5024ec7994955bd2f2cb55509a0cc3dd62d\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 0, \"end_char_idx\": 3520, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "105ad3e7-dd4e-4fc3-ad89-828cb68fd275", "doc_id": "105ad3e7-dd4e-4fc3-ad89-828cb68fd275", "ref_doc_id": "105ad3e7-dd4e-4fc3-ad89-828cb68fd275", "chroma:document": "# Using Weaviate for Embeddings Search\n\nThis notebook takes you through a simple flow to download some data, embed it, and then index and search it using a selection of vector databases. This is a common requirement for customers who want to store and search our embeddings with their own data in a secure environment to support production use cases such as chatbots, topic modelling and more.\n\n### What is a Vector Database\n\nA vector database is a database made to store, manage and search embedding vectors. The use of embeddings to encode unstructured data (text, audio, video and more) as vectors for consumption by machine-learning models has exploded in recent years, due to the increasing effectiveness of AI in solving use cases involving natural language, image recognition and other unstructured forms of data. Vector databases have emerged as an effective solution for enterprises to deliver and scale these use cases.\n\n### Why use a Vector Database\n\nVector databases enable enterprises to take many of the embeddings use cases we've shared in this repo (question and answering, chatbot and recommendation services, for example), and make use of them in a secure, scalable environment. Many of our customers make embeddings solve their problems at small scale but performance and security hold them back from going into production - we see vector databases as a key component in solving that, and in this guide we'll walk through the basics of embedding text data, storing it in a vector database and using it for semantic search.\n\n\n### Demo Flow\nThe demo flow is:\n- **Setup**: Import packages and set any required variables\n- **Load data**: Load a dataset and embed it using OpenAI embeddings\n- **Weaviate**\n    - *Setup*: Here we'll set up the Python client for Weaviate. For more details go [here](https://weaviate.io/developers/weaviate/current/client-libraries/python.html)\n    - *Index Data*: We'll create an index with __title__ search vectors in it\n    - *Search Data*: We'll run a few searches to confirm it works\n\nOnce you've run through this notebook you should have a basic understanding of how to setup and use vector databases, and can move on to more complex use cases making use of our embeddings.\n\n## Setup\n\nImport the required libraries and set the embedding model that we'd like to use.\n\n\n```python\n# We'll need to install the Weaviate client\n!pip install weaviate-client\n\n#Install wget to pull zip file\n!pip install wget\n```\n\n\n```python\nimport openai\n\nfrom typing import List, Iterator\nimport pandas as pd\nimport numpy as np\nimport os\nimport wget\nfrom ast import literal_eval\n\n# Weaviate's client library for Python\nimport weaviate\n\n# I've set this to our new embeddings model, this can be changed to the embedding model of your choice\nEMBEDDING_MODEL = \"text-embedding-3-small\"\n\n# Ignore unclosed SSL socket warnings - optional in case you get these errors\nimport warnings\n\nwarnings.filterwarnings(action=\"ignore\", message=\"unclosed\", category=ResourceWarning)\nwarnings.filterwarnings(\"ignore\", category=DeprecationWarning) \n```\n\n## Load data\n\nIn this section we'll load embedded data that we've prepared previous to this session.\n\n\n```python\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\n```python\nimport zipfile\nwith zipfile.ZipFile(\"vector_database_wikipedia_articles_embedded.zip\",\"r\") as zip_ref:\n    zip_ref.extractall(\"../data\")\n```"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 88541259-ca10-4629-945a-9a4f7289b4be
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/Using_Weaviate_for_embeddings_search.ipynb", "title": "Using Weaviate for Embeddings Search", "tokens": 8799, "retrieve_doc": false, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"88541259-ca10-4629-945a-9a4f7289b4be\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/Using_Weaviate_for_embeddings_search.ipynb\", \"title\": \"Using Weaviate for Embeddings Search\", \"tokens\": 8799, \"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\": \"105ad3e7-dd4e-4fc3-ad89-828cb68fd275\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/Using_Weaviate_for_embeddings_search.ipynb\", \"title\": \"Using Weaviate for Embeddings Search\", \"tokens\": 8799, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"f1e50e0a23cbd05a6303dce4eadd3e2a409b3265e3110a49323df38bcf426110\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"46f7b4ec-d57d-4ffd-87c0-09246f2a0cdc\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/Using_Weaviate_for_embeddings_search.ipynb\", \"title\": \"Using Weaviate for Embeddings Search\", \"tokens\": 8799, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"9ead60d1e11a0d721d70d926e8130ee20d34929a126b60cd1229df5ac2decdda\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"8ea2a501-e502-4073-9df9-284491264d2c\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"55d75d734c6c465942a4bbe99c9e2550ca1dde90d5af183d906f3fc23ae149c3\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 2319, \"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": "105ad3e7-dd4e-4fc3-ad89-828cb68fd275", "doc_id": "105ad3e7-dd4e-4fc3-ad89-828cb68fd275", "ref_doc_id": "105ad3e7-dd4e-4fc3-ad89-828cb68fd275", "chroma:document": "```python\n# We'll need to install the Weaviate client\n!pip install weaviate-client\n\n#Install wget to pull zip file\n!pip install wget\n```\n\n\n```python\nimport openai\n\nfrom typing import List, Iterator\nimport pandas as pd\nimport numpy as np\nimport os\nimport wget\nfrom ast import literal_eval\n\n# Weaviate's client library for Python\nimport weaviate\n\n# I've set this to our new embeddings model, this can be changed to the embedding model of your choice\nEMBEDDING_MODEL = \"text-embedding-3-small\"\n\n# Ignore unclosed SSL socket warnings - optional in case you get these errors\nimport warnings\n\nwarnings.filterwarnings(action=\"ignore\", message=\"unclosed\", category=ResourceWarning)\nwarnings.filterwarnings(\"ignore\", category=DeprecationWarning) \n```\n\n## Load data\n\nIn this section we'll load embedded data that we've prepared previous to this session.\n\n\n```python\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\n```python\nimport zipfile\nwith zipfile.ZipFile(\"vector_database_wikipedia_articles_embedded.zip\",\"r\") as zip_ref:\n    zip_ref.extractall(\"../data\")\n```\n\n\n```python\narticle_df = pd.read_csv('../data/vector_database_wikipedia_articles_embedded.csv')\n```\n\n\n```python\narticle_df.head()\n```\n\n\n\n\n<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>id</th>\n      <th>url</th>\n      <th>title</th>\n      <th>text</th>\n      <th>title_vector</th>\n      <th>content_vector</th>\n      <th>vector_id</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>1</td>\n      <td>https://simple.wikipedia.org/wiki/April</td>\n      <td>April</td>\n      <td>April is the fourth month of the year in the J...</td>\n      <td>[0.001009464613161981, -0.020700545981526375, ...</td>\n      <td>[-0.011253940872848034, -0.013491976074874401,...</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>2</td>\n      <td>https://simple.wikipedia.org/wiki/August</td>\n      <td>August</td>\n      <td>August (Aug.)"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 8ea2a501-e502-4073-9df9-284491264d2c
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/Using_Weaviate_for_embeddings_search.ipynb", "title": "Using Weaviate for Embeddings Search", "tokens": 8799, "retrieve_doc": false, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"8ea2a501-e502-4073-9df9-284491264d2c\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/Using_Weaviate_for_embeddings_search.ipynb\", \"title\": \"Using Weaviate for Embeddings Search\", \"tokens\": 8799, \"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\": \"105ad3e7-dd4e-4fc3-ad89-828cb68fd275\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/Using_Weaviate_for_embeddings_search.ipynb\", \"title\": \"Using Weaviate for Embeddings Search\", \"tokens\": 8799, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"f1e50e0a23cbd05a6303dce4eadd3e2a409b3265e3110a49323df38bcf426110\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"88541259-ca10-4629-945a-9a4f7289b4be\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/Using_Weaviate_for_embeddings_search.ipynb\", \"title\": \"Using Weaviate for Embeddings Search\", \"tokens\": 8799, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"acb6e82dcf4dcfb26dc8899aeddf5df26228d31ae68655ca2020ff2b9f72ea9a\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"631c409c-feab-46bf-9c1c-2aba15d00cd2\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"0eb9f1fbcad7c87e0ae1cc80d55f22c888212d66f0901dbcd88725f848899c3c\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 3523, \"end_char_idx\": 5701, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "105ad3e7-dd4e-4fc3-ad89-828cb68fd275", "doc_id": "105ad3e7-dd4e-4fc3-ad89-828cb68fd275", "ref_doc_id": "105ad3e7-dd4e-4fc3-ad89-828cb68fd275", "chroma:document": "```python\narticle_df = pd.read_csv('../data/vector_database_wikipedia_articles_embedded.csv')\n```\n\n\n```python\narticle_df.head()\n```\n\n\n\n\n<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>id</th>\n      <th>url</th>\n      <th>title</th>\n      <th>text</th>\n      <th>title_vector</th>\n      <th>content_vector</th>\n      <th>vector_id</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>1</td>\n      <td>https://simple.wikipedia.org/wiki/April</td>\n      <td>April</td>\n      <td>April is the fourth month of the year in the J...</td>\n      <td>[0.001009464613161981, -0.020700545981526375, ...</td>\n      <td>[-0.011253940872848034, -0.013491976074874401,...</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>2</td>\n      <td>https://simple.wikipedia.org/wiki/August</td>\n      <td>August</td>\n      <td>August (Aug.) is the eighth month of the year ...</td>\n      <td>[0.0009286514250561595, 0.000820168002974242, ...</td>\n      <td>[0.0003609954728744924, 0.007262262050062418, ...</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>6</td>\n      <td>https://simple.wikipedia.org/wiki/Art</td>\n      <td>Art</td>\n      <td>Art is a creative activity that expresses imag...</td>\n      <td>[0.003393713850528002, 0.0061537534929811954, ...</td>\n      <td>[-0.004959689453244209, 0.015772193670272827, ...</td>\n      <td>2</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>8</td>\n      <td>https://simple.wikipedia.org/wiki/A</td>\n      <td>A</td>\n      <td>A or a is the first letter of the English alph...</td>\n      <td>[0.0153952119871974, -0.013759135268628597, 0....</td>\n      <td>[0.024894846603274345, -0.022186409682035446, ...</td>\n      <td>3</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>9</td>\n      <td>https://simple.wikipedia.org/wiki/Air</td>\n      <td>Air</td>\n      <td>Air refers to the Earth's atmosphere."}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 631c409c-feab-46bf-9c1c-2aba15d00cd2
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/Using_Weaviate_for_embeddings_search.ipynb", "title": "Using Weaviate for Embeddings Search", "tokens": 8799, "retrieve_doc": false, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"631c409c-feab-46bf-9c1c-2aba15d00cd2\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/Using_Weaviate_for_embeddings_search.ipynb\", \"title\": \"Using Weaviate for Embeddings Search\", \"tokens\": 8799, \"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\": \"105ad3e7-dd4e-4fc3-ad89-828cb68fd275\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/Using_Weaviate_for_embeddings_search.ipynb\", \"title\": \"Using Weaviate for Embeddings Search\", \"tokens\": 8799, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"f1e50e0a23cbd05a6303dce4eadd3e2a409b3265e3110a49323df38bcf426110\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"8ea2a501-e502-4073-9df9-284491264d2c\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/Using_Weaviate_for_embeddings_search.ipynb\", \"title\": \"Using Weaviate for Embeddings Search\", \"tokens\": 8799, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"9c7eb5d14437d9a303d1fc6534fa1eb459d4cbf8873d93da2ce41ef3b74d4772\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"884ddc2d-69ae-4d33-9b7d-69e49fa4cc28\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"56e2aa1bde5ed15fe8073faa23455e10c4418bcfff784ccff7bb57b05c25c908\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 4671, \"end_char_idx\": 6869, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "105ad3e7-dd4e-4fc3-ad89-828cb68fd275", "doc_id": "105ad3e7-dd4e-4fc3-ad89-828cb68fd275", "ref_doc_id": "105ad3e7-dd4e-4fc3-ad89-828cb68fd275", "chroma:document": "is the eighth month of the year ...</td>\n      <td>[0.0009286514250561595, 0.000820168002974242, ...</td>\n      <td>[0.0003609954728744924, 0.007262262050062418, ...</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>6</td>\n      <td>https://simple.wikipedia.org/wiki/Art</td>\n      <td>Art</td>\n      <td>Art is a creative activity that expresses imag...</td>\n      <td>[0.003393713850528002, 0.0061537534929811954, ...</td>\n      <td>[-0.004959689453244209, 0.015772193670272827, ...</td>\n      <td>2</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>8</td>\n      <td>https://simple.wikipedia.org/wiki/A</td>\n      <td>A</td>\n      <td>A or a is the first letter of the English alph...</td>\n      <td>[0.0153952119871974, -0.013759135268628597, 0....</td>\n      <td>[0.024894846603274345, -0.022186409682035446, ...</td>\n      <td>3</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>9</td>\n      <td>https://simple.wikipedia.org/wiki/Air</td>\n      <td>Air</td>\n      <td>Air refers to the Earth's atmosphere. Air is a...</td>\n      <td>[0.02224554680287838, -0.02044147066771984, -0...</td>\n      <td>[0.021524671465158463, 0.018522677943110466, -...</td>\n      <td>4</td>\n    </tr>\n  </tbody>\n</table>\n</div>\n\n\n\n\n```python\n# Read vectors from strings back into a list\narticle_df['title_vector'] = article_df.title_vector.apply(literal_eval)\narticle_df['content_vector'] = article_df.content_vector.apply(literal_eval)\n\n# Set vector_id to be a string\narticle_df['vector_id'] = article_df['vector_id'].apply(str)\n```\n\n\n```python\narticle_df.info(show_counts=True)\n```\n\n    <class 'pandas.core.frame.DataFrame'>\n    RangeIndex: 25000 entries, 0 to 24999\n    Data columns (total 7 columns):\n     #   Column          Non-Null Count  Dtype \n    ---  ------          --------------  ----- \n     0   id              25000 non-null  int64 \n     1   url             25000 non-null  object\n     2   title           25000 non-null  object\n     3   text            25000 non-null  object\n     4   title_vector    25000 non-null  object\n     5   content_vector  25000 non-null  object\n     6   vector_id       25000 non-null  object\n    dtypes: int64(1), object(6)\n    memory usage: 1.3+ MB"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 884ddc2d-69ae-4d33-9b7d-69e49fa4cc28
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/Using_Weaviate_for_embeddings_search.ipynb", "title": "Using Weaviate for Embeddings Search", "tokens": 8799, "retrieve_doc": false, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"884ddc2d-69ae-4d33-9b7d-69e49fa4cc28\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/Using_Weaviate_for_embeddings_search.ipynb\", \"title\": \"Using Weaviate for Embeddings Search\", \"tokens\": 8799, \"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\": \"105ad3e7-dd4e-4fc3-ad89-828cb68fd275\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/Using_Weaviate_for_embeddings_search.ipynb\", \"title\": \"Using Weaviate for Embeddings Search\", \"tokens\": 8799, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"f1e50e0a23cbd05a6303dce4eadd3e2a409b3265e3110a49323df38bcf426110\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"631c409c-feab-46bf-9c1c-2aba15d00cd2\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/Using_Weaviate_for_embeddings_search.ipynb\", \"title\": \"Using Weaviate for Embeddings Search\", \"tokens\": 8799, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"4320c7c17eb3368c7bfc18cc765fcc9a783c8fba72ee141f67ffd98304297e89\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"6168404b-425e-4936-8735-6ca773f8a578\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"686d4ea9bbc87de3b274fe0ef6b95b9180e4ab82f9db022f1d6861c6c8def44d\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 5702, \"end_char_idx\": 7367, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "105ad3e7-dd4e-4fc3-ad89-828cb68fd275", "doc_id": "105ad3e7-dd4e-4fc3-ad89-828cb68fd275", "ref_doc_id": "105ad3e7-dd4e-4fc3-ad89-828cb68fd275", "chroma:document": "Air is a...</td>\n      <td>[0.02224554680287838, -0.02044147066771984, -0...</td>\n      <td>[0.021524671465158463, 0.018522677943110466, -...</td>\n      <td>4</td>\n    </tr>\n  </tbody>\n</table>\n</div>\n\n\n\n\n```python\n# Read vectors from strings back into a list\narticle_df['title_vector'] = article_df.title_vector.apply(literal_eval)\narticle_df['content_vector'] = article_df.content_vector.apply(literal_eval)\n\n# Set vector_id to be a string\narticle_df['vector_id'] = article_df['vector_id'].apply(str)\n```\n\n\n```python\narticle_df.info(show_counts=True)\n```\n\n    <class 'pandas.core.frame.DataFrame'>\n    RangeIndex: 25000 entries, 0 to 24999\n    Data columns (total 7 columns):\n     #   Column          Non-Null Count  Dtype \n    ---  ------          --------------  ----- \n     0   id              25000 non-null  int64 \n     1   url             25000 non-null  object\n     2   title           25000 non-null  object\n     3   text            25000 non-null  object\n     4   title_vector    25000 non-null  object\n     5   content_vector  25000 non-null  object\n     6   vector_id       25000 non-null  object\n    dtypes: int64(1), object(6)\n    memory usage: 1.3+ MB\n\n\n## Weaviate\n\nAnother vector database option we'll explore is **Weaviate**, which offers both a managed, [SaaS](https://console.weaviate.io/) option, as well as a self-hosted [open source](https://github.com/weaviate/weaviate) option. As we've already looked at a cloud vector database, we'll try the self-hosted option here.\n\nFor this we will:\n- Set up a local deployment of Weaviate\n- Create indices in Weaviate\n- Store our data there\n- Fire some similarity search queries\n- Try a real use case"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 6168404b-425e-4936-8735-6ca773f8a578
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/Using_Weaviate_for_embeddings_search.ipynb", "title": "Using Weaviate for Embeddings Search", "tokens": 8799, "retrieve_doc": false, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"6168404b-425e-4936-8735-6ca773f8a578\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/Using_Weaviate_for_embeddings_search.ipynb\", \"title\": \"Using Weaviate for Embeddings Search\", \"tokens\": 8799, \"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\": \"105ad3e7-dd4e-4fc3-ad89-828cb68fd275\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/Using_Weaviate_for_embeddings_search.ipynb\", \"title\": \"Using Weaviate for Embeddings Search\", \"tokens\": 8799, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"f1e50e0a23cbd05a6303dce4eadd3e2a409b3265e3110a49323df38bcf426110\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"884ddc2d-69ae-4d33-9b7d-69e49fa4cc28\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/Using_Weaviate_for_embeddings_search.ipynb\", \"title\": \"Using Weaviate for Embeddings Search\", \"tokens\": 8799, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"2227bc53c26ec91854caaf023a6210198f8ca58076b71aadcde3ce81a581636c\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"d5a16a3d-9ee7-4c84-9148-7b1c6c0f6d80\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"90fecac5f3411c5c078a789fd288daf8432efa3aa262124fce90eb352c3ffb0b\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 5907, \"end_char_idx\": 9346, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "105ad3e7-dd4e-4fc3-ad89-828cb68fd275", "doc_id": "105ad3e7-dd4e-4fc3-ad89-828cb68fd275", "ref_doc_id": "105ad3e7-dd4e-4fc3-ad89-828cb68fd275", "chroma:document": "```python\n# Read vectors from strings back into a list\narticle_df['title_vector'] = article_df.title_vector.apply(literal_eval)\narticle_df['content_vector'] = article_df.content_vector.apply(literal_eval)\n\n# Set vector_id to be a string\narticle_df['vector_id'] = article_df['vector_id'].apply(str)\n```\n\n\n```python\narticle_df.info(show_counts=True)\n```\n\n    <class 'pandas.core.frame.DataFrame'>\n    RangeIndex: 25000 entries, 0 to 24999\n    Data columns (total 7 columns):\n     #   Column          Non-Null Count  Dtype \n    ---  ------          --------------  ----- \n     0   id              25000 non-null  int64 \n     1   url             25000 non-null  object\n     2   title           25000 non-null  object\n     3   text            25000 non-null  object\n     4   title_vector    25000 non-null  object\n     5   content_vector  25000 non-null  object\n     6   vector_id       25000 non-null  object\n    dtypes: int64(1), object(6)\n    memory usage: 1.3+ MB\n\n\n## Weaviate\n\nAnother vector database option we'll explore is **Weaviate**, which offers both a managed, [SaaS](https://console.weaviate.io/) option, as well as a self-hosted [open source](https://github.com/weaviate/weaviate) option. As we've already looked at a cloud vector database, we'll try the self-hosted option here.\n\nFor this we will:\n- Set up a local deployment of Weaviate\n- Create indices in Weaviate\n- Store our data there\n- Fire some similarity search queries\n- Try a real use case\n\n\n### Bring your own vectors approach\nIn this cookbook, we provide the data with already generated vectors. This is a good approach for scenarios, where your data is already vectorized.\n\n### Automated vectorization with OpenAI module\nFor scenarios, where your data is not vectorized yet, you can delegate the vectorization task with OpenAI to Weaviate.\nWeaviate offers a built-in module [text2vec-openai](https://weaviate.io/developers/weaviate/modules/retriever-vectorizer-modules/text2vec-openai), which takes care of the vectorization for you at:\n* import\n* for any CRUD operations\n* for semantic search\n\nCheck out the [Getting Started with Weaviate and OpenAI module cookbook](./weaviate/getting-started-with-weaviate-and-openai.ipynb) to learn step by step how to import and vectorize data in one step.\n\n### Setup\n\nTo run Weaviate locally, you'll need [Docker](https://www.docker.com/). Following the instructions contained in the Weaviate documentation [here](https://weaviate.io/developers/weaviate/installation/docker-compose), we created an example docker-compose.yml file in this repo saved at [./weaviate/docker-compose.yml](./weaviate/docker-compose.yml).\n\nAfter starting Docker, you can start Weaviate locally by navigating to the `examples/vector_databases/weaviate/` directory and running `docker-compose up -d`.\n\n#### SaaS\nAlternatively you can use [Weaviate Cloud Service](https://console.weaviate.io/) (WCS) to create a free Weaviate cluster.\n1. create a free account and/or login to [WCS](https://console.weaviate.io/)\n2. create a `Weaviate Cluster` with the following settings:\n    * Sandbox: `Sandbox Free`\n    * Weaviate Version: Use default (latest)\n    * OIDC Authentication: `Disabled`\n3. your instance should be ready in a minute or two\n4. make a note of the `Cluster Id`. The link will take you to the full path of your cluster (you will need it later to connect to it). It should be something like: `https://your-project-name-suffix.weaviate.network`"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: d5a16a3d-9ee7-4c84-9148-7b1c6c0f6d80
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/Using_Weaviate_for_embeddings_search.ipynb", "title": "Using Weaviate for Embeddings Search", "tokens": 8799, "retrieve_doc": false, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"d5a16a3d-9ee7-4c84-9148-7b1c6c0f6d80\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/Using_Weaviate_for_embeddings_search.ipynb\", \"title\": \"Using Weaviate for Embeddings Search\", \"tokens\": 8799, \"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\": \"105ad3e7-dd4e-4fc3-ad89-828cb68fd275\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/Using_Weaviate_for_embeddings_search.ipynb\", \"title\": \"Using Weaviate for Embeddings Search\", \"tokens\": 8799, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"f1e50e0a23cbd05a6303dce4eadd3e2a409b3265e3110a49323df38bcf426110\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"6168404b-425e-4936-8735-6ca773f8a578\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/Using_Weaviate_for_embeddings_search.ipynb\", \"title\": \"Using Weaviate for Embeddings Search\", \"tokens\": 8799, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"948bfa1d880a92ecb8626ee624642409d1c395f2965032fdb9cd83cad0458c23\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"ce56af66-b8b1-494e-9868-9f2c714e359e\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"982b6e72b18ea116823a5652081d817fc7c69f77f70b1f9af7be82eb4780ea38\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 9350, \"end_char_idx\": 11140, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "105ad3e7-dd4e-4fc3-ad89-828cb68fd275", "doc_id": "105ad3e7-dd4e-4fc3-ad89-828cb68fd275", "ref_doc_id": "105ad3e7-dd4e-4fc3-ad89-828cb68fd275", "chroma:document": "```python\n# Option #1 - Self-hosted - Weaviate Open Source \nclient = weaviate.Client(\n    url=\"http://localhost:8080\",\n    additional_headers={\n        \"X-OpenAI-Api-Key\": os.getenv(\"OPENAI_API_KEY\")\n    }\n)\n```\n\n\n```python\n# Option #2 - SaaS - (Weaviate Cloud Service)\nclient = weaviate.Client(\n    url=\"https://your-wcs-instance-name.weaviate.network\",\n    additional_headers={\n        \"X-OpenAI-Api-Key\": os.getenv(\"OPENAI_API_KEY\")\n    }\n)\n```\n\n\n```python\nclient.is_ready()\n```\n\n### Index data\n\nIn Weaviate you create __schemas__ to capture each of the entities you will be searching. \n\nIn this case we'll create a schema called **Article** with the **title** vector from above included for us to search by.\n\nThe next few steps closely follow the documentation Weaviate provides [here](https://weaviate.io/developers/weaviate/quickstart).\n\n\n\n```python\n# Clear up the schema, so that we can recreate it\nclient.schema.delete_all()\nclient.schema.get()\n\n# Define the Schema object to use `text-embedding-3-small` on `title` and `content`, but skip it for `url`\narticle_schema = {\n    \"class\": \"Article\",\n    \"description\": \"A collection of articles\",\n    \"vectorizer\": \"text2vec-openai\",\n    \"moduleConfig\": {\n        \"text2vec-openai\": {\n          \"model\": \"ada\",\n          \"modelVersion\": \"002\",\n          \"type\": \"text\"\n        }\n    },\n    \"properties\": [{\n        \"name\": \"title\",\n        \"description\": \"Title of the article\",\n        \"dataType\": [\"string\"]\n    },\n    {\n        \"name\": \"content\",\n        \"description\": \"Contents of the article\",\n        \"dataType\": [\"text\"],\n        \"moduleConfig\": { \"text2vec-openai\": { \"skip\": True } }\n    }]\n}\n\n# add the Article schema\nclient.schema.create_class(article_schema)\n\n# get the schema to make sure it worked\nclient.schema.get()\n```"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: ce56af66-b8b1-494e-9868-9f2c714e359e
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/Using_Weaviate_for_embeddings_search.ipynb", "title": "Using Weaviate for Embeddings Search", "tokens": 8799, "retrieve_doc": false, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"ce56af66-b8b1-494e-9868-9f2c714e359e\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/Using_Weaviate_for_embeddings_search.ipynb\", \"title\": \"Using Weaviate for Embeddings Search\", \"tokens\": 8799, \"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\": \"105ad3e7-dd4e-4fc3-ad89-828cb68fd275\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/Using_Weaviate_for_embeddings_search.ipynb\", \"title\": \"Using Weaviate for Embeddings Search\", \"tokens\": 8799, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"f1e50e0a23cbd05a6303dce4eadd3e2a409b3265e3110a49323df38bcf426110\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"d5a16a3d-9ee7-4c84-9148-7b1c6c0f6d80\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/Using_Weaviate_for_embeddings_search.ipynb\", \"title\": \"Using Weaviate for Embeddings Search\", \"tokens\": 8799, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"baddf20f95d1ca3e8ea1ec2dc79d3f99a78645360f9398bf2c6205b6284a9c39\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"6db1b5d9-9282-4e03-a40c-f1df8ee7bc0d\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"e6ee35f80c0a64480f769fb7c0d160afc6cd88a0f192af479dec9b9d33e0cd37\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 9564, \"end_char_idx\": 12819, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "105ad3e7-dd4e-4fc3-ad89-828cb68fd275", "doc_id": "105ad3e7-dd4e-4fc3-ad89-828cb68fd275", "ref_doc_id": "105ad3e7-dd4e-4fc3-ad89-828cb68fd275", "chroma:document": "```python\n# Option #2 - SaaS - (Weaviate Cloud Service)\nclient = weaviate.Client(\n    url=\"https://your-wcs-instance-name.weaviate.network\",\n    additional_headers={\n        \"X-OpenAI-Api-Key\": os.getenv(\"OPENAI_API_KEY\")\n    }\n)\n```\n\n\n```python\nclient.is_ready()\n```\n\n### Index data\n\nIn Weaviate you create __schemas__ to capture each of the entities you will be searching. \n\nIn this case we'll create a schema called **Article** with the **title** vector from above included for us to search by.\n\nThe next few steps closely follow the documentation Weaviate provides [here](https://weaviate.io/developers/weaviate/quickstart).\n\n\n\n```python\n# Clear up the schema, so that we can recreate it\nclient.schema.delete_all()\nclient.schema.get()\n\n# Define the Schema object to use `text-embedding-3-small` on `title` and `content`, but skip it for `url`\narticle_schema = {\n    \"class\": \"Article\",\n    \"description\": \"A collection of articles\",\n    \"vectorizer\": \"text2vec-openai\",\n    \"moduleConfig\": {\n        \"text2vec-openai\": {\n          \"model\": \"ada\",\n          \"modelVersion\": \"002\",\n          \"type\": \"text\"\n        }\n    },\n    \"properties\": [{\n        \"name\": \"title\",\n        \"description\": \"Title of the article\",\n        \"dataType\": [\"string\"]\n    },\n    {\n        \"name\": \"content\",\n        \"description\": \"Contents of the article\",\n        \"dataType\": [\"text\"],\n        \"moduleConfig\": { \"text2vec-openai\": { \"skip\": True } }\n    }]\n}\n\n# add the Article schema\nclient.schema.create_class(article_schema)\n\n# get the schema to make sure it worked\nclient.schema.get()\n```\n\n\n\n\n    {'classes': [{'class': 'Article',\n       'description': 'A collection of articles',\n       'invertedIndexConfig': {'bm25': {'b': 0.75, 'k1': 1.2},\n        'cleanupIntervalSeconds': 60,\n        'stopwords': {'additions': None, 'preset': 'en', 'removals': None}},\n       'moduleConfig': {'text2vec-openai': {'model': 'ada',\n         'modelVersion': '002',\n         'type': 'text',\n         'vectorizeClassName': True}},\n       'properties': [{'dataType': ['string'],\n         'description': 'Title of the article',\n         'moduleConfig': {'text2vec-openai': {'skip': False,\n           'vectorizePropertyName': False}},\n         'name': 'title',\n         'tokenization': 'word'},\n        {'dataType': ['text'],\n         'description': 'Contents of the article',\n         'moduleConfig': {'text2vec-openai': {'skip': True,\n           'vectorizePropertyName': False}},\n         'name': 'content',\n         'tokenization': 'word'}],\n       'replicationConfig': {'factor': 1},\n       'shardingConfig': {'virtualPerPhysical': 128,\n        'desiredCount': 1,\n        'actualCount': 1,\n        'desiredVirtualCount': 128,\n        'actualVirtualCount': 128,\n        'key': '_id',\n        'strategy': 'hash',\n        'function': 'murmur3'},\n       'vectorIndexConfig': {'skip': False,\n        'cleanupIntervalSeconds': 300,\n        'maxConnections': 64,\n        'efConstruction': 128,\n        'ef': -1,\n        'dynamicEfMin': 100,\n        'dynamicEfMax': 500,\n        'dynamicEfFactor': 8,\n        'vectorCacheMaxObjects': 1000000000000,\n        'flatSearchCutoff': 40000,\n        'distance': 'cosine'},\n       'vectorIndexType': 'hnsw',\n       'vectorizer': 'text2vec-openai'}]}"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 6db1b5d9-9282-4e03-a40c-f1df8ee7bc0d
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/Using_Weaviate_for_embeddings_search.ipynb", "title": "Using Weaviate for Embeddings Search", "tokens": 8799, "retrieve_doc": false, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"6db1b5d9-9282-4e03-a40c-f1df8ee7bc0d\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/Using_Weaviate_for_embeddings_search.ipynb\", \"title\": \"Using Weaviate for Embeddings Search\", \"tokens\": 8799, \"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\": \"105ad3e7-dd4e-4fc3-ad89-828cb68fd275\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/Using_Weaviate_for_embeddings_search.ipynb\", \"title\": \"Using Weaviate for Embeddings Search\", \"tokens\": 8799, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"f1e50e0a23cbd05a6303dce4eadd3e2a409b3265e3110a49323df38bcf426110\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"ce56af66-b8b1-494e-9868-9f2c714e359e\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/Using_Weaviate_for_embeddings_search.ipynb\", \"title\": \"Using Weaviate for Embeddings Search\", \"tokens\": 8799, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"dacb84ae0acd83f866a831c1438cd4392b5301b2b9ad7b880fd9d5374c6190ca\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"3655ed68-78e3-4f66-9351-8056d183fb1a\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"b826d1f19ce073fb40a7dd4d7b173da3b4357cb1e4c3230cae13b71d465433f5\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": null, \"end_char_idx\": null, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "105ad3e7-dd4e-4fc3-ad89-828cb68fd275", "doc_id": "105ad3e7-dd4e-4fc3-ad89-828cb68fd275", "ref_doc_id": "105ad3e7-dd4e-4fc3-ad89-828cb68fd275", "chroma:document": "```python\n### Step 1 - configure Weaviate Batch, which optimizes CRUD operations in bulk\n# - starting batch size of 100\n# - dynamically increase/decrease based on performance\n# - add timeout retries if something goes wrong\n\nclient.batch.configure(\n    batch_size=100,\n    dynamic=True,\n    timeout_retries=3,\n)\n```\n\n\n\n\n    <weaviate.batch.crud_batch.Batch at 0x3f0ca0fa0>\n\n\n\n\n```python\n### Step 2 - import data\n\nprint(\"Uploading data with vectors to Article schema.\")\n\ncounter=0\n\nwith client.batch as batch:\n    for k,v in article_df.iterrows():\n        \n        # print update message every 100 objects        \n        if (counter %100 == 0):\n            print(f\"Import {counter} / {len(article_df)} \")\n        \n        properties = {\n            \"title\": v[\"title\"],\n            \"content\": v[\"text\"]\n        }\n        \n        vector = v[\"title_vector\"]\n        \n        batch.add_data_object(properties, \"Article\", None, vector)\n        counter = counter+1\n\nprint(f\"Importing ({len(article_df)}) Articles complete\")  \n```\n\n    Uploading data with vectors to Article schema.\n    Import 0 / 25000 \n    Import 100 / 25000 \n    Import 200 / 25000 \n    Import 300 / 25000 \n    Import 400 / 25000 \n    Import 500 / 25000 \n    Import 600 / 25000 \n    Import 700 / 25000 \n    Import 800 / 25000 \n    Import 900 / 25000 \n    Import 1000 / 25000 \n    Import 1100 / 25000 \n    Import 1200 / 25000 \n    Import 1300 / 25000 \n    Import 1400 / 25000 \n    Import 1500 / 25000 \n    Import 1600 / 25000 \n    Import 1700 / 25000 \n    Import 1800 / 25000 \n    Import 1900 / 25000 \n    Import 2000 / 25000 \n    Import 2100 / 25000 \n    Import 2200 / 25000 \n    Import 2300 / 25000 \n    Import 2400 / 25000 \n    Import 2500 / 25000 \n    Import 2600 / 25000 \n    Import 2700 / 25000 \n    Import 2800 / 25000 \n    Import 2900 / 25000 \n    Import 3000 / 25000 \n    Import 3100 / 25000 \n    Import 3200 / 25000 \n    Import 3300 / 25000 \n    Import 3400 / 25000 \n    Import 3500 / 25000 \n    Import 3600 / 25000 \n    Import 3700 / 25000 \n    Import 3800 / 25000 \n    Import 3900 / 25000 \n    Import 4000 / 25000 \n    Import 4100 / 25000 \n    Import 4200 /"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: 3655ed68-78e3-4f66-9351-8056d183fb1a
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/Using_Weaviate_for_embeddings_search.ipynb", "title": "Using Weaviate for Embeddings Search", "tokens": 8799, "retrieve_doc": false, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"3655ed68-78e3-4f66-9351-8056d183fb1a\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/Using_Weaviate_for_embeddings_search.ipynb\", \"title\": \"Using Weaviate for Embeddings Search\", \"tokens\": 8799, \"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\": \"105ad3e7-dd4e-4fc3-ad89-828cb68fd275\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/Using_Weaviate_for_embeddings_search.ipynb\", \"title\": \"Using Weaviate for Embeddings Search\", \"tokens\": 8799, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"f1e50e0a23cbd05a6303dce4eadd3e2a409b3265e3110a49323df38bcf426110\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"6db1b5d9-9282-4e03-a40c-f1df8ee7bc0d\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/Using_Weaviate_for_embeddings_search.ipynb\", \"title\": \"Using Weaviate for Embeddings Search\", \"tokens\": 8799, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"2b38e0b97d1a7825ec619572f8637d5d70f8a874a95919c37cf847eda610866d\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"a8f7bfd3-68d0-4037-8877-0e53e64feb7c\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"817b9687fbb19a9f5a55424392c1379fb2b6b748f1b47e451a691cded3994200\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 14121, \"end_char_idx\": 15714, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "105ad3e7-dd4e-4fc3-ad89-828cb68fd275", "doc_id": "105ad3e7-dd4e-4fc3-ad89-828cb68fd275", "ref_doc_id": "105ad3e7-dd4e-4fc3-ad89-828cb68fd275", "chroma:document": "Import 900 / 25000 \n    Import 1000 / 25000 \n    Import 1100 / 25000 \n    Import 1200 / 25000 \n    Import 1300 / 25000 \n    Import 1400 / 25000 \n    Import 1500 / 25000 \n    Import 1600 / 25000 \n    Import 1700 / 25000 \n    Import 1800 / 25000 \n    Import 1900 / 25000 \n    Import 2000 / 25000 \n    Import 2100 / 25000 \n    Import 2200 / 25000 \n    Import 2300 / 25000 \n    Import 2400 / 25000 \n    Import 2500 / 25000 \n    Import 2600 / 25000 \n    Import 2700 / 25000 \n    Import 2800 / 25000 \n    Import 2900 / 25000 \n    Import 3000 / 25000 \n    Import 3100 / 25000 \n    Import 3200 / 25000 \n    Import 3300 / 25000 \n    Import 3400 / 25000 \n    Import 3500 / 25000 \n    Import 3600 / 25000 \n    Import 3700 / 25000 \n    Import 3800 / 25000 \n    Import 3900 / 25000 \n    Import 4000 / 25000 \n    Import 4100 / 25000 \n    Import 4200 / 25000 \n    Import 4300 / 25000 \n    Import 4400 / 25000 \n    Import 4500 / 25000 \n    Import 4600 / 25000 \n    Import 4700 / 25000 \n    Import 4800 / 25000 \n    Import 4900 / 25000 \n    Import 5000 / 25000 \n    Import 5100 / 25000 \n    Import 5200 / 25000 \n    Import 5300 / 25000 \n    Import 5400 / 25000 \n    Import 5500 / 25000 \n    Import 5600 / 25000 \n    Import 5700 / 25000 \n    Import 5800 / 25000 \n    Import 5900 / 25000 \n    Import 6000 / 25000 \n    Import 6100 / 25000 \n    Import 6200 / 25000 \n    Import 6300 / 25000 \n    Import 6400 / 25000 \n    Import 6500 / 25000 \n    Import 6600 / 25000 \n    Import 6700 / 25000 \n    Import 6800 / 25000 \n    Import 6900 / 25000 \n    Import 7000 / 25000 \n    Import 7100 / 25000 \n    Import 7200 / 25000"}


created_at: 2024-08-26 20:31:21
topic: persistent://default/default/47f0afae-77ee-4e4a-bcd4-0b050f4de62c
id: a8f7bfd3-68d0-4037-8877-0e53e64feb7c
encoding: FLOAT32
metadata:
{"url": "https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/Using_Weaviate_for_embeddings_search.ipynb", "title": "Using Weaviate for Embeddings Search", "tokens": 8799, "retrieve_doc": false, "source": "openai_cookbooks", "_node_content": "{\"id_\": \"a8f7bfd3-68d0-4037-8877-0e53e64feb7c\", \"embedding\": null, \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/Using_Weaviate_for_embeddings_search.ipynb\", \"title\": \"Using Weaviate for Embeddings Search\", \"tokens\": 8799, \"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\": \"105ad3e7-dd4e-4fc3-ad89-828cb68fd275\", \"node_type\": \"4\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/Using_Weaviate_for_embeddings_search.ipynb\", \"title\": \"Using Weaviate for Embeddings Search\", \"tokens\": 8799, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"f1e50e0a23cbd05a6303dce4eadd3e2a409b3265e3110a49323df38bcf426110\", \"class_name\": \"RelatedNodeInfo\"}, \"2\": {\"node_id\": \"3655ed68-78e3-4f66-9351-8056d183fb1a\", \"node_type\": \"1\", \"metadata\": {\"url\": \"https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/weaviate/Using_Weaviate_for_embeddings_search.ipynb\", \"title\": \"Using Weaviate for Embeddings Search\", \"tokens\": 8799, \"retrieve_doc\": false, \"source\": \"openai_cookbooks\"}, \"hash\": \"447e2a62615131256367c7ff71ec12aba63fad8e7f6f4df0ead7903ea7b212d5\", \"class_name\": \"RelatedNodeInfo\"}, \"3\": {\"node_id\": \"7430c852-9a75-410d-ac75-015ee60e5560\", \"node_type\": \"1\", \"metadata\": {}, \"hash\": \"4d2127694d0da5e7bdd5b1f8131be3765976240e348bcd183cd3fc898e763d42\", \"class_name\": \"RelatedNodeInfo\"}}, \"text\": \"\", \"mimetype\": \"text/plain\", \"start_char_idx\": 14895, \"end_char_idx\": 16487, \"text_template\": \"{metadata_str}\\n\\n{content}\", \"metadata_template\": \"{key}: {value}\", \"metadata_seperator\": \"\\n\", \"class_name\": \"TextNode\"}", "_node_type": "TextNode", "document_id": "105ad3e7-dd4e-4fc3-ad89-828cb68fd275", "doc_id": "105ad3e7-dd4e-4fc3-ad89-828cb68fd275", "ref_doc_id": "105ad3e7-dd4e-4fc3-ad89-828cb68fd275", "chroma:document": "Import 4000 / 25000 \n    Import 4100 / 25000 \n    Import 4200 / 25000 \n    Import 4300 / 25000 \n    Import 4400 / 25000 \n    Import 4500 / 25000 \n    Import 4600 / 25000 \n    Import 4700 / 25000 \n    Import 4800 / 25000 \n    Import 4900 / 25000 \n    Import 5000 / 25000 \n    Import 5100 / 25000 \n    Import 5200 / 25000 \n    Import 5300 / 25000 \n    Import 5400 / 25000 \n    Import 5500 / 25000 \n    Import 5600 / 25000 \n    Import 5700 / 25000 \n    Import 5800 / 25000 \n    Import 5900 / 25000 \n    Import 6000 / 25000 \n    Import 6100 / 25000 \n    Import 6200 / 25000 \n    Import 6300 / 25000 \n    Import 6400 / 25000 \n    Import 6500 / 25000 \n    Import 6600 / 25000 \n    Import 6700 / 25000 \n    Import 6800 / 25000 \n    Import 6900 / 25000 \n    Import 7000 / 25000 \n    Import 7100 / 25000 \n    Import 7200 / 25000 \n    Import 7300 / 25000 \n    Import 7400 / 25000 \n    Import 7500 / 25000 \n    Import 7600 / 25000 \n    Import 7700 / 25000 \n    Import 7800 / 25000 \n    Import 7900 / 25000 \n    Import 8000 / 25000 \n    Import 8100 / 25000 \n    Import 8200 / 25000 \n    Import 8300 / 25000 \n    Import 8400 / 25000 \n    Import 8500 / 25000 \n    Import 8600 / 25000 \n    Import 8700 / 25000 \n    Import 8800 / 25000 \n    Import 8900 / 25000 \n    Import 9000 / 25000 \n    Import 9100 / 25000 \n    Import 9200 / 25000 \n    Import 9300 / 25000 \n    Import 9400 / 25000 \n    Import 9500 / 25000 \n    Import 9600 / 25000 \n    Import 9700 / 25000 \n    Import 9800 / 25000 \n    Import 9900 / 25000 \n    Import 10000 / 25000 \n    Import 10100 / 25000 \n    Import 10200 / 25000 \n    Import 10300 /"}


