|
292 | 292 | "EMBEDDING_MODEL = \"text-embedding-ada-002\"\n",
|
293 | 293 | "\n",
|
294 | 294 | "# Define question\n",
|
295 |
| - "question = 'How wide is the Atlantic ocean?'\n", |
| 295 | + "question = 'How big is the Atlantic ocean?'\n", |
296 | 296 | "\n",
|
297 | 297 | "# Create embedding\n",
|
298 | 298 | "question_embedding = openai.Embedding.create(input=question, model=EMBEDDING_MODEL)\n"
|
|
353 | 353 | " \"num_candidates\": 100\n",
|
354 | 354 | " }\n",
|
355 | 355 | ")\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" |
357 | 358 | ]
|
358 | 359 | },
|
359 | 360 | {
|
360 | 361 | "cell_type": "markdown",
|
361 | 362 | "id": "276c1147",
|
362 | 363 | "metadata": {},
|
363 | 364 | "source": [
|
364 |
| - "## Next steps\n", |
365 |
| - "\n", |
366 | 365 | "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",
|
367 | 366 | "\n",
|
368 | 367 | "Play around with different queries, and if you want to try with your own data, you can experiment with different embedding models.\n",
|
|
395 | 394 | " model=\"gpt-3.5-turbo\",\n",
|
396 | 395 | " messages=[\n",
|
397 | 396 | " {\"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", |
399 | 401 | " ]\n",
|
400 | 402 | ")\n",
|
401 | 403 | "\n",
|
|
0 commit comments