|
10 | 10 | "\n",
|
11 | 11 | "- **Level**: Beginner\n",
|
12 | 12 | "- **Time to complete**: 10 minutes\n",
|
13 |
| - "- **Components Used**: [`InMemoryDocumentStore`](https://docs.haystack.deepset.ai/v2.0/docs/inmemorydocumentstore), [`SentenceTransformersDocumentEmbedder`](https://docs.haystack.deepset.ai/v2.0/docs/sentencetransformersdocumentembedder), [`SentenceTransformersTextEmbedder`](https://docs.haystack.deepset.ai/v2.0/docs/sentencetransformerstextembedder), [`InMemoryEmbeddingRetriever`](https://docs.haystack.deepset.ai/v2.0/docs/inmemoryembeddingretriever), [`PromptBuilder`](https://docs.haystack.deepset.ai/v2.0/docs/promptbuilder), [`OpenAIGenerator`](https://docs.haystack.deepset.ai/v2.0/docs/openaigenerator)\n", |
| 13 | + "- **Components Used**: [`InMemoryDocumentStore`](https://docs.haystack.deepset.ai/docs/inmemorydocumentstore), [`SentenceTransformersDocumentEmbedder`](https://docs.haystack.deepset.ai/docs/sentencetransformersdocumentembedder), [`SentenceTransformersTextEmbedder`](https://docs.haystack.deepset.ai/docs/sentencetransformerstextembedder), [`InMemoryEmbeddingRetriever`](https://docs.haystack.deepset.ai/docs/inmemoryembeddingretriever), [`PromptBuilder`](https://docs.haystack.deepset.ai/docs/promptbuilder), [`OpenAIGenerator`](https://docs.haystack.deepset.ai/docs/openaigenerator)\n", |
14 | 14 | "- **Prerequisites**: You must have an [OpenAI API Key](https://platform.openai.com/api-keys).\n",
|
15 | 15 | "- **Goal**: After completing this tutorial, you'll have learned the new prompt syntax and how to use PromptBuilder and OpenAIGenerator to build a generative question-answering pipeline with retrieval-augmentation.\n",
|
16 | 16 | "\n",
|
|
25 | 25 | "source": [
|
26 | 26 | "## Overview\n",
|
27 | 27 | "\n",
|
28 |
| - "This tutorial shows you how to create a generative question-answering pipeline using the retrieval-augmentation ([RAG](https://www.deepset.ai/blog/llms-retrieval-augmentation)) approach with Haystack 2.0. The process involves four main components: [SentenceTransformersTextEmbedder](https://docs.haystack.deepset.ai/v2.0/docs/sentencetransformerstextembedder) for creating an embedding for the user query, [InMemoryBM25Retriever](https://docs.haystack.deepset.ai/v2.0/docs/inmemorybm25retriever) for fetching relevant documents, [PromptBuilder](https://docs.haystack.deepset.ai/v2.0/docs/promptbuilder) for creating a template prompt, and [OpenAIGenerator](https://docs.haystack.deepset.ai/v2.0/docs/openaigenerator) for generating responses.\n", |
| 28 | + "This tutorial shows you how to create a generative question-answering pipeline using the retrieval-augmentation ([RAG](https://www.deepset.ai/blog/llms-retrieval-augmentation)) approach with Haystack 2.0. The process involves four main components: [SentenceTransformersTextEmbedder](https://docs.haystack.deepset.ai/docs/sentencetransformerstextembedder) for creating an embedding for the user query, [InMemoryBM25Retriever](https://docs.haystack.deepset.ai/docs/inmemorybm25retriever) for fetching relevant documents, [PromptBuilder](https://docs.haystack.deepset.ai/docs/promptbuilder) for creating a template prompt, and [OpenAIGenerator](https://docs.haystack.deepset.ai/docs/openaigenerator) for generating responses.\n", |
29 | 29 | "\n",
|
30 | 30 | "For this tutorial, you'll use the Wikipedia pages of [Seven Wonders of the Ancient World](https://en.wikipedia.org/wiki/Wonders_of_the_World) as Documents, but you can replace them with any text you want.\n"
|
31 | 31 | ]
|
|
38 | 38 | "source": [
|
39 | 39 | "## Preparing the Colab Environment\n",
|
40 | 40 | "\n",
|
41 |
| - "- [Enable GPU Runtime in Colab](https://docs.haystack.deepset.ai/v2.0/docs/enabling-gpu-acceleration)\n", |
42 |
| - "- [Set logging level to INFO](https://docs.haystack.deepset.ai/v2.0/docs/logging)" |
| 41 | + "- [Enable GPU Runtime in Colab](https://docs.haystack.deepset.ai/docs/enabling-gpu-acceleration)\n", |
| 42 | + "- [Set logging level to INFO](https://docs.haystack.deepset.ai/docs/logging)" |
43 | 43 | ]
|
44 | 44 | },
|
45 | 45 | {
|
|
183 | 183 | "source": [
|
184 | 184 | "### Enabling Telemetry\n",
|
185 | 185 | "\n",
|
186 |
| - "Knowing you're using this tutorial helps us decide where to invest our efforts to build a better product but you can always opt out by commenting the following line. See [Telemetry](https://docs.haystack.deepset.ai/v2.0/docs/enabling-telemetry) for more details." |
| 186 | + "Knowing you're using this tutorial helps us decide where to invest our efforts to build a better product but you can always opt out by commenting the following line. See [Telemetry](https://docs.haystack.deepset.ai/docs/enabling-telemetry) for more details." |
187 | 187 | ]
|
188 | 188 | },
|
189 | 189 | {
|
|
301 | 301 | "source": [
|
302 | 302 | "### Initalize a Document Embedder\n",
|
303 | 303 | "\n",
|
304 |
| - "To store your data in the DocumentStore with embeddings, initialize a [SentenceTransformersDocumentEmbedder](https://docs.haystack.deepset.ai/v2.0/docs/sentencetransformersdocumentembedder) with the model name and call `warm_up()` to download the embedding model.\n", |
| 304 | + "To store your data in the DocumentStore with embeddings, initialize a [SentenceTransformersDocumentEmbedder](https://docs.haystack.deepset.ai/docs/sentencetransformersdocumentembedder) with the model name and call `warm_up()` to download the embedding model.\n", |
305 | 305 | "\n",
|
306 |
| - "> If you'd like, you can use a different [Embedder](https://docs.haystack.deepset.ai/v2.0/docs/embedders) for your documents." |
| 306 | + "> If you'd like, you can use a different [Embedder](https://docs.haystack.deepset.ai/docs/embedders) for your documents." |
307 | 307 | ]
|
308 | 308 | },
|
309 | 309 | {
|
|
407 | 407 | "source": [
|
408 | 408 | "## Building the RAG Pipeline\n",
|
409 | 409 | "\n",
|
410 |
| - "The next step is to build a [Pipeline](https://docs.haystack.deepset.ai/v2.0/docs/pipelines) to generate answers for the user query following the RAG approach. To create the pipeline, you first need to initialize each component, add them to your pipeline, and connect them." |
| 410 | + "The next step is to build a [Pipeline](https://docs.haystack.deepset.ai/docs/pipelines) to generate answers for the user query following the RAG approach. To create the pipeline, you first need to initialize each component, add them to your pipeline, and connect them." |
411 | 411 | ]
|
412 | 412 | },
|
413 | 413 | {
|
|
444 | 444 | "source": [
|
445 | 445 | "### Initialize the Retriever\n",
|
446 | 446 | "\n",
|
447 |
| - "Initialize a [InMemoryEmbeddingRetriever](https://docs.haystack.deepset.ai/v2.0/docs/inmemoryembeddingretriever) and make it use the InMemoryDocumentStore you initialized earlier in this tutorial. This Retriever will get the relevant documents to the query." |
| 447 | + "Initialize a [InMemoryEmbeddingRetriever](https://docs.haystack.deepset.ai/docs/inmemoryembeddingretriever) and make it use the InMemoryDocumentStore you initialized earlier in this tutorial. This Retriever will get the relevant documents to the query." |
448 | 448 | ]
|
449 | 449 | },
|
450 | 450 | {
|
|
470 | 470 | "\n",
|
471 | 471 | "Create a custom prompt for a generative question answering task using the RAG approach. The prompt should take in two parameters: `documents`, which are retrieved from a document store, and a `question` from the user. Use the Jinja2 looping syntax to combine the content of the retrieved documents in the prompt.\n",
|
472 | 472 | "\n",
|
473 |
| - "Next, initialize a [PromptBuilder](https://docs.haystack.deepset.ai/v2.0/docs/promptbuilder) instance with your prompt template. The PromptBuilder, when given the necessary values, will automatically fill in the variable values and generate a complete prompt. This approach allows for a more tailored and effective question-answering experience." |
| 473 | + "Next, initialize a [PromptBuilder](https://docs.haystack.deepset.ai/docs/promptbuilder) instance with your prompt template. The PromptBuilder, when given the necessary values, will automatically fill in the variable values and generate a complete prompt. This approach allows for a more tailored and effective question-answering experience." |
474 | 474 | ]
|
475 | 475 | },
|
476 | 476 | {
|
|
507 | 507 | "### Initialize a Generator\n",
|
508 | 508 | "\n",
|
509 | 509 | "\n",
|
510 |
| - "Generators are the components that interact with large language models (LLMs). Now, set `OPENAI_API_KEY` environment variable and initialize a [OpenAIGenerator](https://docs.haystack.deepset.ai/v2.0/docs/OpenAIGenerator) that can communicate with OpenAI GPT models. As you initialize, provide a model name:" |
| 510 | + "Generators are the components that interact with large language models (LLMs). Now, set `OPENAI_API_KEY` environment variable and initialize a [OpenAIGenerator](https://docs.haystack.deepset.ai/docs/OpenAIGenerator) that can communicate with OpenAI GPT models. As you initialize, provide a model name:" |
511 | 511 | ]
|
512 | 512 | },
|
513 | 513 | {
|
|
545 | 545 | "id": "nenbo2SvycHd"
|
546 | 546 | },
|
547 | 547 | "source": [
|
548 |
| - "> You can replace `OpenAIGenerator` in your pipeline with another `Generator`. Check out the full list of generators [here](https://docs.haystack.deepset.ai/v2.0/docs/generators)." |
| 548 | + "> You can replace `OpenAIGenerator` in your pipeline with another `Generator`. Check out the full list of generators [here](https://docs.haystack.deepset.ai/docs/generators)." |
549 | 549 | ]
|
550 | 550 | },
|
551 | 551 | {
|
|
558 | 558 | "\n",
|
559 | 559 | "To build a pipeline, add all components to your pipeline and connect them. Create connections from `text_embedder`'s \"embedding\" output to \"query_embedding\" input of `retriever`, from `retriever` to `prompt_builder` and from `prompt_builder` to `llm`. Explicitly connect the output of `retriever` with \"documents\" input of the `prompt_builder` to make the connection obvious as `prompt_builder` has two inputs (\"documents\" and \"question\").\n",
|
560 | 560 | "\n",
|
561 |
| - "For more information on pipelines and creating connections, refer to [Creating Pipelines](https://docs.haystack.deepset.ai/v2.0/docs/creating-pipelines) documentation." |
| 561 | + "For more information on pipelines and creating connections, refer to [Creating Pipelines](https://docs.haystack.deepset.ai/docs/creating-pipelines) documentation." |
562 | 562 | ]
|
563 | 563 | },
|
564 | 564 | {
|
|
0 commit comments