From 55229321245a81a9574cdfa571c61fb6c30aee9d Mon Sep 17 00:00:00 2001
From: Anush <anushshetty90@gmail.com>
Date: Fri, 8 Mar 2024 22:36:05 +0530
Subject: [PATCH] docs: Updated Qdrant usage examples (#11768)

* docs: Update QdrantIndexDemo.ipynb

* docs: Updated QdrantIndexDemo.ipynb

* chore: Update example model
---
 .../vector_stores/QdrantIndexDemo.ipynb       | 53 ++++++++++++-------
 1 file changed, 33 insertions(+), 20 deletions(-)

diff --git a/docs/examples/vector_stores/QdrantIndexDemo.ipynb b/docs/examples/vector_stores/QdrantIndexDemo.ipynb
index 32581bf169..39a19f8d17 100644
--- a/docs/examples/vector_stores/QdrantIndexDemo.ipynb
+++ b/docs/examples/vector_stores/QdrantIndexDemo.ipynb
@@ -1,7 +1,6 @@
 {
  "cells": [
   {
-   "attachments": {},
    "cell_type": "markdown",
    "id": "dd821a8d",
    "metadata": {},
@@ -32,7 +31,7 @@
    "metadata": {},
    "outputs": [],
    "source": [
-    "%pip install llama-index-vector-stores-qdrant"
+    "%pip install llama-index-vector-stores-qdrant llama-index-readers-file llama-index-embeddings-fastembed llama-index-llms-openai"
    ]
   },
   {
@@ -50,7 +49,11 @@
     "from IPython.display import Markdown, display\n",
     "from llama_index.core import VectorStoreIndex, SimpleDirectoryReader\n",
     "from llama_index.core import StorageContext\n",
-    "from llama_index.vector_stores.qdrant import QdrantVectorStore"
+    "from llama_index.vector_stores.qdrant import QdrantVectorStore\n",
+    "from llama_index.embeddings.fastembed import FastEmbedEmbedding\n",
+    "from llama_index.core import Settings\n",
+    "\n",
+    "Settings.embed_model = FastEmbedEmbedding(model_name=\"BAAI/bge-base-en-v1.5\")"
    ]
   },
   {
@@ -58,21 +61,29 @@
    "id": "07489add",
    "metadata": {},
    "source": [
-    "If running this for the first, time, install using this command: \n",
+    "If running for the first, time, install the dependencies using:\n",
     "\n",
     "```\n",
-    "!pip install -U qdrant_client\n",
+    "!pip install -U qdrant_client fastembed\n",
     "```"
    ]
   },
+  {
+   "cell_type": "markdown",
+   "id": "wGLkbqIm4XIe",
+   "metadata": {},
+   "source": [
+    "Set your OpenAI key for authenticating the LLM"
+   ]
+  },
   {
    "cell_type": "code",
    "execution_count": null,
-   "id": "86d852a3",
+   "id": "uI25Wj6x4SrT",
    "metadata": {},
    "outputs": [],
    "source": [
-    "os.environ[\"OPENAI_API_KEY\"] = \"YOUR OPENAI API KEY\""
+    "%env OPENAI_API_KEY=<YOUR_OPENAI_API_KEY>"
    ]
   },
   {
@@ -87,7 +98,6 @@
    ]
   },
   {
-   "attachments": {},
    "cell_type": "markdown",
    "id": "c475d645",
    "metadata": {},
@@ -196,7 +206,7 @@
     {
      "data": {
       "text/markdown": [
-       "<b>The author worked on writing and programming outside of school before college. They wrote short stories and tried writing programs on the IBM 1401 computer. They also mentioned getting a microcomputer, specifically a TRS-80, and started programming on it.</b>"
+       "<b>The author worked on writing and programming before college.</b>"
       ],
       "text/plain": [
        "<IPython.core.display.Markdown object>"
@@ -233,7 +243,7 @@
     {
      "data": {
       "text/markdown": [
-       "<b>After his time at Viaweb, the author decided to pursue his passion for painting. He left Yahoo, where he had been working after Viaweb was acquired, and immediately started painting. However, he struggled with energy and ambition, and eventually returned to New York to resume his old life as a painter.</b>"
+       "<b>The author arranged to do freelance work for a group that did projects for customers after his time at Viaweb.</b>"
       ],
       "text/plain": [
        "<IPython.core.display.Markdown object>"
@@ -277,13 +287,13 @@
    "metadata": {},
    "outputs": [],
    "source": [
-    "client = qdrant_client.QdrantClient(\n",
-    "    # location=\":memory:\"\n",
-    "    # Async upsertion does not work\n",
-    "    # on 'memory' location and requires\n",
-    "    # Qdrant to be deployed somewhere.\n",
-    "    url=\"http://localhost:6334\",\n",
-    "    prefer_grpc=True,\n",
+    "aclient = qdrant_client.AsyncQdrantClient(\n",
+    "    # you can use :memory: mode for fast and light-weight experiments,\n",
+    "    # it does not require to have Qdrant deployed anywhere\n",
+    "    # but requires qdrant-client >= 1.1.1\n",
+    "    location=\":memory:\"\n",
+    "    # otherwise set Qdrant instance address with:\n",
+    "    # uri=\"http://<host>:<port>\"\n",
     "    # set API KEY for Qdrant Cloud\n",
     "    # api_key=\"<qdrant-api-key>\",\n",
     ")"
@@ -297,7 +307,7 @@
    "outputs": [],
    "source": [
     "vector_store = QdrantVectorStore(\n",
-    "    client=client, collection_name=\"paul_graham\", prefer_grpc=True\n",
+    "    aclient=aclient, collection_name=\"paul_graham\", prefer_grpc=True\n",
     ")\n",
     "storage_context = StorageContext.from_defaults(vector_store=vector_store)\n",
     "index = VectorStoreIndex.from_documents(\n",
@@ -335,7 +345,7 @@
     {
      "data": {
       "text/markdown": [
-       "<b>The author worked on writing and programming outside of school. They wrote short stories and tried writing programs on the IBM 1401 computer. They also built a microcomputer and started programming on it, writing simple games and a word processor.</b>"
+       "<b>The author worked on writing short stories and programming, particularly on an IBM 1401 computer in 9th grade using an early version of Fortran. Later, the author transitioned to working on microcomputers, starting with a TRS-80 in about 1980, where they wrote simple games, programs, and a word processor.</b>"
       ],
       "text/plain": [
        "<IPython.core.display.Markdown object>"
@@ -372,7 +382,7 @@
     {
      "data": {
       "text/markdown": [
-       "<b>After his time at Viaweb, the author started working on a new idea. He decided to move to Cambridge and start a new company. However, he faced difficulties in finding a partner to work on the idea with him. Eventually, he recruited a team and began building a new dialect of Lisp called Arc. He also gave a talk at a Lisp conference and posted a file of the talk online, which gained a significant audience.</b>"
+       "<b>The author went on to co-found Y Combinator after his time at Viaweb.</b>"
       ],
       "text/plain": [
        "<IPython.core.display.Markdown object>"
@@ -388,6 +398,9 @@
   }
  ],
  "metadata": {
+  "colab": {
+   "provenance": []
+  },
   "kernelspec": {
    "display_name": "Python 3 (ipykernel)",
    "language": "python",
-- 
GitLab