diff --git a/notebooks/integrations/openai/openai-KNN-RAG.ipynb b/notebooks/integrations/openai/openai-KNN-RAG.ipynb index 8f7ee867..d99e040c 100644 --- a/notebooks/integrations/openai/openai-KNN-RAG.ipynb +++ b/notebooks/integrations/openai/openai-KNN-RAG.ipynb @@ -292,7 +292,7 @@ "EMBEDDING_MODEL = \"text-embedding-ada-002\"\n", "\n", "# Define question\n", - "question = 'How wide is the Atlantic ocean?'\n", + "question = 'How big is the Atlantic ocean?'\n", "\n", "# Create embedding\n", "question_embedding = openai.Embedding.create(input=question, model=EMBEDDING_MODEL)\n" @@ -353,7 +353,8 @@ " \"num_candidates\": 100\n", " }\n", ")\n", - "pretty_response(response)" + "pretty_response(response)\n", + "top_hit_summary = response['hits']['hits'][0]['_source']['text'] # Store content of top hit for final step" ] }, { @@ -361,8 +362,6 @@ "id": "276c1147", "metadata": {}, "source": [ - "## Next steps\n", - "\n", "Success! Now you know how to use Elasticsearch as a vector database to store embeddings, encode queries by calling the OpenAI [`embeddings`](https://platform.openai.com/docs/api-reference/embeddings) endpoint, and run semantic search using [kNN search](https://www.elastic.co/guide/en/elasticsearch/reference/current/knn-search.html) to find the top results.\n", "\n", "Play around with different queries, and if you want to try with your own data, you can experiment with different embedding models.\n", @@ -395,7 +394,10 @@ " model=\"gpt-3.5-turbo\",\n", " messages=[\n", " {\"role\": \"system\", \"content\": \"You are a helpful assistant.\"},\n", - " {\"role\": \"user\", \"content\": \"Answer the following question:\" + question + \"by using the following text:\"},\n", + " {\"role\": \"user\", \"content\": \"Answer the following question:\" \n", + " + question \n", + " + \"by using the following text:\" \n", + " + top_hit_summary},\n", " ]\n", ")\n", "\n",