From 4cd74c0c923a254ff3cc16628cc1389f48475bc9 Mon Sep 17 00:00:00 2001 From: Jacob Lee Date: Mon, 5 Aug 2024 12:29:06 -0700 Subject: [PATCH] docs[patch]: Update AWS Kendra docs (#6380) * Update AWS Kendra docs * Update kendra-retriever.ipynb --- .../docs/integrations/retrievers/exa.ipynb | 6 +- .../retrievers/kendra-retriever.ipynb | 233 ++++++++++++++++++ .../retrievers/kendra-retriever.mdx | 29 --- 3 files changed, 237 insertions(+), 31 deletions(-) create mode 100644 docs/core_docs/docs/integrations/retrievers/kendra-retriever.ipynb delete mode 100644 docs/core_docs/docs/integrations/retrievers/kendra-retriever.mdx diff --git a/docs/core_docs/docs/integrations/retrievers/exa.ipynb b/docs/core_docs/docs/integrations/retrievers/exa.ipynb index ea1d9a8ddc37..795f5fdc7d12 100644 --- a/docs/core_docs/docs/integrations/retrievers/exa.ipynb +++ b/docs/core_docs/docs/integrations/retrievers/exa.ipynb @@ -23,13 +23,15 @@ "\n", "## Overview\n", "\n", - "This will help you getting started with the [ExaRetriever](/docs/concepts/#retrievers). For detailed documentation of all ExaRetriever features and configurations head to the [API reference](https://api.js.langchain.com/classes/langchain_exa.ExaRetriever.html).\n", + "[Exa](https://exa.ai/) is a search engine that retrieves relevant content from the web given some input query.\n", + "\n", + "This guide will help you getting started with the Exa [retriever](/docs/concepts/#retrievers). For detailed documentation of all `ExaRetriever` features and configurations head to the [API reference](https://api.js.langchain.com/classes/langchain_exa.ExaRetriever.html).\n", "\n", "### Integration details\n", "\n", "| Retriever | Source | Package |\n", "| :--- | :--- | :---: |\n", - "[ExaRetriever](https://api.js.langchain.com/classes/langchain_exa.ExaRetriever.html) | Information on the web. | @langchain/exa |\n", + "[ExaRetriever](https://api.js.langchain.com/classes/langchain_exa.ExaRetriever.html) | Information on the web. | [`@langchain/exa`](https://www.npmjs.com/package/@langchain/exa) |\n", "\n", "## Setup\n", "\n", diff --git a/docs/core_docs/docs/integrations/retrievers/kendra-retriever.ipynb b/docs/core_docs/docs/integrations/retrievers/kendra-retriever.ipynb new file mode 100644 index 000000000000..ad8c5da4751f --- /dev/null +++ b/docs/core_docs/docs/integrations/retrievers/kendra-retriever.ipynb @@ -0,0 +1,233 @@ +{ + "cells": [ + { + "cell_type": "raw", + "id": "afaf8039", + "metadata": { + "vscode": { + "languageId": "raw" + } + }, + "source": [ + "---\n", + "sidebar_label: Amazon Kendra Retriever\n", + "---" + ] + }, + { + "cell_type": "markdown", + "id": "e49f1e0d", + "metadata": {}, + "source": [ + "# AWSKendraRetriever\n", + "\n", + "## Overview\n", + "\n", + "[Amazon Kendra](https://aws.amazon.com/kendra/) is an intelligent search service provided by Amazon Web Services (AWS).\n", + "It utilizes advanced natural language processing (NLP) and machine learning algorithms to enable powerful search capabilities across various data sources within an organization.\n", + "Kendra is designed to help users find the information they need quickly and accurately, improving productivity and decision-making.\n", + "\n", + "With Kendra, users can search across a wide range of content types, including documents, FAQs, knowledge bases, manuals, and websites.\n", + "It supports multiple languages and can understand complex queries, synonyms, and contextual meanings to provide highly relevant search results.\n", + "\n", + "This will help you getting started with the Amazon Kendra [`retriever`](/docs/concepts/#retrievers). For detailed documentation of all `AWSKendraRetriever` features and configurations head to the [API reference](https://api.js.langchain.com/classes/langchain_aws.AmazonKendraRetriever.html).\n", + "\n", + "### Integration details\n", + "\n", + "| Retriever | Source | Package |\n", + "| :--- | :--- | :---: |\n", + "[AWSKendraRetriever](https://api.js.langchain.com/classes/langchain_aws.AmazonKendraRetriever.html) | Various AWS resources | [`@langchain/aws`](https://www.npmjs.com/package/@langchain/aws) |\n", + "\n", + "## Setup\n", + "\n", + "You'll need an AWS account and an Amazon Kendra instance to get started. See this [tutorial](https://docs.aws.amazon.com/kendra/latest/dg/getting-started.html) from AWS for more information.\n", + "\n", + "If you want to get automated tracing from individual queries, you can also set your [LangSmith](https://docs.smith.langchain.com/) API key by uncommenting below:\n", + "\n", + "```typescript\n", + "// process.env.LANGSMITH_API_KEY = \"\";\n", + "// process.env.LANGSMITH_TRACING = \"true\";\n", + "```\n", + "\n", + "### Installation\n", + "\n", + "This retriever lives in the `@langchain/aws` package:\n", + "\n", + "```{=mdx}\n", + "import IntegrationInstallTooltip from \"@mdx_components/integration_install_tooltip.mdx\";\n", + "import Npm2Yarn from \"@theme/Npm2Yarn\";\n", + "\n", + "\n", + "\n", + "\n", + " @langchain/aws\n", + "\n", + "```" + ] + }, + { + "cell_type": "markdown", + "id": "a38cde65-254d-4219-a441-068766c0d4b5", + "metadata": {}, + "source": [ + "## Instantiation\n", + "\n", + "Now we can instantiate our retriever:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "70cc8e65-2a02-408a-bbc6-8ef649057d82", + "metadata": {}, + "outputs": [], + "source": [ + "import { AmazonKendraRetriever } from \"@langchain/aws\";\n", + "\n", + "const retriever = new AmazonKendraRetriever({\n", + " topK: 10,\n", + " indexId: \"YOUR_INDEX_ID\",\n", + " region: \"us-east-2\", // Your region\n", + " clientOptions: {\n", + " credentials: {\n", + " accessKeyId: \"YOUR_ACCESS_KEY_ID\",\n", + " secretAccessKey: \"YOUR_SECRET_ACCESS_KEY\",\n", + " },\n", + " },\n", + "});" + ] + }, + { + "cell_type": "markdown", + "id": "5c5f2839-4020-424e-9fc9-07777eede442", + "metadata": {}, + "source": [ + "## Usage" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "51a60dbe-9f2e-4e04-bb62-23968f17164a", + "metadata": {}, + "outputs": [], + "source": [ + "const query = \"...\"\n", + "\n", + "await retriever.invoke(query);" + ] + }, + { + "cell_type": "markdown", + "id": "dfe8aad4-8626-4330-98a9-7ea1ca5d2e0e", + "metadata": {}, + "source": [ + "## Use within a chain\n", + "\n", + "Like other retrievers, __module_name__ can be incorporated into LLM applications via [chains](/docs/how_to/sequence/).\n", + "\n", + "We will need a LLM or chat model:\n", + "\n", + "```{=mdx}\n", + "import ChatModelTabs from \"@theme/ChatModelTabs\";\n", + "\n", + "\n", + "```" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "25b647a3-f8f2-4541-a289-7a241e43f9df", + "metadata": {}, + "outputs": [], + "source": [ + "// @ls-docs-hide-cell\n", + "\n", + "import { ChatOpenAI } from \"@langchain/openai\";\n", + "\n", + "const llm = new ChatOpenAI({\n", + " model: \"gpt-4o-mini\",\n", + " temperature: 0,\n", + "});" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "23e11cc9-abd6-4855-a7eb-799f45ca01ae", + "metadata": {}, + "outputs": [], + "source": [ + "import { ChatPromptTemplate } from \"@langchain/core/prompts\";\n", + "import { RunnablePassthrough, RunnableSequence } from \"@langchain/core/runnables\";\n", + "import { StringOutputParser } from \"@langchain/core/output_parsers\";\n", + "\n", + "import type { Document } from \"@langchain/core/documents\";\n", + "\n", + "const prompt = ChatPromptTemplate.fromTemplate(`\n", + "Answer the question based only on the context provided.\n", + "\n", + "Context: {context}\n", + "\n", + "Question: {question}`);\n", + "\n", + "const formatDocs = (docs: Document[]) => {\n", + " return docs.map((doc) => doc.pageContent).join(\"\\n\\n\");\n", + "}\n", + "\n", + "// See https://js.langchain.com/v0.2/docs/tutorials/rag\n", + "const ragChain = RunnableSequence.from([\n", + " {\n", + " context: retriever.pipe(formatDocs),\n", + " question: new RunnablePassthrough(),\n", + " },\n", + " prompt,\n", + " llm,\n", + " new StringOutputParser(),\n", + "]);" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d47c37dd-5c11-416c-a3b6-bec413cd70e8", + "metadata": {}, + "outputs": [], + "source": [ + "await ragChain.invoke(query);" + ] + }, + { + "cell_type": "markdown", + "id": "3a5bb5ca-c3ae-4a58-be67-2cd18574b9a3", + "metadata": {}, + "source": [ + "## API reference\n", + "\n", + "For detailed documentation of all `AmazonKendraRetriever` features and configurations head to the [API reference](https://api.js.langchain.com/classes/langchain_aws.AmazonKendraRetriever.html)." + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "TypeScript", + "language": "typescript", + "name": "tslab" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "typescript", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.4" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/docs/core_docs/docs/integrations/retrievers/kendra-retriever.mdx b/docs/core_docs/docs/integrations/retrievers/kendra-retriever.mdx deleted file mode 100644 index 250a65300eae..000000000000 --- a/docs/core_docs/docs/integrations/retrievers/kendra-retriever.mdx +++ /dev/null @@ -1,29 +0,0 @@ ---- -hide_table_of_contents: true ---- - -# Amazon Kendra Retriever - -Amazon Kendra is an intelligent search service provided by Amazon Web Services (AWS). -It utilizes advanced natural language processing (NLP) and machine learning algorithms to enable powerful search capabilities across various data sources within an organization. -Kendra is designed to help users find the information they need quickly and accurately, improving productivity and decision-making. - -With Kendra, users can search across a wide range of content types, including documents, FAQs, knowledge bases, manuals, and websites. -It supports multiple languages and can understand complex queries, synonyms, and contextual meanings to provide highly relevant search results. - -## Setup - -import IntegrationInstallTooltip from "@mdx_components/integration_install_tooltip.mdx"; - - - -```bash npm2yarn -npm i @langchain/aws -``` - -## Usage - -import CodeBlock from "@theme/CodeBlock"; -import Example from "@examples/retrievers/kendra.ts"; - -{Example}