Tony20100/langchain_full huggingface dataset:
Compare the output of two models (or two outputs of the same model).
evaluation.schema.StringEvaluator()
Grade, tag, or otherwise evaluate predictions relative to their inputs and/or reference labels.
evaluation.scoring.eval_chain.LabeledScoreStringEvalChain
A chain for scoring the output of a model on a scale of 1-10.
evaluation.scoring.eval_chain.ScoreStringEvalChain
A chain for scoring on a scale of 1-10 the output of a model.
evaluation.scoring.eval_chain.ScoreStringResultOutputParser
A parser for the output of the ScoreStringEvalChain.
evaluation.string_distance.base.PairwiseStringDistanceEvalChain
Compute string edit distances between two predictions.
evaluation.string_distance.base.StringDistance(value)
Distance metric to use.
evaluation.string_distance.base.StringDistanceEvalChain
Compute string distances between the prediction and the reference.
Functions¶
evaluation.comparison.eval_chain.resolve_pairwise_criteria(...)
Resolve the criteria for the pairwise evaluator.
evaluation.criteria.eval_chain.resolve_criteria(...)
Resolve the criteria to evaluate.
evaluation.loading.load_dataset(uri)
Load a dataset from the LangChainDatasets on HuggingFace.
evaluation.loading.load_evaluator(evaluator, *)
Load the requested evaluation chain specified by a string.
evaluation.loading.load_evaluators(evaluators, *)
Load evaluators specified by a list of evaluator types.
evaluation.scoring.eval_chain.resolve_criteria(...)
Resolve the criteria for the pairwise evaluator.
langchain.hub¶
Interface with the LangChain Hub.
Functions¶
hub.pull(owner_repo_commit, *[, api_url, ...])
Pull an object from the hub and returns it as a LangChain object.
hub.push(repo_full_name, object, *[, ...])
Push an object to the hub and returns the URL it can be viewed at in a browser.
langchain.indexes¶
langchain.indexes¶
Index is used to avoid writing duplicated content
into the vectostore and to avoid over-writing content if it’s unchanged.
Indexes also :
Create knowledge graphs from data.
Support indexing workflows from LangChain data loaders to vectorstores.
Importantly, Index keeps on working even if the content being written is derived
via a set of transformations from some source content (e.g., indexing children
documents that were derived from parent documents by chunking.)
Classes¶
indexes.vectorstore.VectorStoreIndexWrapper
Wrapper around a vectorstore for easy access.
indexes.vectorstore.VectorstoreIndexCreator
Logic for creating indexes.
langchain.memory¶
Memory maintains Chain state, incorporating context from past runs.
Class hierarchy for Memory:
BaseMemory --> BaseChatMemory --> <name>Memory  # Examples: ZepMemory, MotorheadMemory
Main helpers:
BaseChatMessageHistory
Chat Message History stores the chat message history in different stores.
Class hierarchy for ChatMessageHistory:
BaseChatMessageHistory --> <name>ChatMessageHistory  # Example: ZepChatMessageHistory
Main helpers:
AIMessage, BaseMessage, HumanMessage
Classes¶
memory.buffer.ConversationBufferMemory
Buffer for storing conversation memory.
memory.buffer.ConversationStringBufferMemory
Buffer for storing conversation memory.
memory.buffer_window.ConversationBufferWindowMemory
Buffer for storing conversation memory inside a limited size window.
memory.chat_memory.BaseChatMemory
Abstract base class for chat memory.
memory.combined.CombinedMemory
Combining multiple memories' data together.
memory.entity.BaseEntityStore
Abstract base class for Entity store.
memory.entity.ConversationEntityMemory
Entity extractor & summarizer memory.
memory.entity.InMemoryEntityStore
In-memory Entity store.
memory.entity.RedisEntityStore
Redis-backed Entity store.
memory.entity.SQLiteEntityStore
SQLite-backed Entity store
Redis-backed Entity store.
memory.entity.SQLiteEntityStore
SQLite-backed Entity store
memory.entity.UpstashRedisEntityStore
Upstash Redis backed Entity store.
memory.readonly.ReadOnlySharedMemory
Memory wrapper that is read-only and cannot be changed.
memory.simple.SimpleMemory
Simple memory for storing context or other information that shouldn't ever change between prompts.
memory.summary.ConversationSummaryMemory
Conversation summarizer to chat memory.
memory.summary.SummarizerMixin
Mixin for summarizer.
memory.summary_buffer.ConversationSummaryBufferMemory
Buffer with summarizer for storing conversation memory.
memory.token_buffer.ConversationTokenBufferMemory
Conversation chat memory with token limit.
memory.vectorstore.VectorStoreRetrieverMemory
VectorStoreRetriever-backed memory.
Functions¶
memory.utils.get_prompt_input_key(inputs, ...)
Get the prompt input key.
langchain.model_laboratory¶
Experiment with different models.
Classes¶
model_laboratory.ModelLaboratory(chains[, names])
Experiment with different models.
langchain.output_parsers¶
OutputParser classes parse the output of an LLM call.
Class hierarchy:
BaseLLMOutputParser --> BaseOutputParser --> <name>OutputParser  # ListOutputParser, PydanticOutputParser
Main helpers:
Serializable, Generation, PromptValue
Classes¶
output_parsers.boolean.BooleanOutputParser
Parse the output of an LLM call to a boolean.
output_parsers.combining.CombiningOutputParser
Combine multiple output parsers into one.
output_parsers.datetime.DatetimeOutputParser
Parse the output of an LLM call to a datetime.
output_parsers.enum.EnumOutputParser
Parse an output that is one of a set of values.
output_parsers.fix.OutputFixingParser
Wrap a parser and try to fix parsing errors.
output_parsers.pandas_dataframe.PandasDataFrameOutputParser
output_parsers.pandas_dataframe.PandasDataFrameOutputParser
Parse an output using Pandas DataFrame format.
output_parsers.regex.RegexParser
Parse the output of an LLM call using a regex.
output_parsers.regex_dict.RegexDictParser
Parse the output of an LLM call into a Dictionary using a regex.
output_parsers.retry.RetryOutputParser
Wrap a parser and try to fix parsing errors.
output_parsers.retry.RetryWithErrorOutputParser
Wrap a parser and try to fix parsing errors.
output_parsers.structured.ResponseSchema
Schema for a response from a structured output parser.
output_parsers.structured.StructuredOutputParser
Parse the output of an LLM call to a structured output.
output_parsers.yaml.YamlOutputParser
Parse YAML output using a pydantic model.
Functions¶
output_parsers.loading.load_output_parser(config)
Load an output parser.
langchain.retrievers¶
Retriever class returns Documents given a text query.
It is more general than a vector store. A retriever does not need to be able to
store documents, only to return (or retrieve) it. Vector stores can be used as
the backbone of a retriever, but there are other types of retrievers as well.
Class hierarchy:
BaseRetriever --> <name>Retriever  # Examples: ArxivRetriever, MergerRetriever
Main helpers:
Document, Serializable, Callbacks,
CallbackManagerForRetrieverRun, AsyncCallbackManagerForRetrieverRun
Classes¶
retrievers.contextual_compression.ContextualCompressionRetriever
Retriever that wraps a base retriever and compresses the results.
retrievers.document_compressors.base.DocumentCompressorPipeline
Document compressor that uses a pipeline of Transformers.
retrievers.document_compressors.chain_extract.LLMChainExtractor
retrievers.document_compressors.chain_extract.LLMChainExtractor
Document compressor that uses an LLM chain to extract the relevant parts of documents.
retrievers.document_compressors.chain_extract.NoOutputParser
Parse outputs that could return a null string of some sort.
retrievers.document_compressors.chain_filter.LLMChainFilter
Filter that drops documents that aren't relevant to the query.
retrievers.document_compressors.cohere_rerank.CohereRerank
[Deprecated] Document compressor that uses Cohere Rerank API.
retrievers.document_compressors.cross_encoder.BaseCrossEncoder()
Interface for cross encoder models.
retrievers.document_compressors.cross_encoder_rerank.CrossEncoderReranker
Document compressor that uses CrossEncoder for reranking.
retrievers.document_compressors.embeddings_filter.EmbeddingsFilter
Document compressor that uses embeddings to drop documents unrelated to the query.
retrievers.ensemble.EnsembleRetriever
Retriever that ensembles the multiple retrievers.
retrievers.merger_retriever.MergerRetriever
Retriever that merges the results of multiple retrievers.
retrievers.multi_query.LineListOutputParser
Output parser for a list of lines.
retrievers.multi_query.MultiQueryRetriever
Given a query, use an LLM to write a set of queries.
retrievers.multi_vector.MultiVectorRetriever
Retrieve from a set of multiple embeddings for the same document.
retrievers.multi_vector.SearchType(value)
Enumerator of the types of search to perform.
retrievers.parent_document_retriever.ParentDocumentRetriever
Retrieve small chunks then retrieve their parent documents.
retrievers.re_phraser.RePhraseQueryRetriever
Given a query, use an LLM to re-phrase it.
retrievers.self_query.base.SelfQueryRetriever
retrievers.self_query.base.SelfQueryRetriever
Retriever that uses a vector store and an LLM to generate the vector store queries.
retrievers.time_weighted_retriever.TimeWeightedVectorStoreRetriever
Retriever that combines embedding similarity with recency in retrieving values.
Functions¶
retrievers.document_compressors.chain_extract.default_get_input(...)
Return the compression chain input.
retrievers.document_compressors.chain_filter.default_get_input(...)
Return the compression chain input.
retrievers.ensemble.unique_by_key(iterable, key)
Yield unique elements of an iterable based on a key function.
langchain.runnables¶
LangChain Runnable and the LangChain Expression Language (LCEL).
The LangChain Expression Language (LCEL) offers a declarative method to build
production-grade programs that harness the power of LLMs.
Programs created using LCEL and LangChain Runnables inherently support
synchronous, asynchronous, batch, and streaming operations.
Support for async allows servers hosting the LCEL based programs
to scale better for higher concurrent loads.
Batch operations allow for processing multiple inputs in parallel.
Streaming of intermediate outputs, as they’re being generated, allows for
creating more responsive UX.
This module contains non-core Runnable classes.
Classes¶
runnables.hub.HubRunnable
An instance of a runnable stored in the LangChain Hub.
runnables.openai_functions.OpenAIFunction
A function description for ChatOpenAI
runnables.openai_functions.OpenAIFunctionsRouter
A runnable that routes to the selected function.
langchain.smith¶
LangSmith utilities.
This module provides utilities for connecting to LangSmith. For more information on LangSmith, see the LangSmith documentation.
Evaluation
Evaluation
LangSmith helps you evaluate Chains and other language model application components using a number of LangChain evaluators.
An example of this is shown below, assuming you’ve created a LangSmith dataset called <my_dataset_name>:
from langsmith import Client
from langchain_community.chat_models import ChatOpenAI
from langchain.chains import LLMChain
from langchain.smith import RunEvalConfig, run_on_dataset
# Chains may have memory. Passing in a constructor function lets the
# evaluation framework avoid cross-contamination between runs.
def construct_chain():
    llm = ChatOpenAI(temperature=0)
    chain = LLMChain.from_string(
        llm,
        "What's the answer to {your_input_key}"
    )
    return chain
# Load off-the-shelf evaluators via config or the EvaluatorType (string or enum)
evaluation_config = RunEvalConfig(
    evaluators=[
        "qa",  # "Correctness" against a reference answer
        "embedding_distance",
        RunEvalConfig.Criteria("helpfulness"),
        RunEvalConfig.Criteria({
            "fifth-grader-score": "Do you have to be smarter than a fifth grader to answer this question?"
        }),
    ]
)
client = Client()
run_on_dataset(
    client,
    "<my_dataset_name>",
    construct_chain,
    evaluation=evaluation_config,
)
You can also create custom evaluators by subclassing the
StringEvaluator
or LangSmith’s RunEvaluator classes.
from typing import Optional
from langchain.evaluation import StringEvaluator
class MyStringEvaluator(StringEvaluator):
    @property
    def requires_input(self) -> bool:
        return False
    @property
    def requires_reference(self) -> bool:
        return True
    @property
def requires_reference(self) -> bool:
        return True
    @property
    def evaluation_name(self) -> str:
        return "exact_match"
    def _evaluate_strings(self, prediction, reference=None, input=None, **kwargs) -> dict:
        return {"score": prediction == reference}
evaluation_config = RunEvalConfig(
    custom_evaluators = [MyStringEvaluator()],
)
run_on_dataset(
    client,
    "<my_dataset_name>",
    construct_chain,
    evaluation=evaluation_config,
)
Primary Functions
arun_on_dataset: Asynchronous function to evaluate a chain, agent, or other LangChain component over a dataset.
run_on_dataset: Function to evaluate a chain, agent, or other LangChain component over a dataset.
RunEvalConfig: Class representing the configuration for running evaluation. You can select evaluators by EvaluatorType or config, or you can pass in custom_evaluators
Classes¶
smith.evaluation.config.EvalConfig
Configuration for a given run evaluator.
smith.evaluation.config.RunEvalConfig
Configuration for a run evaluation.
smith.evaluation.config.SingleKeyEvalConfig
Configuration for a run evaluator that only requires a single key.
smith.evaluation.progress.ProgressBarCallback(total)
A simple progress bar for the console.
smith.evaluation.runner_utils.ChatModelInput
Input for a chat model.
smith.evaluation.runner_utils.EvalError(...)
Your architecture raised an error.
smith.evaluation.runner_utils.InputFormatError
Raised when the input format is invalid.
smith.evaluation.runner_utils.TestResult
A dictionary of the results of a single test run.
smith.evaluation.string_run_evaluator.ChainStringRunMapper
Extract items to evaluate from the run object from a chain.
smith.evaluation.string_run_evaluator.LLMStringRunMapper
Extract items to evaluate from the run object.
Extract items to evaluate from the run object.
smith.evaluation.string_run_evaluator.StringExampleMapper
Map an example, or row in the dataset, to the inputs of an evaluation.
smith.evaluation.string_run_evaluator.StringRunEvaluatorChain
Evaluate Run and optional examples.
smith.evaluation.string_run_evaluator.StringRunMapper
Extract items to evaluate from the run object.
smith.evaluation.string_run_evaluator.ToolStringRunMapper
Map an input to the tool.
Functions¶
smith.evaluation.name_generation.random_name()
Generate a random name.
smith.evaluation.runner_utils.arun_on_dataset(...)
Run the Chain or language model on a dataset and store traces to the specified project name.
smith.evaluation.runner_utils.run_on_dataset(...)
Run the Chain or language model on a dataset and store traces to the specified project name.
langchain.storage¶
Implementations of key-value stores and storage helpers.
Module provides implementations of various key-value stores that conform
to a simple key-value interface.
The primary goal of these storages is to support implementation of caching.
Classes¶
storage.encoder_backed.EncoderBackedStore(...)
Wraps a store with key and value encoders/decoders.
storage.file_system.LocalFileStore(root_path, *)
BaseStore interface that works on the local file system.
langchain_google_vertexai 1.0.5¶
langchain_google_vertexai.callbacks¶
Classes¶
callbacks.VertexAICallbackHandler()
Callback Handler that tracks VertexAI info.
langchain_google_vertexai.chains¶
Functions¶
chains.create_structured_runnable(function, ...)
Create a runnable sequence that uses OpenAI functions.
chains.get_output_parser(functions)
Get the appropriate function output parser given the user functions.
langchain_google_vertexai.chat_models¶
Wrapper around Google VertexAI chat-based models.
Classes¶
chat_models.ChatVertexAI
Vertex AI Chat large language models API.
langchain_google_vertexai.embeddings¶
Classes¶
embeddings.GoogleEmbeddingModelType(value)
An enumeration.
embeddings.GoogleEmbeddingModelVersion(value)
An enumeration.
embeddings.VertexAIEmbeddings
Google Cloud VertexAI embedding models.
langchain_google_vertexai.evaluators¶
Classes¶
evaluators.evaluation.VertexPairWiseStringEvaluator(...)
Evaluate the perplexity of a predicted string.
evaluators.evaluation.VertexStringEvaluator(...)
Evaluate the perplexity of a predicted string.
langchain_google_vertexai.functions_utils¶
Classes¶
functions_utils.PydanticFunctionsOutputParser
Parse an output as a pydantic object.
langchain_google_vertexai.gemma¶
Classes¶
gemma.GemmaChatLocalHF
Create a new model by parsing and validating input data from keyword arguments.
gemma.GemmaChatLocalKaggle
Needed for mypy typing to recognize model_name as a valid arg.
gemma.GemmaChatVertexAIModelGarden
Needed for mypy typing to recognize model_name as a valid arg.
gemma.GemmaLocalHF
Local gemma model loaded from HuggingFace.
gemma.GemmaLocalKaggle
Local gemma chat model loaded from Kaggle.
gemma.GemmaLocalKaggle
Local gemma chat model loaded from Kaggle.
gemma.GemmaVertexAIModelGarden
Create a new model by parsing and validating input data from keyword arguments.
Functions¶
gemma.gemma_messages_to_prompt(history)
Converts a list of messages to a chat prompt for Gemma.
langchain_google_vertexai.llms¶
Classes¶
llms.VertexAI
Google Vertex AI large language models.
langchain_google_vertexai.model_garden¶
Classes¶
model_garden.ChatAnthropicVertex
Create a new model by parsing and validating input data from keyword arguments.
model_garden.VertexAIModelGarden
Large language models served from Vertex AI Model Garden.
langchain_google_vertexai.vectorstores¶
Classes¶
vectorstores.document_storage.DataStoreDocumentStorage(...)
Stores documents in Google Cloud DataStore.
vectorstores.document_storage.DocumentStorage()
Abstract interface of a key, text storage for retrieving documents.
vectorstores.document_storage.GCSDocumentStorage(bucket)
Stores documents in Google Cloud Storage.
vectorstores.vectorstores.VectorSearchVectorStore(...)
VertexAI VectorStore that handles the search and indexing using Vector Search and stores the documents in Google Cloud Storage.
vectorstores.vectorstores.VectorSearchVectorStoreDatastore(...)
VectorSearch with DatasTore document storage.
vectorstores.vectorstores.VectorSearchVectorStoreGCS(...)
Alias of VectorSearchVectorStore for consistency with the rest of vector stores with different document storage backends.
langchain_google_vertexai.vision_models¶
Classes¶
vision_models.VertexAIImageCaptioning
Implementation of the Image Captioning model as an LLM.
vision_models.VertexAIImageCaptioningChat
Implementation of the Image Captioning model as a chat.
vision_models.VertexAIImageEditorChat
Given an image and a prompt, edits the image.
vision_models.VertexAIImageGeneratorChat
langchain_qdrant 0.1.0¶
langchain_qdrant.vectorstores¶
Classes¶
vectorstores.Qdrant(client, collection_name)
Qdrant vector store.
vectorstores.QdrantException
Qdrant related exceptions.
Functions¶
vectorstores.sync_call_fallback(method)
Decorator to call the synchronous method of the class if the async method is not implemented.
langchain_mistralai 0.1.8¶
langchain_mistralai.chat_models¶
Classes¶
chat_models.ChatMistralAI
A chat model that uses the MistralAI API.
Functions¶
chat_models.acompletion_with_retry(llm[, ...])
Use tenacity to retry the async completion call.
langchain_mistralai.embeddings¶
Classes¶
embeddings.DummyTokenizer()
Dummy tokenizer for when tokenizer cannot be accessed (e.g., via Huggingface)
embeddings.MistralAIEmbeddings
MistralAI embedding models.
langchain_upstage 0.1.6¶
langchain_upstage.chat_models¶
Classes¶
chat_models.ChatUpstage
ChatUpstage chat model.
langchain_upstage.embeddings¶
Classes¶
embeddings.UpstageEmbeddings
UpstageEmbeddings embedding model.
langchain_upstage.layout_analysis¶
Classes¶
layout_analysis.UpstageLayoutAnalysisLoader(...)
Upstage Layout Analysis.
Functions¶
layout_analysis.get_from_param_or_env(key[, ...])
Get a value from a param or an environment variable.
layout_analysis.validate_api_key(api_key)
Validates the provided API key.
layout_analysis.validate_file_path(file_path)
Validates if a file exists at the given file path.
langchain_upstage.layout_analysis_parsers¶
Classes¶
layout_analysis_parsers.UpstageLayoutAnalysisParser([...])
Upstage Layout Analysis Parser.
Functions¶
layout_analysis_parsers.get_from_param_or_env(key)
Get a value from a param or an environment variable.
layout_analysis_parsers.parse_output(data, ...)
Parse the output data based on the specified output type.
layout_analysis_parsers.validate_api_key(api_key)
Validates the provided API key.
layout_analysis_parsers.validate_file_path(...)
Validates if a file exists at the given file path.
langchain_upstage.tools¶
Classes¶
tools.groundedness_check.GroundednessCheck
[Deprecated]
tools.groundedness_check.UpstageGroundednessCheck
Tool that checks the groundedness of a context and an assistant message.
tools.groundedness_check.UpstageGroundednessCheckInput
Input for the Groundedness Check tool.
langchain_nvidia_ai_endpoints 0.1.1¶
langchain_nvidia_ai_endpoints.callbacks¶
Callback Handler that prints to std out.
Classes¶
callbacks.UsageCallbackHandler()
Callback Handler that tracks OpenAI info.
Functions¶
callbacks.get_token_cost_for_model(...[, ...])
Get the cost in USD for a given model and number of tokens.
callbacks.get_usage_callback([price_map, ...])
Get the OpenAI callback handler in a context manager.
callbacks.standardize_model_name(model_name)
Standardize the model name to a format that can be used in the OpenAI API.
langchain_nvidia_ai_endpoints.chat_models¶
Chat Model Components Derived from ChatModel/NVIDIA
Classes¶
chat_models.ChatNVIDIA
NVIDIA chat model.
langchain_nvidia_ai_endpoints.embeddings¶
Embeddings Components Derived from NVEModel/Embeddings
Classes¶
embeddings.NVIDIAEmbeddings
Client to NVIDIA embeddings models.
langchain_nvidia_ai_endpoints.reranking¶
Classes¶
reranking.NVIDIARerank
LangChain Document Compressor that uses the NVIDIA NeMo Retriever Reranking API.
reranking.Ranking
Create a new model by parsing and validating input data from keyword arguments.
langchain_nvidia_ai_endpoints.tools¶
OpenAI chat wrapper.
Classes¶
tools.ServerToolsMixin()
langchain_community 0.2.4¶
langchain_community.adapters¶
Adapters are used to adapt LangChain models to other APIs.
LangChain integrates with many model providers.
While LangChain has its own message and model APIs,
LangChain has also made it as easy as
possible to explore other models by exposing an adapter to adapt LangChain
models to the other APIs, as to the OpenAI API.
Classes¶
adapters.openai.Chat()
Chat.
adapters.openai.ChatCompletion()
Chat completion.
adapters.openai.ChatCompletionChunk
Chat completion chunk.
adapters.openai.ChatCompletions
Chat completions.
adapters.openai.Choice
Choice.
adapters.openai.ChoiceChunk
Choice chunk.
adapters.openai.Completions()
Completions.
adapters.openai.IndexableBaseModel
Allows a BaseModel to return its fields by string variable indexing.
Functions¶
adapters.openai.aenumerate(iterable[, start])
Async version of enumerate function.
adapters.openai.convert_dict_to_message(_dict)
Convert a dictionary to a LangChain message.
adapters.openai.convert_message_to_dict(message)
Convert a LangChain message to a dictionary.
adapters.openai.convert_messages_for_finetuning(...)
Convert messages to a list of lists of dictionaries for fine-tuning.
adapters.openai.convert_openai_messages(messages)
Convert dictionaries representing OpenAI messages to LangChain format.
langchain_community.agent_toolkits¶
Toolkits are sets of tools that can be used to interact with
various services and APIs.
Classes¶
agent_toolkits.ainetwork.toolkit.AINetworkToolkit
Toolkit for interacting with AINetwork Blockchain.
agent_toolkits.amadeus.toolkit.AmadeusToolkit
Toolkit for interacting with Amadeus which offers APIs for travel.