Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updating opensearch imports #19

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ For more examples, you may also find our [Blog](https://haystack.deepset.ai/blog
| Use Gemini Models with Vertex AI| <a href="https://colab.research.google.com/github/deepset-ai/haystack-cookbook/blob/main/notebooks/vertexai-gemini-examples.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a>|
| Gradient AI Embedders and Generators for RAG | <a href="https://colab.research.google.com/github/deepset-ai/haystack-cookbook/blob/main/notebooks/gradient-embeders-and-generators-for-notion-rag.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a>|
| Mixtral 8x7B with Hugging Face TGI for Web QA | <a href="https://colab.research.google.com/github/deepset-ai/haystack-cookbook/blob/main/notebooks/mixtral-8x7b-for-web-qa.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a>|
| Amazong Bedrock and OpenSearch for PDF QA | <a href="https://colab.research.google.com/github/deepset-ai/haystack-cookbook/blob/main/notebooks/amazon_bedrock_for_documentation_qa.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a>|
| Use Zephyr 7B Beta with Hugging Face for RAG | <a href="https://colab.research.google.com/github/deepset-ai/haystack-cookbook/blob/main/notebooks/zephyr-7b-beta-for-rag.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a>|
| Hacker News RAG with Custom Component | <a href="https://colab.research.google.com/github/deepset-ai/haystack-cookbook/blob/main/notebooks/hackernews-custom-component-rag.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a>|
| Use Chroma for RAG and Indexing | <a href="https://colab.research.google.com/github/deepset-ai/haystack-cookbook/blob/main/notebooks/chroma-indexing-and-rag-examples.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a>|
Expand Down
98 changes: 27 additions & 71 deletions notebooks/amazon_bedrock_for_documentation_qa.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"metadata": {
"id": "chi-VAhGeuQn"
},
Expand Down Expand Up @@ -96,7 +96,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"metadata": {
"id": "Vaxe75MXkMi2"
},
Expand All @@ -117,7 +117,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"metadata": {
"id": "f9gbVwRU_Y5Q"
},
Expand Down Expand Up @@ -169,7 +169,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": null,
"metadata": {
"id": "SrBctAl5e_Kf"
},
Expand All @@ -182,7 +182,7 @@
"from haystack.components.preprocessors import DocumentCleaner, DocumentSplitter\n",
"from haystack.components.writers import DocumentWriter\n",
"from haystack.document_stores import DuplicatePolicy\n",
"from opensearch_haystack import OpenSearchDocumentStore\n",
"from haystack_integrations.document_stores.opensearch import OpenSearchDocumentStore\n",
"\n",
"## Initialize the OpenSearchDocumentStore\n",
"document_store = OpenSearchDocumentStore()\n",
Expand Down Expand Up @@ -241,7 +241,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": null,
"metadata": {
"id": "8Q3JYuyShRnQ"
},
Expand All @@ -250,7 +250,7 @@
"from haystack.components.builders import PromptBuilder\n",
"from haystack.pipeline import Pipeline\n",
"from amazon_bedrock_haystack.generators.amazon_bedrock import AmazonBedrockGenerator\n",
"from opensearch_haystack import OpenSearchBM25Retriever\n",
"from haystack_integrations.components.retrievers.opensearch import OpenSearchBM25Retriever\n",
"\n",
"## Create pipeline components\n",
"retriever = OpenSearchBM25Retriever(document_store=document_store, top_k=15)\n",
Expand Down Expand Up @@ -295,24 +295,15 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "mDYCSRRtiAy5",
"outputId": "671da188-ed15-48e7-958f-0e1343faf458"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Amazon Bedrock is a fully managed service that makes high-performing foundation models (FMs) from leading AI startups and Amazon available for your use through a unified API. You can choose from a wide range of foundation models to find the model that is best suited for your use case. Amazon Bedrock also offers a broad set of capabilities to build generative AI applications with security, privacy, and responsible AI. Using Amazon Bedrock, you can easily experiment with and evaluate top foundation models for your use cases, privately customize them with your data using techniques such as fine-tuning and Retrieval Augmented Generation (RAG), and build agents that execute tasks using your enterprise systems and data sources.\n",
"With Amazon Bedrock's serverless experience, you can get started quickly, privately customize foundation models with your own data, and easily and securely integrate and deploy them into your applications using AWS tools without having to manage any infrastructure.\n"
]
}
],
"outputs": [],
"source": [
"question = \"What is Amazon Bedrock?\"\n",
"response = rag_pipeline.run({\"retriever\": {\"query\": question}, \"prompt_builder\": {\"question\": question}})\n",
Expand All @@ -322,29 +313,15 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "giSWajzyAcNp",
"outputId": "0ec1dcc6-4a28-4815-f9b4-7c073584c20e"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"To setup Amazon Bedrock, follow these steps:\n",
"1. Sign up for an AWS account\n",
"2. Create an administrative user\n",
"3. Grant programmatic access\n",
"4. Console access\n",
"5. Model access\n",
"6. Set up the Amazon Bedrock API\n"
]
}
],
"outputs": [],
"source": [
"question = \"How can I setup Amazon Bedrock?\"\n",
"response = rag_pipeline.run({\"retriever\": {\"query\": question}, \"prompt_builder\": {\"question\": question}})\n",
Expand All @@ -354,23 +331,15 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "ROhJ8VL_JdHc",
"outputId": "76f73ed3-4fb3-4def-b88e-bbfde218cb7e"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Amazon Bedrock supports fine-tuning of foundation models through model customization jobs. You can create a model customization job by providing a training dataset that you own. During a model customization job, you can tune the hyperparameters of the model to improve its performance on your specific task or domain. For more information, see Custom models.\n"
]
}
],
"outputs": [],
"source": [
"question = \"How can I finetune foundation models?\"\n",
"response = rag_pipeline.run({\"retriever\": {\"query\": question}, \"prompt_builder\": {\"question\": question}})\n",
Expand All @@ -380,29 +349,15 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "9ohsesYDgsSq",
"outputId": "2ab326d4-4279-424a-a826-10dfcbe3c00d"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"When formulating your prompts for Amazon Titan models, it's important to consider the task or instruction you want the models to perform, the context of the task, demonstration examples, and the input text that you want the models to use in their response. Depending on your use case, the availability of data, and the task, your prompt should combine one or more of these components.\n",
"\n",
"For example, if you're asking the model to summarize a text, you might include the text itself, the task or instruction (\"Summarize the text\"), demonstration examples (\"Example summaries\"), and the input text (\"The following is text from a restaurant review: \\\"I finally got to check out Alessandro's Brilliant Pizza and it is now one of my favorite restaurants in Seattle. The dining room has a beautiful view over the Puget Sound but it was surprisingly not crowded. I ordered the fried castelvetrano olives, a spicy Neapolitan-style pizza and a gnocchi dish. The olives were absolutely decadent, and the pizza came with a smoked mozzarella, which was delicious. The gnocchi was fresh and wonderful. The waitstaff were attentive, and overall the experience was lovely. I hope to return soon.\\\"\")\n",
"\n",
"By providing this information, you can help the model understand the task and generate a more accurate and relevant response.\n",
"\n",
"Remember that the success of Amazon Titan models depends on the quality and relevance of your prompts, so it's essential to spend time experimenting and refining your approach to get the best results.\n"
]
}
],
"outputs": [],
"source": [
"question = \"How should I form my prompts for Amazon Titan models?\"\n",
"response = rag_pipeline.run({\"retriever\": {\"query\": question}, \"prompt_builder\": {\"question\": question}})\n",
Expand All @@ -412,23 +367,15 @@
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "__NGWZdqh_dJ",
"outputId": "26c84bf3-9401-438a-bac5-1032a5d9c20e"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"When using Claude models with Amazon Bedrock, it's important to wrap your prompts in a conversational style to get desired responses. The main content of the prompt should be wrapped like this: \\n\\nHuman: {{Main Content}}\\n\\nAssistant:. For Claude models, prompts sent via the API must contain \\n\\nHuman: and \\n\\nAssistant:.\n"
]
}
],
"outputs": [],
"source": [
"question = \"How should I form my prompts for Claude models?\"\n",
"response = rag_pipeline.run({\"retriever\": {\"query\": question}, \"prompt_builder\": {\"question\": question}})\n",
Expand All @@ -447,7 +394,16 @@
"name": "python3"
},
"language_info": {
"name": "python"
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
}
},
"nbformat": 4,
Expand Down