-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds retriever integration docs template
- Loading branch information
1 parent
d441c7d
commit 4100736
Showing
1 changed file
with
256 additions
and
0 deletions.
There are no files selected for viewing
256 changes: 256 additions & 0 deletions
256
libs/langchain-scripts/src/cli/docs/templates/retrievers.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,256 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "raw", | ||
"id": "afaf8039", | ||
"metadata": {}, | ||
"source": [ | ||
"---\n", | ||
"sidebar_label: __ModuleName__\n", | ||
"---" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "e49f1e0d", | ||
"metadata": {}, | ||
"source": [ | ||
"# __ModuleName__Retriever\n", | ||
"\n", | ||
"## Overview\n", | ||
"\n", | ||
"- TODO: Make sure API reference link is correct.\n", | ||
"\n", | ||
"This will help you getting started with the __ModuleName__ [retriever](/docs/concepts/#retrievers). For detailed documentation of all __ModuleName__Retriever features and configurations head to the [API reference](https://api.js.langchain.com/classes/__package_name__.__ModuleName__Retriever.html).\n", | ||
"\n", | ||
"### Integration details\n", | ||
"\n", | ||
"TODO: Select one of the tables below, as appropriate.\n", | ||
"\n", | ||
"1: Bring-your-own data (i.e., index and search a custom corpus of documents):\n", | ||
"\n", | ||
"| Retriever | Self-host | Cloud offering | Package | [Py support](https://python.langchain.com/docs/integrations/chat/__package_name_short_snake_case__) |\n", | ||
"| :--- | :--- | :---: | :---: |\n", | ||
"[__ModuleName__Retriever](https://api.js.langchain.com/classes/__package_name__.__ModuleName__Retriever.html) | ❌ | ❌ | __package_name__ |\n", | ||
"\n", | ||
"2: External index (e.g., constructed from Internet data or similar):\n", | ||
"\n", | ||
"| Retriever | Source | Package |\n", | ||
"| :--- | :--- | :---: |\n", | ||
"[__ModuleName__Retriever](https://api.js.langchain.com/classes/__package_name__.__ModuleName__Retriever.html) | Source description | __package_name__ |\n", | ||
"\n", | ||
"## Setup\n", | ||
"\n", | ||
"- TODO: Update with relevant info." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "72ee0c4b-9764-423a-9dbf-95129e185210", | ||
"metadata": {}, | ||
"source": [ | ||
"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:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "a15d341e-3e26-4ca3-830b-5aab30ed66de", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"// process.env.LANGSMITH_API_KEY = \"<YOUR API KEY HERE>\";\n", | ||
"// process.env.LANGSMITH_TRACING = \"true\";" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "0730d6a1-c893-4840-9817-5e5251676d5d", | ||
"metadata": {}, | ||
"source": [ | ||
"### Installation\n", | ||
"\n", | ||
"This retriever lives in the `__package_name__` package:\n", | ||
"\n", | ||
"```{=mdx}\n", | ||
"import IntegrationInstallTooltip from \"@mdx_components/integration_install_tooltip.mdx\";\n", | ||
"import Npm2Yarn from \"@theme/Npm2Yarn\";\n", | ||
"\n", | ||
"<IntegrationInstallTooltip></IntegrationInstallTooltip>\n", | ||
"\n", | ||
"<Npm2Yarn>\n", | ||
" __package_name_pretty__\n", | ||
"</Npm2Yarn>\n", | ||
"```" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "a38cde65-254d-4219-a441-068766c0d4b5", | ||
"metadata": {}, | ||
"source": [ | ||
"## Instantiation\n", | ||
"\n", | ||
"Now we can instantiate our retriever:\n", | ||
"\n", | ||
"- TODO: Update model instantiation with relevant params." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "70cc8e65-2a02-408a-bbc6-8ef649057d82", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import { __ModuleName__Retriever } from \"__module_name__\";\n", | ||
"\n", | ||
"const retriever = new __ModuleName__Retriever(\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, __ModuleName__Retriever 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", | ||
"<ChatModelTabs customVarName=\"llm\" />\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(formatDocumentsAsString),\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(\"...\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "d1ee55bc-ffc8-4cfa-801c-993953a08cfd", | ||
"metadata": {}, | ||
"source": [ | ||
"## TODO: Any functionality or considerations specific to this retriever\n", | ||
"\n", | ||
"Fill in or delete if not relevant." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "3a5bb5ca-c3ae-4a58-be67-2cd18574b9a3", | ||
"metadata": {}, | ||
"source": [ | ||
"## API reference\n", | ||
"\n", | ||
"For detailed documentation of all __ModuleName__Retriever features and configurations head to the [API reference](https://api.js.langchain.com/classes/__package_name__.__ModuleName__Retriever.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 | ||
} |