Tony20100/langchain_full huggingface dataset:
memory.
outputs (Dict[str, str]) – Dictionary of initial chain outputs.
return_only_outputs (bool) – Whether to only return the chain outputs. If False,
inputs are also added to the final outputs.
Returns
A dict of the final chain outputs.
Return type
Dict[str, str]
run(*args: Any, callbacks: Optional[Union[List[BaseCallbackHandler], BaseCallbackManager]] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, **kwargs: Any) → Any¶
[Deprecated] Convenience method for executing chain.
The main difference between this method and Chain.__call__ is that this
method expects inputs to be passed directly in as positional arguments or
keyword arguments, whereas Chain.__call__ expects a single input dictionary
with all the inputs
Parameters
*args (Any) – If the chain expects a single input, it can be passed in as the
sole positional argument.
callbacks (Optional[Union[List[BaseCallbackHandler], BaseCallbackManager]]) – Callbacks to use for this chain run. These will be called in
addition to callbacks passed to the chain during construction, but only
these runtime callbacks will propagate to calls to other objects.
tags (Optional[List[str]]) – List of string tags to pass to all callbacks. These will be passed in
addition to tags passed to the chain during construction, but only
these runtime tags will propagate to calls to other objects.
**kwargs (Any) – If the chain expects multiple inputs, they can be passed in
directly as keyword arguments.
metadata (Optional[Dict[str, Any]]) – 
**kwargs – 
Returns
The chain output.
Return type
Any
Example
# Suppose we have a single-input chain that takes a 'question' string:
Example
# Suppose we have a single-input chain that takes a 'question' string:
chain.run("What's the temperature in Boise, Idaho?")
# -> "The temperature in Boise is..."
# Suppose we have a multi-input chain that takes a 'question' string
# and 'context' string:
question = "What's the temperature in Boise, Idaho?"
context = "Weather report for Boise, Idaho on 07/03/23..."
chain.run(question=question, context=context)
# -> "The temperature in Boise is..."
Notes
Deprecated since version langchain==0.1.0: Use invoke instead.
save(file_path: Union[Path, str]) → None¶
Save the chain.
Expects Chain._chain_type property to be implemented and for memory to benull.
Parameters
file_path (Union[Path, str]) – Path to file to save the chain to.
Return type
None
Example
chain.save(file_path="path/chain.yaml")
classmethod schema(by_alias: bool = True, ref_template: unicode = '#/definitions/{model}') → DictStrAny¶
Parameters
by_alias (bool) – 
ref_template (unicode) – 
Return type
DictStrAny
classmethod schema_json(*, by_alias: bool = True, ref_template: unicode = '#/definitions/{model}', **dumps_kwargs: Any) → unicode¶
Parameters
by_alias (bool) – 
ref_template (unicode) – 
dumps_kwargs (Any) – 
Return type
unicode
stream(input: Input, config: Optional[RunnableConfig] = None, **kwargs: Optional[Any]) → Iterator[Output]¶
Default implementation of stream, which calls invoke.
Subclasses should override this method if they support streaming output.
Parameters
input (Input) –
Parameters
input (Input) – 
config (Optional[RunnableConfig]) – 
kwargs (Optional[Any]) – 
Return type
Iterator[Output]
to_json() → Union[SerializedConstructor, SerializedNotImplemented]¶
Serialize the runnable to JSON.
Return type
Union[SerializedConstructor, SerializedNotImplemented]
to_json_not_implemented() → SerializedNotImplemented¶
Return type
SerializedNotImplemented
transform(input: Iterator[Input], config: Optional[RunnableConfig] = None, **kwargs: Optional[Any]) → Iterator[Output]¶
Default implementation of transform, which buffers input and then calls stream.
Subclasses should override this method if they can start producing output while
input is still being generated.
Parameters
input (Iterator[Input]) – 
config (Optional[RunnableConfig]) – 
kwargs (Optional[Any]) – 
Return type
Iterator[Output]
classmethod update_forward_refs(**localns: Any) → None¶
Try to update ForwardRefs on fields based on this Model, globalns and localns.
Parameters
localns (Any) – 
Return type
None
classmethod validate(value: Any) → Model¶
Parameters
value (Any) – 
Return type
Model
with_alisteners(*, on_start: Optional[AsyncListener] = None, on_end: Optional[AsyncListener] = None, on_error: Optional[AsyncListener] = None) → Runnable[Input, Output]¶
Bind asynchronous lifecycle listeners to a Runnable, returning a new Runnable.
on_start: Asynchronously called before the runnable starts running.
on_end: Asynchronously called after the runnable finishes running.
on_error: Asynchronously called if the runnable throws an error.
The Run object contains information about the run, including its id,
type, input, output, error, start_time, end_time, and any tags or metadata
type, input, output, error, start_time, end_time, and any tags or metadata
added to the run.
Example:
Parameters
on_start (Optional[AsyncListener]) – 
on_end (Optional[AsyncListener]) – 
on_error (Optional[AsyncListener]) – 
Return type
Runnable[Input, Output]
with_config(config: Optional[RunnableConfig] = None, **kwargs: Any) → Runnable[Input, Output]¶
Bind config to a Runnable, returning a new Runnable.
Parameters
config (Optional[RunnableConfig]) – 
kwargs (Any) – 
Return type
Runnable[Input, Output]
with_fallbacks(fallbacks: Sequence[Runnable[Input, Output]], *, exceptions_to_handle: Tuple[Type[BaseException], ...] = (<class 'Exception'>,), exception_key: Optional[str] = None) → RunnableWithFallbacksT[Input, Output]¶
Add fallbacks to a runnable, returning a new Runnable.
Example
from typing import Iterator
from langchain_core.runnables import RunnableGenerator
def _generate_immediate_error(input: Iterator) -> Iterator[str]:
    raise ValueError()
    yield ""
def _generate(input: Iterator) -> Iterator[str]:
    yield from "foo bar"
runnable = RunnableGenerator(_generate_immediate_error).with_fallbacks(
    [RunnableGenerator(_generate)]
    )
print(''.join(runnable.stream({}))) #foo bar
Parameters
fallbacks (Sequence[Runnable[Input, Output]]) – A sequence of runnables to try if the original runnable fails.
exceptions_to_handle (Tuple[Type[BaseException], ...]) – A tuple of exception types to handle.
exception_key (Optional[str]) – If string is specified then handled exceptions will be passed
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]¶
Input keys.
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.
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_keys: List[str]¶
Output keys.
property output_schema: Type[BaseModel]¶
The type of output this runnable produces specified as a pydantic model.
langchain_community.query_constructors.myscale.MyScaleTranslator¶
class langchain_community.query_constructors.myscale.MyScaleTranslator(metadata_key: str = 'metadata')[source]¶
Translate MyScale internal query language elements to valid filters.
Attributes
allowed_comparators
allowed_operators
Subset of allowed logical operators.
map_dict
Methods
__init__([metadata_key])
visit_comparison(comparison)
Translate a Comparison.
visit_operation(operation)
Translate an Operation.
visit_structured_query(structured_query)
Translate a StructuredQuery.
Parameters
metadata_key (str) – 
__init__(metadata_key: str = 'metadata') → None[source]¶
Parameters
metadata_key (str) – 
Return type
None
visit_comparison(comparison: Comparison) → Dict[source]¶
Translate a Comparison.
Parameters
comparison (Comparison) – 
Return type
Dict
visit_operation(operation: Operation) → Dict[source]¶
Translate an Operation.
Parameters
operation (Operation) – 
Return type
Dict
visit_structured_query(structured_query: StructuredQuery) → Tuple[str, dict][source]¶
Translate a StructuredQuery.
Parameters
structured_query (StructuredQuery) – 
Return type
Tuple[str, dict]
langchain_community.query_constructors.supabase.SupabaseVectorTranslator¶
class langchain_community.query_constructors.supabase.SupabaseVectorTranslator[source]¶
Translate Langchain filters to Supabase PostgREST filters.
Attributes
allowed_comparators
Subset of allowed logical comparators.
allowed_operators
Subset of allowed logical operators.
metadata_column
Methods
__init__()
visit_comparison(comparison)
Translate a Comparison.
visit_operation(operation)
Translate an Operation.
visit_structured_query(structured_query)
Translate a StructuredQuery.
__init__()¶
visit_comparison(comparison: Comparison) → str[source]¶
Translate a Comparison.
Parameters
comparison (Comparison) – 
Return type
str
visit_operation(operation: Operation) → str[source]¶
Translate an Operation.
Parameters
operation (Operation) – 
Return type
str
visit_structured_query(structured_query: StructuredQuery) → Tuple[str, Dict[str, str]][source]¶
Translate a StructuredQuery.
Parameters
structured_query (StructuredQuery) – 
Return type
Tuple[str, Dict[str, str]]
langchain_community.query_constructors.weaviate.WeaviateTranslator¶
class langchain_community.query_constructors.weaviate.WeaviateTranslator[source]¶
Translate Weaviate internal query language elements to valid filters.
Attributes
allowed_comparators
allowed_operators
Subset of allowed logical operators.
Methods
__init__()
visit_comparison(comparison)
Translate a Comparison.
visit_operation(operation)
Translate an Operation.
visit_structured_query(structured_query)
Translate a StructuredQuery.
__init__()¶
visit_comparison(comparison: Comparison) → Dict[source]¶
Translate a Comparison.
Parameters
comparison (Comparison) – 
Return type
Dict
visit_operation(operation: Operation) → Dict[source]¶
Translate an Operation.
Parameters
operation (Operation) – 
Return type
Dict
visit_structured_query(structured_query: StructuredQuery) → Tuple[str, dict][source]¶
Translate a StructuredQuery.
Parameters
structured_query (StructuredQuery) – 
Return type
Tuple[str, dict]
langchain_community.query_constructors.chroma.ChromaTranslator¶
class langchain_community.query_constructors.chroma.ChromaTranslator[source]¶
Translate Chroma internal query language elements to valid filters.
Attributes
allowed_comparators
Subset of allowed logical comparators.
allowed_operators
Subset of allowed logical operators.
Methods
__init__()
visit_comparison(comparison)
Translate a Comparison.
visit_operation(operation)
Translate an Operation.
visit_structured_query(structured_query)
Translate a StructuredQuery.
__init__()¶
visit_comparison(comparison: Comparison) → Dict[source]¶
Translate a Comparison.
Parameters
comparison (Comparison) – 
Return type
Dict
visit_operation(operation: Operation) → Dict[source]¶
Translate an Operation.
Parameters
operation (Operation) – 
Return type
Dict
visit_structured_query(structured_query: StructuredQuery) → Tuple[str, dict][source]¶
Translate a StructuredQuery.
Parameters
structured_query (StructuredQuery) – 
Return type
Tuple[str, dict]
Examples using ChromaTranslator¶
How to construct filters for query analysis
How to do “self-querying” retrieval
langchain_community.query_constructors.milvus.process_value¶
langchain_community.query_constructors.milvus.process_value(value: Union[int, float, str], comparator: Comparator) → str[source]¶
Convert a value to a string and add double quotes if it is a string.
It required for comparators involving strings.
Parameters
value (Union[int, float, str]) – The value to convert.
comparator (Comparator) – The comparator.
Returns
The converted value as a string.
Return type
str
langchain_community.query_constructors.redis.RedisTranslator¶
class langchain_community.query_constructors.redis.RedisTranslator(schema: RedisModel)[source]¶
Visitor for translating structured queries to Redis filter expressions.
Attributes
allowed_comparators
Subset of allowed logical comparators.
allowed_operators
Subset of allowed logical operators.
Methods
__init__(schema)
from_vectorstore(vectorstore)
visit_comparison(comparison)
Translate a Comparison.
visit_operation(operation)
Translate an Operation.
visit_structured_query(structured_query)
Translate a StructuredQuery.
Parameters
schema (RedisModel) – 
__init__(schema: RedisModel) → None[source]¶
Parameters
schema (RedisModel) – 
Return type
None
classmethod from_vectorstore(vectorstore: Redis) → RedisTranslator[source]¶
Parameters
vectorstore (Redis) – 
Return type
RedisTranslator
visit_comparison(comparison: Comparison) → RedisFilterExpression[source]¶
Translate a Comparison.
Parameters
comparison (Comparison) – 
Return type
RedisFilterExpression
visit_operation(operation: Operation) → Any[source]¶
Translate an Operation.
Parameters
operation (Operation) – 
Return type
Any
visit_structured_query(structured_query: StructuredQuery) → Tuple[str, dict][source]¶
Translate a StructuredQuery.
Parameters
structured_query (StructuredQuery) – 
Return type
Tuple[str, dict]
langchain_community.query_constructors.astradb.AstraDBTranslator¶
class langchain_community.query_constructors.astradb.AstraDBTranslator[source]¶
Translate AstraDB internal query language elements to valid filters.
Attributes
allowed_comparators
Subset of allowed logical operators.
allowed_operators
Methods
__init__()
visit_comparison(comparison)
Translate a Comparison.
visit_operation(operation)
Translate an Operation.
visit_structured_query(structured_query)
Translate a StructuredQuery.
__init__()¶
visit_comparison(comparison: Comparison) → Dict[source]¶
Translate a Comparison.
Parameters
comparison (Comparison) – 
Return type
Dict
visit_operation(operation: Operation) → Dict[source]¶
Translate an Operation.
Parameters
operation (Operation) – 
Return type
Dict
visit_structured_query(structured_query: StructuredQuery) → Tuple[str, dict][source]¶
Translate a StructuredQuery.
Parameters
structured_query (StructuredQuery) – 
Return type
Tuple[str, dict]
langchain_community.query_constructors.milvus.MilvusTranslator¶
class langchain_community.query_constructors.milvus.MilvusTranslator[source]¶
Translate Milvus internal query language elements to valid filters.
Attributes
allowed_comparators
allowed_operators
Subset of allowed logical comparators.
Methods
__init__()
visit_comparison(comparison)
Translate a Comparison.
visit_operation(operation)
Translate an Operation.
visit_structured_query(structured_query)
Translate a StructuredQuery.
__init__()¶
visit_comparison(comparison: Comparison) → str[source]¶
Translate a Comparison.
Parameters
comparison (Comparison) – 
Return type
str
visit_operation(operation: Operation) → str[source]¶
Translate an Operation.
Parameters
operation (Operation) – 
Return type
str
visit_structured_query(structured_query: StructuredQuery) → Tuple[str, dict][source]¶
Translate a StructuredQuery.
Parameters
structured_query (StructuredQuery) – 
Return type
Tuple[str, dict]
langchain_community.query_constructors.elasticsearch.ElasticsearchTranslator¶
class langchain_community.query_constructors.elasticsearch.ElasticsearchTranslator[source]¶
Translate Elasticsearch internal query language elements to valid filters.
Attributes
allowed_comparators
Subset of allowed logical comparators.
allowed_operators
Subset of allowed logical operators.
Methods
__init__()
visit_comparison(comparison)
Translate a Comparison.
visit_operation(operation)
Translate an Operation.
visit_structured_query(structured_query)
Translate a StructuredQuery.
__init__()¶
visit_comparison(comparison: Comparison) → Dict[source]¶
Translate a Comparison.
Parameters
comparison (Comparison) – 
Return type
Dict
visit_operation(operation: Operation) → Dict[source]¶
Translate an Operation.
Parameters
operation (Operation) – 
Return type
Dict
visit_structured_query(structured_query: StructuredQuery) → Tuple[str, dict][source]¶
Translate a StructuredQuery.
Parameters
structured_query (StructuredQuery) – 
Return type
Tuple[str, dict]
Examples using ElasticsearchTranslator¶
How to construct filters for query analysis
langchain_community.query_constructors.timescalevector.TimescaleVectorTranslator¶
class langchain_community.query_constructors.timescalevector.TimescaleVectorTranslator[source]¶
Translate the internal query language elements to valid filters.
Attributes
COMPARATOR_MAP
OPERATOR_MAP
allowed_comparators
allowed_operators
Subset of allowed logical operators.
Methods
__init__()
visit_comparison(comparison)
Translate a Comparison.
visit_operation(operation)
Translate an Operation.
visit_structured_query(structured_query)
Translate a StructuredQuery.
__init__()¶
visit_comparison(comparison: Comparison) → client.Predicates[source]¶
Translate a Comparison.
Parameters
comparison (Comparison) – 
Return type
client.Predicates
visit_operation(operation: Operation) → client.Predicates[source]¶
Translate an Operation.
Parameters
operation (Operation) – 
Return type
client.Predicates
visit_structured_query(structured_query: StructuredQuery) → Tuple[str, dict][source]¶
Translate a StructuredQuery.
Parameters
structured_query (StructuredQuery) – 
Return type
Tuple[str, dict]
langchain_community.query_constructors.deeplake.DeepLakeTranslator¶
class langchain_community.query_constructors.deeplake.DeepLakeTranslator[source]¶
Translate DeepLake internal query language elements to valid filters.
Attributes
allowed_comparators
Subset of allowed logical comparators.
allowed_operators
Subset of allowed logical operators.
Methods
__init__()
visit_comparison(comparison)
Translate a Comparison.
visit_operation(operation)
Translate an Operation.
visit_structured_query(structured_query)
Translate a StructuredQuery.
__init__()¶
visit_comparison(comparison: Comparison) → str[source]¶
Translate a Comparison.
Parameters
comparison (Comparison) – 
Return type
str
visit_operation(operation: Operation) → str[source]¶
Translate an Operation.
Parameters
operation (Operation) – 
Return type
str
visit_structured_query(structured_query: StructuredQuery) → Tuple[str, dict][source]¶
Translate a StructuredQuery.
Parameters
structured_query (StructuredQuery) – 
Return type
Tuple[str, dict]
langchain_community.query_constructors.mongodb_atlas.MongoDBAtlasTranslator¶
class langchain_community.query_constructors.mongodb_atlas.MongoDBAtlasTranslator[source]¶
Translate Mongo internal query language elements to valid filters.
Attributes
allowed_comparators
Subset of allowed logical operators.
allowed_operators
Methods
__init__()
visit_comparison(comparison)
Translate a Comparison.
visit_operation(operation)
Translate an Operation.
visit_structured_query(structured_query)
Translate a StructuredQuery.
__init__()¶
visit_comparison(comparison: Comparison) → Dict[source]¶
Translate a Comparison.
Parameters
comparison (Comparison) – 
Return type
Dict
visit_operation(operation: Operation) → Dict[source]¶
Translate an Operation.
Parameters
operation (Operation) – 
Return type
Dict
visit_structured_query(structured_query: StructuredQuery) → Tuple[str, dict][source]¶
Translate a StructuredQuery.
Parameters
structured_query (StructuredQuery) – 
Return type
Tuple[str, dict]
langchain_community.query_constructors.qdrant.QdrantTranslator¶
class langchain_community.query_constructors.qdrant.QdrantTranslator(metadata_key: str)[source]¶
Translate Qdrant internal query language elements to valid filters.
Attributes
allowed_comparators
Subset of allowed logical comparators.
allowed_operators
Subset of allowed logical operators.
Methods
__init__(metadata_key)
visit_comparison(comparison)
Translate a Comparison.
visit_operation(operation)
Translate an Operation.
visit_structured_query(structured_query)
Translate a StructuredQuery.
Parameters
metadata_key (str) – 
__init__(metadata_key: str)[source]¶
Parameters
metadata_key (str) – 
visit_comparison(comparison: Comparison) → rest.FieldCondition[source]¶
Translate a Comparison.
Parameters
comparison (Comparison) – 
Return type
rest.FieldCondition
visit_operation(operation: Operation) → rest.Filter[source]¶
Translate an Operation.
Parameters
operation (Operation) – 
Return type
rest.Filter
visit_structured_query(structured_query: StructuredQuery) → Tuple[str, dict][source]¶
Translate a StructuredQuery.
Parameters
structured_query (StructuredQuery) – 
Return type
Tuple[str, dict]
langchain_community.query_constructors.opensearch.OpenSearchTranslator¶
class langchain_community.query_constructors.opensearch.OpenSearchTranslator[source]¶
Translate OpenSearch internal query domain-specific
language elements to valid filters.
Attributes
allowed_comparators
Subset of allowed logical comparators.
allowed_operators
Subset of allowed logical operators.
Methods
__init__()
visit_comparison(comparison)
Translate a Comparison.
visit_operation(operation)
Translate an Operation.
visit_structured_query(structured_query)
Translate a StructuredQuery.
__init__()¶
visit_comparison(comparison: Comparison) → Dict[source]¶
Translate a Comparison.
Parameters
comparison (Comparison) – 
Return type
Dict
visit_operation(operation: Operation) → Dict[source]¶
Translate an Operation.
Parameters
operation (Operation) – 
Return type
Dict
visit_structured_query(structured_query: StructuredQuery) → Tuple[str, dict][source]¶
Translate a StructuredQuery.
Parameters
structured_query (StructuredQuery) – 
Return type
Tuple[str, dict]
langchain_community.query_constructors.dingo.DingoDBTranslator¶
class langchain_community.query_constructors.dingo.DingoDBTranslator[source]¶
Translate DingoDB internal query language elements to valid filters.
Attributes
allowed_comparators
Subset of allowed logical comparators.
allowed_operators
Subset of allowed logical operators.
Methods
__init__()
visit_comparison(comparison)
Translate a Comparison.
visit_operation(operation)
Translate an Operation.
visit_structured_query(structured_query)
Translate a StructuredQuery.
__init__()¶
visit_comparison(comparison: Comparison) → Comparison[source]¶
Translate a Comparison.
Parameters
comparison (Comparison) – 
Return type
Comparison
visit_operation(operation: Operation) → Operation[source]¶
Translate an Operation.
Parameters
operation (Operation) – 
Return type
Operation
visit_structured_query(structured_query: StructuredQuery) → Tuple[str, dict][source]¶
Translate a StructuredQuery.
Parameters
structured_query (StructuredQuery) – 
Return type
Tuple[str, dict]
langchain_community.query_constructors.pgvector.PGVectorTranslator¶
class langchain_community.query_constructors.pgvector.PGVectorTranslator[source]¶
Translate PGVector internal query language elements to valid filters.
Attributes
allowed_comparators
Subset of allowed logical comparators.
allowed_operators
Subset of allowed logical operators.
Methods
__init__()
visit_comparison(comparison)
Translate a Comparison.
visit_operation(operation)
Translate an Operation.
visit_structured_query(structured_query)
Translate a StructuredQuery.
__init__()¶
visit_comparison(comparison: Comparison) → Dict[source]¶
Translate a Comparison.
Parameters
comparison (Comparison) – 
Return type
Dict
visit_operation(operation: Operation) → Dict[source]¶
Translate an Operation.
Parameters
operation (Operation) – 
Return type
Dict
visit_structured_query(structured_query: StructuredQuery) → Tuple[str, dict][source]¶
Translate a StructuredQuery.
Parameters
structured_query (StructuredQuery) – 
Return type
Tuple[str, dict]