Tony20100/langchain_full huggingface dataset:
langchain_google_community.docai.DocAIParsingResults¶
class langchain_google_community.docai.DocAIParsingResults(source_path: str, parsed_path: str)[source]¶
A dataclass to store Document AI parsing results.
Attributes
source_path
parsed_path
Methods
__init__(source_path, parsed_path)
Parameters
source_path (str) – 
parsed_path (str) – 
__init__(source_path: str, parsed_path: str) → None¶
Parameters
source_path (str) – 
parsed_path (str) – 
Return type
None
langchain_google_community.bigquery_vector_search.BigQueryVectorSearch¶
class langchain_google_community.bigquery_vector_search.BigQueryVectorSearch(embedding: Embeddings, project_id: str, dataset_name: str, table_name: str, location: str = 'US', content_field: str = 'content', metadata_field: str = 'metadata', text_embedding_field: str = 'text_embedding', doc_id_field: str = 'doc_id', distance_strategy: DistanceStrategy = DistanceStrategy.EUCLIDEAN_DISTANCE, credentials: Optional[Any] = None)[source]¶
Google Cloud BigQuery vector store.
To use, you need the following packages installed:google-cloud-bigquery
Constructor for BigQueryVectorSearch.
Parameters
embedding (Embeddings) – Text Embedding model to use.
project_id (str) – GCP project.
dataset_name (str) – BigQuery dataset to store documents and embeddings.
table_name (str) – BigQuery table name.
location (str, optional) – BigQuery region. Defaults to
`US`(multi-region).
content_field (str) – Specifies the column to store the content.
Defaults to content.
metadata_field (str) – Specifies the column to store the metadata.
Defaults to metadata.
text_embedding_field (str) – Specifies the column to store
the embeddings vector.
Defaults to text_embedding.
doc_id_field (str) – Specifies the column to store the document id.
Defaults to doc_id.
distance_strategy (DistanceStrategy, optional) – Determines the strategy employed for calculating
the distance between vectors in the embedding space.
Defaults to EUCLIDEAN_DISTANCE.
Available options are:
- COSINE: Measures the similarity between two vectors of an inner
product space.
EUCLIDEAN_DISTANCE: Computes the Euclidean distance betweentwo vectors. This metric considers the geometric distance in
the vector space, and might be more suitable for embeddings
that rely on spatial relationships. This is the default behavior
credentials (Credentials, optional) – Custom Google Cloud credentials
to use. Defaults to None.
Attributes
embeddings
Access the query embedding object if available.
full_table_id
Methods
__init__(embedding, project_id, ...[, ...])
Constructor for BigQueryVectorSearch.
aadd_documents(documents, **kwargs)
Run more documents through the embeddings and add to the vectorstore.
aadd_texts(texts[, metadatas])
Run more texts through the embeddings and add to the vectorstore.
add_documents(documents, **kwargs)
Run more documents through the embeddings and add to the vectorstore.
add_texts(texts[, metadatas])
Run more texts through the embeddings and add to the vectorstore.
add_texts_with_embeddings(texts, embs[, ...])
Run more texts through the embeddings and add to the vectorstore.
adelete([ids])
Delete by vector ID or other criteria.
afrom_documents(documents, embedding, **kwargs)
Return VectorStore initialized from documents and embeddings.
afrom_texts(texts, embedding[, metadatas])
Return VectorStore initialized from texts and embeddings.
amax_marginal_relevance_search(query[, k, ...])
Return docs selected using the maximal marginal relevance.
amax_marginal_relevance_search_by_vector(...)
Return docs selected using the maximal marginal relevance.
as_retriever(**kwargs)
Return VectorStoreRetriever initialized from this VectorStore.
asearch(query, search_type, **kwargs)
Return docs most similar to query using specified search type.
asimilarity_search(query[, k])
Return docs most similar to query.
asimilarity_search(query[, k])
Return docs most similar to query.
asimilarity_search_by_vector(embedding[, k])
Return docs most similar to embedding vector.
asimilarity_search_with_relevance_scores(query)
Return docs and relevance scores in the range [0, 1].
asimilarity_search_with_score(*args, **kwargs)
Run similarity search with distance.
delete([ids])
Delete by vector ID or other criteria.
explore_job_stats(job_id)
Return the statistics for a single job execution.
from_documents(documents, embedding, **kwargs)
Return VectorStore initialized from documents and embeddings.
from_texts(texts, embedding[, metadatas])
Return VectorStore initialized from texts and embeddings.
get_documents([ids, filter])
Search documents by their ids or metadata values.
max_marginal_relevance_search(query[, k, ...])
Return docs selected using the maximal marginal relevance.
max_marginal_relevance_search_by_vector(...)
Return docs selected using the maximal marginal relevance.
search(query, search_type, **kwargs)
Return docs most similar to query using specified search type.
similarity_search(query[, k, filter, ...])
Run similarity search.
similarity_search_by_vector(embedding[, k, ...])
Return docs most similar to embedding vector.
similarity_search_with_relevance_scores(query)
Return docs and relevance scores in the range [0, 1].
similarity_search_with_score(query[, k, ...])
Run similarity search with score.
similarity_search_with_score_by_vector(embedding)
Return docs most similar to embedding vector.
similarity_search_with_score_by_vector(embedding)
Return docs most similar to embedding vector.
__init__(embedding: Embeddings, project_id: str, dataset_name: str, table_name: str, location: str = 'US', content_field: str = 'content', metadata_field: str = 'metadata', text_embedding_field: str = 'text_embedding', doc_id_field: str = 'doc_id', distance_strategy: DistanceStrategy = DistanceStrategy.EUCLIDEAN_DISTANCE, credentials: Optional[Any] = None)[source]¶
Constructor for BigQueryVectorSearch.
Parameters
embedding (Embeddings) – Text Embedding model to use.
project_id (str) – GCP project.
dataset_name (str) – BigQuery dataset to store documents and embeddings.
table_name (str) – BigQuery table name.
location (str, optional) – BigQuery region. Defaults to
`US`(multi-region).
content_field (str) – Specifies the column to store the content.
Defaults to content.
metadata_field (str) – Specifies the column to store the metadata.
Defaults to metadata.
text_embedding_field (str) – Specifies the column to store
the embeddings vector.
Defaults to text_embedding.
doc_id_field (str) – Specifies the column to store the document id.
Defaults to doc_id.
distance_strategy (DistanceStrategy, optional) – Determines the strategy employed for calculating
the distance between vectors in the embedding space.
Defaults to EUCLIDEAN_DISTANCE.
Available options are:
- COSINE: Measures the similarity between two vectors of an inner
product space.
EUCLIDEAN_DISTANCE: Computes the Euclidean distance betweentwo vectors. This metric considers the geometric distance in
the vector space, and might be more suitable for embeddings
that rely on spatial relationships. This is the default behavior
langchain_text_splitters.spacy.SpacyTextSplitter¶
class langchain_text_splitters.spacy.SpacyTextSplitter(separator: str = '\n\n', pipeline: str = 'en_core_web_sm', max_length: int = 1000000, **kwargs: Any)[source]¶
Splitting text using Spacy package.
Per default, Spacy’s en_core_web_sm model is used and
its default max_length is 1000000 (it is the length of maximum character
this model takes which can be increased for large files). For a faster, but
potentially less accurate splitting, you can use pipeline=’sentencizer’.
Initialize the spacy text splitter.
Methods
__init__([separator, pipeline, max_length])
Initialize the spacy text splitter.
atransform_documents(documents, **kwargs)
Asynchronously transform a list of documents.
create_documents(texts[, metadatas])
Create documents from a list of texts.
from_huggingface_tokenizer(tokenizer, **kwargs)
Text splitter that uses HuggingFace tokenizer to count length.
from_tiktoken_encoder([encoding_name, ...])
Text splitter that uses tiktoken encoder to count length.
split_documents(documents)
Split documents.
split_text(text)
Split incoming text and return chunks.
transform_documents(documents, **kwargs)
Transform sequence of documents by splitting them.
Parameters
separator (str) – 
pipeline (str) – 
max_length (int) – 
kwargs (Any) – 
__init__(separator: str = '\n\n', pipeline: str = 'en_core_web_sm', max_length: int = 1000000, **kwargs: Any) → None[source]¶
Initialize the spacy text splitter.
Parameters
separator (str) –
Initialize the spacy text splitter.
Parameters
separator (str) – 
pipeline (str) – 
max_length (int) – 
kwargs (Any) – 
Return type
None
async atransform_documents(documents: Sequence[Document], **kwargs: Any) → Sequence[Document]¶
Asynchronously transform a list of documents.
Parameters
documents (Sequence[Document]) – A sequence of Documents to be transformed.
kwargs (Any) – 
Returns
A list of transformed Documents.
Return type
Sequence[Document]
create_documents(texts: List[str], metadatas: Optional[List[dict]] = None) → List[Document]¶
Create documents from a list of texts.
Parameters
texts (List[str]) – 
metadatas (Optional[List[dict]]) – 
Return type
List[Document]
classmethod from_huggingface_tokenizer(tokenizer: Any, **kwargs: Any) → TextSplitter¶
Text splitter that uses HuggingFace tokenizer to count length.
Parameters
tokenizer (Any) – 
kwargs (Any) – 
Return type
TextSplitter
classmethod from_tiktoken_encoder(encoding_name: str = 'gpt2', model_name: Optional[str] = None, allowed_special: Union[Literal['all'], AbstractSet[str]] = {}, disallowed_special: Union[Literal['all'], Collection[str]] = 'all', **kwargs: Any) → TS¶
Text splitter that uses tiktoken encoder to count length.
Parameters
encoding_name (str) – 
model_name (Optional[str]) – 
allowed_special (Union[Literal['all'], ~typing.AbstractSet[str]]) – 
disallowed_special (Union[Literal['all'], ~typing.Collection[str]]) – 
kwargs (Any) – 
Return type
TS
kwargs (Any) – 
Return type
TS
split_documents(documents: Iterable[Document]) → List[Document]¶
Split documents.
Parameters
documents (Iterable[Document]) – 
Return type
List[Document]
split_text(text: str) → List[str][source]¶
Split incoming text and return chunks.
Parameters
text (str) – 
Return type
List[str]
transform_documents(documents: Sequence[Document], **kwargs: Any) → Sequence[Document]¶
Transform sequence of documents by splitting them.
Parameters
documents (Sequence[Document]) – 
kwargs (Any) – 
Return type
Sequence[Document]
Examples using SpacyTextSplitter¶
Atlas
How to split text by tokens 
spaCy
langchain_community.chains.graph_qa.gremlin.extract_gremlin¶
langchain_community.chains.graph_qa.gremlin.extract_gremlin(text: str) → str[source]¶
Extract Gremlin code from a text.
Parameters
text (str) – Text to extract Gremlin code from.
Returns
Gremlin code extracted from the text.
Return type
str
langchain.chains.api.base.APIChain¶
class langchain.chains.api.base.APIChain[source]¶
Bases: Chain
Chain that makes API calls and summarizes the responses to answer a question.
Security Note: This API chain uses the requests toolkitto make GET, POST, PATCH, PUT, and DELETE requests to an API.
Exercise care in who is allowed to use this chain. If exposing
to end users, consider that users will be able to make arbitrary
requests on behalf of the server hosting the code. For example,
users could ask the server to make a request to a private API
that is only accessible from the server.
Control access to who can submit issue requests using this toolkit and
what network access it has.
See https://python.langchain.com/docs/security for more information.
Create a new model by parsing and validating input data from keyword arguments.
Raises ValidationError if the input data cannot be parsed to form a valid model.
param api_answer_chain: LLMChain [Required]¶
param api_docs: str [Required]¶
param api_request_chain: LLMChain [Required]¶
param callback_manager: Optional[BaseCallbackManager] = None¶
[DEPRECATED] Use callbacks instead.
param callbacks: Callbacks = None¶
Optional list of callback handlers (or callback manager). Defaults to None.
Callback handlers are called throughout the lifecycle of a call to a chain,
starting with on_chain_start, ending with on_chain_end or on_chain_error.
Each custom chain can optionally call additional callback methods, see Callback docs
for full details.
param limit_to_domains: Optional[Sequence[str]] = None¶
Use to limit the domains that can be accessed by the API chain.
For example, to limit to just the domain https://www.example.com, setlimit_to_domains=[“https://www.example.com”].
# -> {"_type": "foo", "verbose": False, ...}
classmethod from_llm_and_api_docs(llm: BaseLanguageModel, api_docs: str, headers: Optional[dict] = None, api_url_prompt: BasePromptTemplate = PromptTemplate(input_variables=['api_docs', 'question'], template='You are given the below API Documentation:\n{api_docs}\nUsing this documentation, generate the full API url to call for answering the user question.\nYou should build the API url in order to get a response that is as short as possible, while still getting the necessary information to answer the question. Pay attention to deliberately exclude any unnecessary pieces of data in the API call.\n\nQuestion:{question}\nAPI url:'), api_response_prompt: BasePromptTemplate = PromptTemplate(input_variables=['api_docs', 'api_response', 'api_url', 'question'], template='You are given the below API Documentation:\n{api_docs}\nUsing this documentation, generate the full API url to call for answering the user question.\nYou should build the API url in order to get a response that is as short as possible, while still getting the necessary information to answer the question. Pay attention to deliberately exclude any unnecessary pieces of data in the API call.\n\nQuestion:{question}\nAPI url: {api_url}\n\nHere is the response from the API:\n\n{api_response}\n\nSummarize this response to answer the original question.\n\nSummary:'), limit_to_domains: Optional[Sequence[str]] = (), **kwargs: Any) → APIChain[source]¶
Load chain from just an LLM and the api docs.
Parameters
llm (BaseLanguageModel) – 
api_docs (str) – 
headers (Optional[dict]) – 
api_url_prompt (BasePromptTemplate) – 
api_response_prompt (BasePromptTemplate) –
api_response_prompt (BasePromptTemplate) – 
limit_to_domains (Optional[Sequence[str]]) – 
kwargs (Any) – 
Return type
APIChain
classmethod from_orm(obj: Any) → Model¶
Parameters
obj (Any) – 
Return type
Model
get_graph(config: Optional[RunnableConfig] = None) → Graph¶
Return a graph representation of this runnable.
Parameters
config (Optional[RunnableConfig]) – 
Return type
Graph
get_input_schema(config: Optional[RunnableConfig] = None) → Type[BaseModel]¶
Get a pydantic model that can be used to validate input to the runnable.
Runnables that leverage the configurable_fields and configurable_alternatives
methods will have a dynamic input schema that depends on which
configuration the runnable is invoked with.
This method allows to get an input schema for a specific configuration.
Parameters
config (Optional[RunnableConfig]) – A config to use when generating the schema.
Returns
A pydantic model that can be used to validate input.
Return type
Type[BaseModel]
classmethod get_lc_namespace() → List[str]¶
Get the namespace of the langchain object.
For example, if the class is langchain.llms.openai.OpenAI, then the
namespace is [“langchain”, “llms”, “openai”]
Return type
List[str]
get_name(suffix: Optional[str] = None, *, name: Optional[str] = None) → str¶
Get the name of the runnable.
Parameters
suffix (Optional[str]) – 
name (Optional[str]) – 
Return type
str
get_output_schema(config: Optional[RunnableConfig] = None) → Type[BaseModel]¶
Get a pydantic model that can be used to validate output to the runnable.
langchain.chains.conversation.base.ConversationChain¶
class langchain.chains.conversation.base.ConversationChain[source]¶
Bases: LLMChain
Chain to have a conversation and load context from memory.
Example
from langchain.chains import ConversationChain
from langchain_community.llms import OpenAI
conversation = ConversationChain(llm=OpenAI())
Create a new model by parsing and validating input data from keyword arguments.
Raises ValidationError if the input data cannot be parsed to form a valid model.
param callback_manager: Optional[BaseCallbackManager] = None¶
[DEPRECATED] Use callbacks instead.
param callbacks: Callbacks = None¶
Optional list of callback handlers (or callback manager). Defaults to None.
Callback handlers are called throughout the lifecycle of a call to a chain,
starting with on_chain_start, ending with on_chain_end or on_chain_error.
Each custom chain can optionally call additional callback methods, see Callback docs
for full details.
param llm: Union[Runnable[LanguageModelInput, str], Runnable[LanguageModelInput, BaseMessage]] [Required]¶
Language model to call.
param llm_kwargs: dict [Optional]¶
param memory: BaseMemory [Optional]¶
Default memory store.
param metadata: Optional[Dict[str, Any]] = None¶
Optional metadata associated with the chain. Defaults to None.
This metadata will be associated with each call to this chain,
and passed as arguments to the handlers defined in callbacks.
You can use these to eg identify a specific instance of a chain with its use case.
param output_parser: BaseLLMOutputParser [Optional]¶
Output parser to use.
Defaults to one that takes the most likely string but does not change it
otherwise.
Defaults to one that takes the most likely string but does not change it
otherwise.
param prompt: BasePromptTemplate = PromptTemplate(input_variables=['history', 'input'], template='The following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific details from its context. If the AI does not know the answer to a question, it truthfully says it does not know.\n\nCurrent conversation:\n{history}\nHuman: {input}\nAI:')¶
Default conversation prompt to use.
param return_final_only: bool = True¶
Whether to return only the final parsed result. Defaults to True.
If false, will return a bunch of extra information about the generation.
param tags: Optional[List[str]] = None¶
Optional list of tags associated with the chain. Defaults to None.
These tags will be associated with each call to this chain,
and passed as arguments to the handlers defined in callbacks.
You can use these to eg identify a specific instance of a chain with its use case.
param verbose: bool [Optional]¶
Whether or not run in verbose mode. In verbose mode, some intermediate logs
will be printed to the console. Defaults to the global verbose value,
accessible via langchain.globals.get_verbose().
__call__(inputs: Union[Dict[str, Any], Any], return_only_outputs: bool = False, callbacks: Optional[Union[List[BaseCallbackHandler], BaseCallbackManager]] = None, *, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, run_name: Optional[str] = None, include_run_info: bool = False) → Dict[str, Any]¶
[Deprecated] Execute the chain.
Parameters
inputs (Union[Dict[str, Any], Any]) – Dictionary of inputs, or single input if chain expects
This method allows to get an output schema for a specific configuration.
Parameters
config (Optional[RunnableConfig]) – A config to use when generating the schema.
Returns
A pydantic model that can be used to validate output.
Return type
Type[BaseModel]
get_prompts(config: Optional[RunnableConfig] = None) → List[BasePromptTemplate]¶
Parameters
config (Optional[RunnableConfig]) – 
Return type
List[BasePromptTemplate]
invoke(input: Dict[str, Any], config: Optional[RunnableConfig] = None, **kwargs: Any) → Dict[str, Any]¶
Transform a single input into an output. Override to implement.
Parameters
input (Dict[str, Any]) – The input to the runnable.
config (Optional[RunnableConfig]) – A config to use when invoking the runnable.
The config supports standard keys like ‘tags’, ‘metadata’ for tracing
purposes, ‘max_concurrency’ for controlling how much work to do
in parallel, and other keys. Please refer to the RunnableConfig
for more details.
kwargs (Any) – 
Returns
The output of the runnable.
Return type
Dict[str, Any]
classmethod is_lc_serializable() → bool[source]¶
Is this class serializable?
Return type
bool
json(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, by_alias: bool = False, skip_defaults: Optional[bool] = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, encoder: Optional[Callable[[Any], Any]] = None, models_as_dict: bool = True, **dumps_kwargs: Any) → unicode¶
raise ValueError("x is 1")
    else:
         pass
runnable = RunnableLambda(_lambda)
try:
    runnable.with_retry(
        stop_after_attempt=2,
        retry_if_exception_type=(ValueError,),
    ).invoke(1)
except ValueError:
    pass
assert (count == 2)
Parameters
retry_if_exception_type (Tuple[Type[BaseException], ...]) – A tuple of exception types to retry on
wait_exponential_jitter (bool) – Whether to add jitter to the wait time
between retries
stop_after_attempt (int) – The maximum number of attempts to make before giving up
Returns
A new Runnable that retries the original runnable on exceptions.
Return type
Runnable[Input, Output]
with_types(*, input_type: Optional[Type[Input]] = None, output_type: Optional[Type[Output]] = None) → Runnable[Input, Output]¶
Bind input and output types to a Runnable, returning a new Runnable.
Parameters
input_type (Optional[Type[Input]]) – 
output_type (Optional[Type[Output]]) – 
Return type
Runnable[Input, Output]
property InputType: Type[Input]¶
The type of input this runnable accepts specified as a type annotation.
property OutputType: Type[Output]¶
The type of output this runnable produces specified as a type annotation.
property config_specs: List[ConfigurableFieldSpec]¶
List configurable fields for this runnable.
property input_keys: List[str]¶
Use this since so some prompt vars come from history.
property input_schema: Type[BaseModel]¶
The type of input this runnable accepts specified as a pydantic model.
property lc_attributes: Dict¶
List of attribute names that should be included in the serialized kwargs.
These attributes must be accepted by the constructor.
These attributes must be accepted by the constructor.
property lc_secrets: Dict[str, str]¶
A map of constructor argument names to secret ids.
For example,{“openai_api_key”: “OPENAI_API_KEY”}
name: Optional[str] = None¶
The name of the runnable. Used for debugging and tracing.
property output_schema: Type[BaseModel]¶
The type of output this runnable produces specified as a pydantic model.
Examples using ConversationChain¶
Bedrock
NVIDIA NIMs
langchain_community.chains.pebblo_retrieval.models.Runtime¶
class langchain_community.chains.pebblo_retrieval.models.Runtime[source]¶
Bases: BaseModel
OS, language details
Create a new model by parsing and validating input data from keyword arguments.
Raises ValidationError if the input data cannot be parsed to form a valid model.
param host: str [Required]¶
param ip: Optional[str] = ''¶
param language: str [Required]¶
param language_version: str [Required]¶
param os: str [Required]¶
param os_version: str [Required]¶
param path: str [Required]¶
param platform: str [Required]¶
param runtime: Optional[str] = ''¶
param type: Optional[str] = ''¶
classmethod construct(_fields_set: Optional[SetStr] = None, **values: Any) → Model¶
Creates a new model setting __dict__ and __fields_set__ from trusted or pre-validated data.
Default values are respected, but no other validation is performed.
Behaves as if Config.extra = ‘allow’ was set since it adds all passed values
Parameters
_fields_set (Optional[SetStr]) – 
values (Any) – 
Return type
Model
copy(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, update: Optional[DictStrAny] = None, deep: bool = False) → Model¶
Duplicate a model, optionally choose which fields to include, exclude and change.
Parameters
include (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) – fields to include in new model