id
stringlengths
6
6
text
stringlengths
20
17.2k
title
stringclasses
1 value
144596
import { BaseRetriever, type BaseRetrieverInput, type BaseRetrieverInterface, } from "@langchain/core/retrievers"; import type { DocumentInterface } from "@langchain/core/documents"; import { CallbackManagerForRetrieverRun } from "@langchain/core/callbacks/manager"; import { BaseDocumentCompressor } from "./docum...
144612
import type { EmbeddingsInterface } from "@langchain/core/embeddings"; import type { DocumentInterface } from "@langchain/core/documents"; import { cosineSimilarity } from "@langchain/core/utils/math"; import { BaseDocumentCompressor } from "./index.js"; /** * Interface for the parameters of the `EmbeddingsFilter` cl...
144692
import type { BaseLanguageModelInterface } from "@langchain/core/language_models/base"; import { BaseMessage, SystemMessage, getBufferString, } from "@langchain/core/messages"; import { BasePromptTemplate } from "@langchain/core/prompts"; import { InputValues, MemoryVariables, OutputValues, } from "@langcha...
144696
import { getBufferString } from "@langchain/core/messages"; import { InputValues, MemoryVariables, OutputValues, } from "@langchain/core/memory"; import { BaseConversationSummaryMemory, BaseConversationSummaryMemoryInput, } from "./summary.js"; /** * Interface for the input parameters of the * Conversation...
144700
import { InputValues, MemoryVariables } from "@langchain/core/memory"; import { getBufferString } from "@langchain/core/messages"; import { BaseChatMemory, BaseChatMemoryInput } from "./chat_memory.js"; /** * Interface for the input parameters of the `BufferMemory` class. */ export interface BufferMemoryInput extend...
144706
import { test, expect } from "@jest/globals"; import { ChatOpenAI, OpenAIChat } from "@langchain/openai"; import { SystemMessage } from "@langchain/core/messages"; import { ConversationSummaryMemory } from "../summary.js"; test("Test summary memory", async () => { const memory = new ConversationSummaryMemory({ l...
144709
import { test, expect } from "@jest/globals"; import { OpenAI, ChatOpenAI } from "@langchain/openai"; import { SystemMessage } from "@langchain/core/messages"; import { ConversationSummaryBufferMemory } from "../summary_buffer.js"; test("Test summary buffer memory", async () => { const memory = new ConversationSumma...
144727
import { Document } from "@langchain/core/documents"; /** * Given a list of documents, this util formats their contents * into a string, separated by newlines. * * @param documents * @returns A string of the documents page content, separated by newlines. */ export const formatDocumentsAsString = (documents: Docu...
144787
import { describe, expect, test } from "@jest/globals"; import { Document } from "@langchain/core/documents"; import { CharacterTextSplitter, LatexTextSplitter, MarkdownTextSplitter, RecursiveCharacterTextSplitter, TokenTextSplitter, } from "../text_splitter.js"; function textLineGenerator(char: string, leng...
144788
describe("RecursiveCharacter text splitter", () => { test("One unique chunk", async () => { const splitter = new RecursiveCharacterTextSplitter({ chunkSize: 100, chunkOverlap: 0, }); const content = textLineGenerator("A", 70); const docs = await splitter.createDocuments([content]); c...
144789
litter.", async () => { const text = `\\begin{document} \\title{🦜️🔗 LangChain} ⚡ Building applications with LLMs through composability ⚡ \\section{Quick Install} \\begin{verbatim} Hopefully this code block isn't split yarn add langchain \\end{verbatim} As an open source project in a rapidly developing field, we ...
144794
export { mapStoredMessagesToChatMessages, mapChatMessagesToStoredMessages, } from "@langchain/core/messages";
144807
import type { BaseLanguageModelInterface } from "@langchain/core/language_models/base"; import type { StructuredToolInterface, ToolInterface, } from "@langchain/core/tools"; import { CallbackManager } from "@langchain/core/callbacks/manager"; import { BufferMemory } from "../memory/buffer_memory.js"; import { ChatA...
144825
import { OutputParserException } from "@langchain/core/output_parsers"; import { OutputParserArgs } from "../agent.js"; import { AgentActionOutputParser } from "../types.js"; import { FORMAT_INSTRUCTIONS } from "./prompt.js"; export const FINAL_ANSWER_ACTION = "Final Answer:"; /** * A class that extends `AgentAction...
144828
export type CreateStructuredChatAgentParams = { /** LLM to use as the agent. */ llm: BaseLanguageModelInterface; /** Tools this agent has access to. */ tools: (StructuredToolInterface | ToolDefinition)[]; /** * The prompt to use. Must have input keys for * `tools`, `tool_names`, and `agent_scratchpad`. ...
144829
import type { BaseLanguageModelInterface } from "@langchain/core/language_models/base"; import { Callbacks } from "@langchain/core/callbacks/manager"; import { AgentAction, AgentFinish } from "@langchain/core/agents"; import { OutputParserException } from "@langchain/core/output_parsers"; import { renderTemplate } from...
144833
/* eslint-disable no-process-env */ import { expect, test } from "@jest/globals"; import { OpenAI, OpenAIEmbeddings, ChatOpenAI } from "@langchain/openai"; import { Tool } from "@langchain/core/tools"; import { RunnableSequence } from "@langchain/core/runnables"; import { OutputParserException } from "@langchain/core/o...
144843
import { zodToJsonSchema } from "zod-to-json-schema"; import fs from "fs"; import { z } from "zod"; import { AgentAction, AgentFinish, AgentStep } from "@langchain/core/agents"; import { AIMessage } from "@langchain/core/messages"; import { OpenAIEmbeddings, ChatOpenAI } from "@langchain/openai"; import { convertToOpen...
144858
import type { BaseLanguageModelInterface } from "@langchain/core/language_models/base"; import { type ToolInterface, BaseToolkit } from "@langchain/core/tools"; import { renderTemplate } from "@langchain/core/prompts"; import { InfoSqlTool, ListTablesSqlTool, QueryCheckerTool, QuerySqlTool, } from "../../../too...
144862
import { AgentAction, AgentFinish } from "@langchain/core/agents"; import { OutputParserException } from "@langchain/core/output_parsers"; import { AgentActionOutputParser } from "../types.js"; /** * @example * ```typescript * const prompt = ChatPromptTemplate.fromMessages([ * HumanMessagePromptTemplate.fromTemp...
144872
import type { ToolInterface } from "@langchain/core/tools"; import { BasePromptTemplate } from "@langchain/core/prompts"; import type { BaseLanguageModel, BaseLanguageModelInterface, } from "@langchain/core/language_models/base"; import { RunnablePassthrough } from "@langchain/core/runnables"; import { AgentStep } ...
144942
export { BaseMessagePromptTemplate, type MessagesPlaceholderFields as MessagePlaceholderFields, MessagesPlaceholder, type MessageStringPromptTemplateFields, BaseMessageStringPromptTemplate, BaseChatPromptTemplate, type ChatMessagePromptTemplateFields, ChatMessagePromptTemplate, HumanMessagePromptTempl...
144981
import * as url from "node:url"; import * as path from "node:path"; import { test, expect } from "@jest/globals"; import { Document } from "@langchain/core/documents"; import { JSONLoader } from "../fs/json.js"; test("Test JSON loader", async () => { const filePath = path.resolve( path.dirname(url.fileURLToPath(...
144984
import * as url from "node:url"; import * as path from "node:path"; import * as fs from "node:fs/promises"; import { test, expect } from "@jest/globals"; import { Document } from "@langchain/core/documents"; import { JSONLoader } from "../fs/json.js"; test("Test JSON loader from blob", async () => { const filePath =...
144991
import type { readFile as ReadFileT } from "node:fs/promises"; import { Document } from "@langchain/core/documents"; import { getEnv } from "@langchain/core/utils/env"; import { BaseDocumentLoader } from "../base.js"; /** * A class that extends the `BaseDocumentLoader` class. It represents a * document loader that l...
144996
import type { BaseLanguageModelInterface } from "@langchain/core/language_models/base"; import type { VectorStoreInterface } from "@langchain/core/vectorstores"; import { ChainValues } from "@langchain/core/utils/types"; import { CallbackManagerForChainRun } from "@langchain/core/callbacks/manager"; import { PromptTemp...
145008
import type { BaseLanguageModelInterface } from "@langchain/core/language_models/base"; import type { BaseRetrieverInterface } from "@langchain/core/retrievers"; import { ChainValues } from "@langchain/core/utils/types"; import { CallbackManagerForChainRun } from "@langchain/core/callbacks/manager"; import { BaseChain,...
145009
import { PromptTemplate } from "@langchain/core/prompts"; import { LLMChain, LLMChainInput } from "./llm_chain.js"; import { BufferMemory } from "../memory/buffer_memory.js"; import { Optional } from "../types/type-utils.js"; export const DEFAULT_TEMPLATE = `The following is a friendly conversation between a human and...
145010
import { BaseLanguageModel, BaseLanguageModelInterface, BaseLanguageModelInput, } from "@langchain/core/language_models/base"; import type { ChainValues } from "@langchain/core/utils/types"; import type { Generation } from "@langchain/core/outputs"; import type { BaseMessage } from "@langchain/core/messages"; imp...
145012
export class ConversationalRetrievalQAChain extends BaseChain implements ConversationalRetrievalQAChainInput { static lc_name() { return "ConversationalRetrievalQAChain"; } inputKey = "question"; chatHistoryKey = "chat_history"; get inputKeys() { return [this.inputKey, this.chatHistoryKey]; }...
145018
/* eslint-disable spaced-comment */ import { ChatPromptTemplate, SystemMessagePromptTemplate, HumanMessagePromptTemplate, PromptTemplate, } from "@langchain/core/prompts"; import { ConditionalPromptSelector, isChatModel, } from "@langchain/core/example_selectors"; export const DEFAULT_QA_PROMPT = /*#__PURE...
145019
import { test } from "@jest/globals"; import { OpenAI } from "@langchain/openai"; import { Document } from "@langchain/core/documents"; import { loadQAMapReduceChain, loadQARefineChain, loadQAStuffChain, } from "../load.js"; test("Test loadQAStuffChain", async () => { const model = new OpenAI({ modelName: "gpt...
145048
import { test } from "@jest/globals"; import { OpenAI, ChatOpenAI } from "@langchain/openai"; import { ChatPromptTemplate, HumanMessagePromptTemplate, PromptTemplate, } from "@langchain/core/prompts"; import { LLMChain } from "../llm_chain.js"; import { BufferMemory } from "../../memory/buffer_memory.js"; test("...
145049
import { test, expect } from "@jest/globals"; import { Document } from "@langchain/core/documents"; import { BaseLLM } from "@langchain/core/language_models/llms"; import { LLMResult } from "@langchain/core/outputs"; import { loadQAMapReduceChain } from "../question_answering/load.js"; import { loadSummarizationChain }...
145051
import { test } from "@jest/globals"; import { OpenAI } from "@langchain/openai"; import { ConversationChain } from "../conversation.js"; test("Test ConversationChain", async () => { const model = new OpenAI({ modelName: "gpt-3.5-turbo-instruct" }); const chain = new ConversationChain({ llm: model }); // @eslint...
145053
import { expect, test } from "@jest/globals"; import { OpenAI, OpenAIEmbeddings, ChatOpenAI } from "@langchain/openai"; import { PromptTemplate } from "@langchain/core/prompts"; import { ConversationalRetrievalQAChain } from "../conversational_retrieval_chain.js"; import { MemoryVectorStore } from "../../vectorstores/m...
145054
test("Test ConversationalRetrievalQAChain from LLM with a chat model without memory", async () => { const model = new ChatOpenAI({ modelName: "gpt-3.5-turbo", temperature: 0, }); const vectorStore = await MemoryVectorStore.fromTexts( [ "Mitochondria are the powerhouse of the cell", "Foo is...
145072
/* eslint-disable spaced-comment */ import { PromptTemplate } from "@langchain/core/prompts"; export const API_URL_RAW_PROMPT_TEMPLATE = `You are given the below API Documentation: {api_docs} Using this documentation, generate the full API url to call for answering the user question. You should build the API url in or...
145086
/* eslint-disable spaced-comment */ import { BasePromptTemplate, PromptTemplate } from "@langchain/core/prompts"; export const DEFAULT_SQL_DATABASE_PROMPT = /*#__PURE__*/ new PromptTemplate({ template: `Given an input question, first create a syntactically correct {dialect} query to run, then look at the results of ...
145123
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction // import all entrypoints to test, do not do this in your own app import "../../entrypoints.js"; // Import a few things we'll use to test the exports import { LLMChain } from "langchain/chains"; import { ChatOpenAI } from "@langchain/openai...
145141
import { ChatOpenAI } from "@langchain/openai"; import { createOpenAIToolsAgent, AgentExecutor } from "langchain/agents"; import { pull } from "langchain/hub"; import type { ChatPromptTemplate } from "@langchain/core/prompts"; const model = new ChatOpenAI({ openAIApiKey: "sk-XXXX", }); const prompt = await pull<Cha...
145209
# Conceptual guide This section contains introductions to key parts of LangChain. ## Architecture LangChain as a framework consists of several pieces. The below diagram shows how they relate. import ThemedImage from "@theme/ThemedImage"; import useBaseUrl from "@docusaurus/useBaseUrl"; <ThemedImage alt="Diagram ...
145210
:::caution Pure text-in/text-out LLMs tend to be older or lower-level. Many popular models are best used as [chat completion models](/docs/concepts/#chat-models), even for non-chat use cases. You are probably looking for [the section above instead](/docs/concepts/#chat-models). ::: Language models that takes a string...
145211
**Supports Streaming**: Whether the output parser supports streaming. **Input Type**: Expected input type. Most output parsers work on both strings and messages, but some (like OpenAI Functions) need a message with specific arguments. **Output Type**: The output type of the object returned by the parser. **Descripti...
145212
LangChain includes a [`BaseStore`](https://api.js.langchain.com/classes/langchain_core.stores.BaseStore.html) interface, which allows for storage of arbitrary data. However, LangChain components that require KV-storage accept a more specific `BaseStore<string, Uint8Array>` instance that stores binary data (referred to ...
145213
| Event | Event Trigger | Associated Method | | ---------------- | ------------------------------------------- | ---------------------- | | Chat model start | When a chat model starts | `handleChatModelStart` | | LLM start | When a llm starts ...
145214
- You need to explicitly initialize and manage some aggregator or other stream to collect results. - The execution order isn't explicitly guaranteed, and you could theoretically have a callback run after the `.invoke()` method finishes. - Providers would often make you pass an additional parameter to stream outputs ins...
145215
Some models, such as [Mistral](/docs/integrations/chat/mistral/), [OpenAI](/docs/integrations/chat/openai/), [Together AI](/docs/integrations/chat/togetherai/) and [Ollama](/docs/integrations/chat/ollama/), support a feature called **JSON mode**, usually enabled via config. When enabled, JSON mode will constrain the m...
145216
These requirements are model-specific and should be checked for the model you are using. If your model requires ToolMessages after tool calls and/or AIMessages after ToolMessages and your examples only include expected tool calls and not the actual tool outputs, you can try adding dummy ToolMessages / AIMessages to the...
145233
:::tip We're unifying model params across all packages. We now suggest using `model` instead of `modelName`, and `apiKey` for API keys. :::
145238
--- sidebar_position: 1 sidebar_label: v0.2 --- # LangChain v0.2 LangChain v0.2 was released in May 2024. This release includes a number of breaking changes and deprecations. This document contains a guide on upgrading to 0.2.x, as well as a list of deprecations and breaking changes. :::note Reference - [Migrating ...
145242
{ "cells": [ { "cell_type": "markdown", "id": "ce8457ed-c0b1-4a74-abbd-9d3d2211270f", "metadata": {}, "source": [ "# Migrating off ConversationTokenBufferMemory\n", "\n", "Follow this guide if you're trying to migrate off one of the old memory classes listed below:\n", "\n", "\n", ...
145249
# INVALID_PROMPT_INPUT A [prompt template](/docs/concepts#prompt-templates) received missing or invalid input variables. One unexpected way this can occur is if you add a JSON object directly into a prompt template: ```ts import { PromptTemplate } from "@langchain/core/prompts"; import { ChatOpenAI } from "@langchai...
145251
# MESSAGE_COERCION_FAILURE Several modules in LangChain take [`MessageLike`](https://api.js.langchain.com/types/_langchain_core.messages.BaseMessageLike.html) objects in place of formal [`BaseMessage`](/docs/concepts#message-types) classes. These include OpenAI style message objects (`{ role: "user", content: "Hello w...
145258
# OUTPUT_PARSING_FAILURE An [output parser](/docs/concepts#output-parsers) was unable to handle model output as expected. To illustrate this, let's say you have an output parser that expects a chat model to output JSON surrounded by a markdown code tag (triple backticks). Here would be an example of good input: ````...
145259
# MODEL_AUTHENTICATION Your model provider is denying you access to their service. ## Troubleshooting The following may help resolve this error: - Confirm that your API key or other credentials are correct. - If you are relying on an environment variable to authenticate, confirm that the variable name is correct an...
145262
# Few Shot Prompt Templates Few shot prompting is a prompting technique which provides the Large Language Model (LLM) with a list of examples, and then asks the LLM to generate some text following the lead of the examples provided. An example of this is the following: Say you want your LLM to respond in a specific f...
145263
```typescript const examplePrompt = PromptTemplate.fromTemplate("An example about {x}"); const exampleSelector = await LengthBasedExampleSelector.fromExamples( [{ x: "foo" }, { x: "bar" }], { examplePrompt, maxLength: 200 } ); const prompt = new FewShotPromptTemplate({ prefix: "{foo}{bar}", exampleSelector, e...
145278
{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# How to do retrieval\n", "\n", ":::info Prerequisites\n", "\n", "This guide assumes familiarity with the following:\n", "\n", "- [Chatbots](/docs/tutorials/chatbot)\n", "- [Retrieval-augmented generation](/...
145286
{ "cells": [ { "cell_type": "raw", "id": "8165bd4c", "metadata": { "vscode": { "languageId": "raw" } }, "source": [ "---\n", "keywords: [memory]\n", "---" ] }, { "cell_type": "markdown", "id": "f47033eb", "metadata": {}, "source": [ "# How to add message...
145296
" messageLog: [\n", " AIMessageChunk {\n", " \"id\": \"chatcmpl-A7eziUrDmLSSMoiOskhrfbsHqx4Sd\",\n", " \"content\": \"\",\n", " \"additional_kwargs\": {\n", " \"tool_calls\": [\n", " {\n", " ...
145297
" messageLog: [\n", " AIMessageChunk {\n", " \"id\": \"chatcmpl-A7f0NdSRSUJsBP6ENTpiQD4LzpBAH\",\n", " \"content\": \"\",\n", " \"additional_kwargs\": {\n", " \"tool_calls\": [\n", " {\n", " \"index\"...
145302
"data": { "text/plain": [ "{ input: \u001b[32m\"hi!\"\u001b[39m, output: \u001b[32m\"Hello! How can I assist you today?\"\u001b[39m }" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "await agentExecutor.invoke({ input: \"...
145306
{ "cells": [ { "cell_type": "markdown", "id": "ea37db49-d389-4291-be73-885d06c1fb7e", "metadata": {}, "source": [ "# How to do extraction without using function calling\n", "\n", ":::info Prerequisites\n", "\n", "This guide assumes familiarity with t...
145308
{ "cells": [ { "cell_type": "markdown", "id": "c3ee8d00", "metadata": {}, "source": [ "# How to split by character\n", "\n", ":::info Prerequisites\n", "\n", "This guide assumes familiarity with the following concepts:\n", "\n", "- [Text splitters](/docs/concepts#text-splitter...
145312
```bash [chain/start] [1:chain:AgentExecutor] Entering Chain run with input: { "input": "Who directed the 2023 film Oppenheimer and what is their age? What is their age in days (assume 365 days per year)?" } [chain/start] [1:chain:AgentExecutor > 2:chain:ToolCallingAgent] Entering Chain run with input: { "input": "...
145390
"execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import { ConsoleCallbackHandler } from \"@langchain/core/tracers/console\";\n", "import { ChatPromptTemplate } from \"@langchain/core/prompts\";\n", "import { ChatAnthropic } from \"@langchain/anthrop...
145397
--- sidebar_position: 2 --- # How to embed text data :::info Head to [Integrations](/docs/integrations/text_embedding) for documentation on built-in integrations with text embedding providers. ::: :::info Prerequisites This guide assumes familiarity with the following concepts: - [Embeddings](/docs/concepts/#embed...
145402
{ "cells": [ { "cell_type": "raw", "metadata": {}, "source": [ "---\n", "sidebar_position: 1\n", "---" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# How to add memory to chatbots\n", "\n", "A key feature of chatbots is their ability to use content of ...
145405
"We can use this same pattern in other ways too. For example, we could use an additional LLM call to generate a summary of the conversation before calling our app. Let's recreate our chat history:" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [], "source": [ "c...
145420
# How to write a custom retriever class :::info Prerequisites This guide assumes familiarity with the following concepts: - [Retrievers](/docs/concepts/#retrievers) ::: To create your own retriever, you need to extend the [`BaseRetriever`](https://api.js.langchain.com/classes/langchain_core.retrievers.BaseRetrieve...
145421
{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# How to return sources\n", "\n", ":::info Prerequisites\n", "\n", "This guide assumes familiarity with the following:\n", "\n", "- [Retrieval-augmented generation](/docs/...
145422
" pageContent: \u001b[32m'Task decomposition can be done (1) by LLM with simple prompting like \"Steps for XYZ.\\\\n1.\", \"What are'\u001b[39m... 887 more characters,\n", " metadata: {\n", " source: \u001b[32m\"https://lilianweng.github.io/posts/2023-06-23-agent/\"\u001b[39...
145428
" documents, new OpenAIEmbeddings(),\n", ");\n", "\n", "const retriever = vectorstore.asRetriever({\n", " k: 1,\n", " searchType: \"similarity\",\n", "});" ] }, { "cell_type": "markdown", "id": "9ba737ac-43a2-4a6f-b855-5bd0305017f1", "metadata": {}, "source": [ "We next...
145433
{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# How to pass callbacks in at runtime\n", "\n", ":::info Prerequisites\n", "\n", "This guide assumes familiarity with the following concepts:\n", "\n", "- [Callbacks](/docs/concepts/#callbacks)\n", "\n", ...
145442
# How to partially format prompt templates :::info Prerequisites This guide assumes familiarity with the following concepts: - [Prompt templates](/docs/concepts/#prompt-templates) ::: Like partially binding arguments to a function, it can make sense to "partial" a prompt template - e.g. pass in a subset of the req...
145443
# How to generate multiple embeddings per document :::info Prerequisites This guide assumes familiarity with the following concepts: - [Retrievers](/docs/concepts/#retrievers) - [Text splitters](/docs/concepts/#text-splitters) - [Retrieval-augmented generation (RAG)](/docs/tutorials/rag) ::: Embedding different re...
145446
# How to init any model in one line import CodeBlock from "@theme/CodeBlock"; Many LLM applications let end users specify what model provider and model they want the application to be powered by. This requires writing some logic to initialize different ChatModels based on some user configuration. The `initChatModel()...
145455
{ "cells": [ { "cell_type": "raw", "id": "04171ad7", "metadata": { "vscode": { "languageId": "raw" } }, "source": [ "---\n", "keywords: [custom tool, custom tools]\n", "---" ] }, { "cell_type": "markdown", "id": "5436020b", "metadata": {}, "source": [ "#...
145469
{ "cells": [ { "cell_type": "raw", "id": "beba2e0e", "metadata": {}, "source": [ "---\n", "sidebar_position: 2\n", "---" ] }, { "cell_type": "markdown", "id": "bb0735c0", "metadata": {}, "source": [ "# How to use few shot examples in chat models\n", "\n", "This ...
145475
# How to invoke runnables in parallel :::info Prerequisites This guide assumes familiarity with the following concepts: - [LangChain Expression Language (LCEL)](/docs/concepts/#langchain-expression-language) - [Chaining runnables](/docs/how_to/sequence/) ::: The [`RunnableParallel`](https://api.js.langchain.com/cl...
145476
{ "cells": [ { "cell_type": "markdown", "id": "72b1b316", "metadata": {}, "source": [ "# How to parse JSON output\n", "\n", "While some model providers support [built-in ways to return structured output](/docs/how_to/structured_output), not all do. We can use an output parser to help users to...
145477
--- keywords: [similaritySearchWithScore] --- # How to create and query vector stores :::info Head to [Integrations](/docs/integrations/vectorstores) for documentation on built-in integrations with vectorstore providers. ::: :::info Prerequisites This guide assumes familiarity with the following concepts: - [Vecto...
145479
"data": { "text/plain": [ "{\n", " setup: \u001b[32m\"Why don't cats play poker in the jungle?\"\u001b[39m,\n", " punchline: \u001b[32m\"Too many cheetahs!\"\u001b[39m\n", "}" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ...
145480
"Where people is an array of objects, each with a name and height_in_meters field.\n", "`\n", "\n", "// Set up a parser\n", "const parser = new JsonOutputParser<People>();\n", "\n", "// Prompt\n", "const prompt = await ChatPromptTemplate.fromMessages(\n", " [\n", " [\n", ...
145482
# How to load JSON data > [JSON (JavaScript Object Notation)](https://en.wikipedia.org/wiki/JSON) is an open standard file format and data interchange format that uses human-readable text to store and transmit data objects consisting of attribute–value pairs and arrays (or other serializable values). > [JSON Lines](h...
145483
--- sidebar_position: 5 --- # How to track token usage :::info Prerequisites This guide assumes familiarity with the following concepts: - [Chat models](/docs/concepts/#chat-models) ::: This notebook goes over how to track your token usage for specific calls. ## Using `AIMessage.usage_metadata` A number of mode...
145487
# How to do retrieval with contextual compression :::info Prerequisites This guide assumes familiarity with the following concepts: - [Retrievers](/docs/concepts/#retrievers) - [Retrieval-augmented generation (RAG)](/docs/tutorials/rag) ::: One challenge with retrieval is that usually you don't know the specific q...
145492
# How to load data from a directory This covers how to load all documents in a directory. The second argument is a map of file extensions to loader factories. Each file will be passed to the matching loader, and the resulting documents will be concatenated together. Example folder: ```text src/document_loaders/exam...
145500
{ "cells": [ { "cell_type": "raw", "id": "d35de667-0352-4bfb-a890-cebe7f676fe7", "metadata": {}, "source": [ "---\n", "sidebar_position: 5\n", "keywords: [RunnablePassthrough, LCEL]\n", "---" ] }, { "cell_type": "markdown", "id": "b022ab74-794d-4c54-ad47-ff9549ddb9d2", "me...
145502
{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# How to force tool calling behavior\n", "\n", "```{=mdx}\n", "\n", ":::info Prerequisites\n", "\n", "This guide assumes familiarity with the following concepts:\n", "- [Chat models](/docs/concepts/#chat-mod...
145504
{ "cells": [ { "cell_type": "raw", "id": "94c3ad61", "metadata": {}, "source": [ "---\n", "sidebar_position: 3\n", "---" ] }, { "cell_type": "markdown", "id": "b91e03f1", "metadata": {}, "source": [ "# How to use few shot examples\n", "\n", "In this guide, we'll...
145512
{ "cells": [ { "cell_type": "raw", "metadata": {}, "source": [ "---\n", "keywords: [RunnablePassthrough, assign, LCEL]\n", "---" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# How to add values to a chain's state\n", "\n", ":::info Prerequisites\n", ...
145513
# How use a vector store to retrieve data :::info Prerequisites This guide assumes familiarity with the following concepts: - [Vector stores](/docs/concepts/#vectorstores) - [Retrievers](/docs/concepts/#retrievers) - [Text splitters](/docs/concepts#text-splitters) - [Chaining runnables](/docs/how_to/sequence/) ::: ...
145522
"Message chunks are additive by design – one can simply add them up using the `.concat()` method to get the state of the response so far!" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "AI...
145537
{ "cells": [ { "cell_type": "raw", "id": "0e77c293-4049-43be-ba49-ff9daeefeee7", "metadata": {}, "source": [ "---\n", "sidebar_position: 4\n", "---" ] }, { "cell_type": "markdown", "id": "14d3fd06", "metadata": {}, "source": [ ...
145539
{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# How to add chat history\n", "\n", "\n", ":::note\n", "\n", "This tutorial previously built a chatbot using [RunnableWithMessageHistory](https://api.js.langchain.com/classes/_lan...
145573
# How to load PDF files > [Portable Document Format (PDF)](https://en.wikipedia.org/wiki/PDF), standardized as ISO 32000, is a file format developed by Adobe in 1992 to present documents, including text formatting and images, in a manner independent of application software, hardware, and operating systems. This cover...
145578
--- sidebar_position: 1 --- # How to stream responses from an LLM All [`LLM`s](https://api.js.langchain.com/classes/langchain_core.language_models_llms.BaseLLM.html) implement the [Runnable interface](https://api.js.langchain.com/classes/langchain_core.runnables.Runnable.html), which comes with **default** implementa...
145586
{ "cells": [ { "cell_type": "raw", "metadata": { "vscode": { "languageId": "raw" } }, "source": [ "---\n", "keywords: [recursivecharactertextsplitter]\n", "---" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# How to recursively split text by cha...