Skip to content

Commit a026d0f

Browse files
authored
Fix RAG prompt to pass top hit as context (#39)
* Fix RAG prompt to pass top hit as context * Update question * Multiline for GH preview
1 parent eaf6e8f commit a026d0f

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

notebooks/integrations/openai/openai-KNN-RAG.ipynb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@
292292
"EMBEDDING_MODEL = \"text-embedding-ada-002\"\n",
293293
"\n",
294294
"# Define question\n",
295-
"question = 'How wide is the Atlantic ocean?'\n",
295+
"question = 'How big is the Atlantic ocean?'\n",
296296
"\n",
297297
"# Create embedding\n",
298298
"question_embedding = openai.Embedding.create(input=question, model=EMBEDDING_MODEL)\n"
@@ -353,16 +353,15 @@
353353
" \"num_candidates\": 100\n",
354354
" }\n",
355355
")\n",
356-
"pretty_response(response)"
356+
"pretty_response(response)\n",
357+
"top_hit_summary = response['hits']['hits'][0]['_source']['text'] # Store content of top hit for final step"
357358
]
358359
},
359360
{
360361
"cell_type": "markdown",
361362
"id": "276c1147",
362363
"metadata": {},
363364
"source": [
364-
"## Next steps\n",
365-
"\n",
366365
"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",
367366
"\n",
368367
"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 @@
395394
" model=\"gpt-3.5-turbo\",\n",
396395
" messages=[\n",
397396
" {\"role\": \"system\", \"content\": \"You are a helpful assistant.\"},\n",
398-
" {\"role\": \"user\", \"content\": \"Answer the following question:\" + question + \"by using the following text:\"},\n",
397+
" {\"role\": \"user\", \"content\": \"Answer the following question:\" \n",
398+
" + question \n",
399+
" + \"by using the following text:\" \n",
400+
" + top_hit_summary},\n",
399401
" ]\n",
400402
")\n",
401403
"\n",

0 commit comments

Comments
 (0)