Tony20100/langchain_full huggingface dataset:
langchain_community.indexes.base.RecordManager¶
class langchain_community.indexes.base.RecordManager(namespace: str)[source]¶
Abstract base class for a record manager.
Initialize the record manager.
Parameters
namespace (str) – The namespace for the record manager.
Methods
__init__(namespace)
Initialize the record manager.
acreate_schema()
Create the database schema for the record manager.
adelete_keys(keys)
Delete specified records from the database.
aexists(keys)
Check if the provided keys exist in the database.
aget_time()
Get the current server time as a high resolution timestamp!
alist_keys(*[, before, after, group_ids, limit])
List records in the database based on the provided filters.
aupdate(keys, *[, group_ids, time_at_least])
Upsert records into the database.
create_schema()
Create the database schema for the record manager.
delete_keys(keys)
Delete specified records from the database.
exists(keys)
Check if the provided keys exist in the database.
get_time()
Get the current server time as a high resolution timestamp!
list_keys(*[, before, after, group_ids, limit])
List records in the database based on the provided filters.
update(keys, *[, group_ids, time_at_least])
Upsert records into the database.
__init__(namespace: str) → None[source]¶
Initialize the record manager.
Parameters
namespace (str) – The namespace for the record manager.
Return type
None
abstract async acreate_schema() → None[source]¶
Create the database schema for the record manager.
Return type
None
abstract async adelete_keys(keys: Sequence[str]) → None[source]¶
Delete specified records from the database.
Parameters
Delete specified records from the database.
Parameters
keys (Sequence[str]) – A list of keys to delete.
Return type
None
abstract async aexists(keys: Sequence[str]) → List[bool][source]¶
Check if the provided keys exist in the database.
Parameters
keys (Sequence[str]) – A list of keys to check.
Returns
A list of boolean values indicating the existence of each key.
Return type
List[bool]
abstract async aget_time() → float[source]¶
Get the current server time as a high resolution timestamp!
It’s important to get this from the server to ensure a monotonic clock,
otherwise there may be data loss when cleaning up old documents!
Returns
The current server time as a float timestamp.
Return type
float
abstract async alist_keys(*, before: Optional[float] = None, after: Optional[float] = None, group_ids: Optional[Sequence[str]] = None, limit: Optional[int] = None) → List[str][source]¶
List records in the database based on the provided filters.
Parameters
before (Optional[float]) – Filter to list records updated before this time.
after (Optional[float]) – Filter to list records updated after this time.
group_ids (Optional[Sequence[str]]) – Filter to list records with specific group IDs.
limit (Optional[int]) – optional limit on the number of records to return.
Returns
A list of keys for the matching records.
Return type
List[str]
abstract async aupdate(keys: Sequence[str], *, group_ids: Optional[Sequence[Optional[str]]] = None, time_at_least: Optional[float] = None) → None[source]¶
Upsert records into the database.
Parameters
keys (Sequence[str]) – A list of record keys to upsert.
Parameters
keys (Sequence[str]) – A list of record keys to upsert.
group_ids (Optional[Sequence[Optional[str]]]) – A list of group IDs corresponding to the keys.
time_at_least (Optional[float]) – if provided, updates should only happen if the
updated_at field is at least this time.
Raises
ValueError – If the length of keys doesn’t match the length of group_ids.
Return type
None
abstract create_schema() → None[source]¶
Create the database schema for the record manager.
Return type
None
abstract delete_keys(keys: Sequence[str]) → None[source]¶
Delete specified records from the database.
Parameters
keys (Sequence[str]) – A list of keys to delete.
Return type
None
abstract exists(keys: Sequence[str]) → List[bool][source]¶
Check if the provided keys exist in the database.
Parameters
keys (Sequence[str]) – A list of keys to check.
Returns
A list of boolean values indicating the existence of each key.
Return type
List[bool]
abstract get_time() → float[source]¶
Get the current server time as a high resolution timestamp!
It’s important to get this from the server to ensure a monotonic clock,
otherwise there may be data loss when cleaning up old documents!
Returns
The current server time as a float timestamp.
Return type
float
abstract list_keys(*, before: Optional[float] = None, after: Optional[float] = None, group_ids: Optional[Sequence[str]] = None, limit: Optional[int] = None) → List[str][source]¶
List records in the database based on the provided filters.
Parameters
before (Optional[float]) – Filter to list records updated before this time.
after (Optional[float]) – Filter to list records updated after this time.
after (Optional[float]) – Filter to list records updated after this time.
group_ids (Optional[Sequence[str]]) – Filter to list records with specific group IDs.
limit (Optional[int]) – optional limit on the number of records to return.
Returns
A list of keys for the matching records.
Return type
List[str]
abstract update(keys: Sequence[str], *, group_ids: Optional[Sequence[Optional[str]]] = None, time_at_least: Optional[float] = None) → None[source]¶
Upsert records into the database.
Parameters
keys (Sequence[str]) – A list of record keys to upsert.
group_ids (Optional[Sequence[Optional[str]]]) – A list of group IDs corresponding to the keys.
time_at_least (Optional[float]) – if provided, updates should only happen if the
updated_at field is at least this time.
Raises
ValueError – If the length of keys doesn’t match the length of group_ids.
Return type
None
langchain.indexes.vectorstore.VectorStoreIndexWrapper¶
class langchain.indexes.vectorstore.VectorStoreIndexWrapper[source]¶
Bases: BaseModel
Wrapper around a vectorstore for easy access.
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 vectorstore: VectorStore [Required]¶
async aquery(question: str, llm: Optional[BaseLanguageModel] = None, retriever_kwargs: Optional[Dict[str, Any]] = None, **kwargs: Any) → str[source]¶
Query the vectorstore.
Parameters
question (str) – 
llm (Optional[BaseLanguageModel]) – 
retriever_kwargs (Optional[Dict[str, Any]]) – 
kwargs (Any) – 
Return type
str
async aquery_with_sources(question: str, llm: Optional[BaseLanguageModel] = None, retriever_kwargs: Optional[Dict[str, Any]] = None, **kwargs: Any) → dict[source]¶
Query the vectorstore and get back sources.
Parameters
question (str) – 
llm (Optional[BaseLanguageModel]) – 
retriever_kwargs (Optional[Dict[str, Any]]) – 
kwargs (Any) – 
Return type
dict
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
content_type (unicode) – 
encoding (unicode) – 
proto (Protocol) – 
allow_pickle (bool) – 
Return type
Model
classmethod parse_obj(obj: Any) → Model¶
Parameters
obj (Any) – 
Return type
Model
classmethod parse_raw(b: Union[str, bytes], *, content_type: unicode = None, encoding: unicode = 'utf8', proto: Protocol = None, allow_pickle: bool = False) → Model¶
Parameters
b (Union[str, bytes]) – 
content_type (unicode) – 
encoding (unicode) – 
proto (Protocol) – 
allow_pickle (bool) – 
Return type
Model
query(question: str, llm: Optional[BaseLanguageModel] = None, retriever_kwargs: Optional[Dict[str, Any]] = None, **kwargs: Any) → str[source]¶
Query the vectorstore.
Parameters
question (str) – 
llm (Optional[BaseLanguageModel]) – 
retriever_kwargs (Optional[Dict[str, Any]]) – 
kwargs (Any) – 
Return type
str
query_with_sources(question: str, llm: Optional[BaseLanguageModel] = None, retriever_kwargs: Optional[Dict[str, Any]] = None, **kwargs: Any) → dict[source]¶
Query the vectorstore and get back sources.
Parameters
question (str) – 
llm (Optional[BaseLanguageModel]) – 
retriever_kwargs (Optional[Dict[str, Any]]) – 
kwargs (Any) – 
Return type
dict
classmethod schema(by_alias: bool = True, ref_template: unicode = '#/definitions/{model}') → DictStrAny¶
Parameters
by_alias (bool) – 
ref_template (unicode) – 
Return type
DictStrAny
langchain.indexes.vectorstore.VectorstoreIndexCreator¶
class langchain.indexes.vectorstore.VectorstoreIndexCreator[source]¶
Bases: BaseModel
Logic for creating indexes.
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 embedding: Embeddings [Required]¶
param text_splitter: TextSplitter [Optional]¶
param vectorstore_cls: Type[VectorStore] [Optional]¶
param vectorstore_kwargs: dict [Optional]¶
async afrom_documents(documents: List[Document]) → VectorStoreIndexWrapper[source]¶
Create a vectorstore index from documents.
Parameters
documents (List[Document]) – 
Return type
VectorStoreIndexWrapper
async afrom_loaders(loaders: List[BaseLoader]) → VectorStoreIndexWrapper[source]¶
Create a vectorstore index from loaders.
Parameters
loaders (List[BaseLoader]) – 
Return type
VectorStoreIndexWrapper
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
Duplicate a model, optionally choose which fields to include, exclude and change.
Parameters
include (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) – fields to include in new model
exclude (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) – fields to exclude from new model, as with values this takes precedence over include
update (Optional[DictStrAny]) – values to change/add in the new model. Note: the data is not validated before creating
the new model: you should trust this data
deep (bool) – set to True to make a deep copy of the model
self (Model) – 
Returns
new model instance
Return type
Model
dict(*, 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) → DictStrAny¶
Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.
Parameters
include (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) – 
exclude (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) – 
by_alias (bool) – 
skip_defaults (Optional[bool]) – 
exclude_unset (bool) – 
exclude_defaults (bool) – 
exclude_none (bool) – 
Return type
DictStrAny
from_documents(documents: List[Document]) → VectorStoreIndexWrapper[source]¶
Create a vectorstore index from documents.
Parameters
documents (List[Document]) – 
Return type
VectorStoreIndexWrapper
Parameters
documents (List[Document]) – 
Return type
VectorStoreIndexWrapper
from_loaders(loaders: List[BaseLoader]) → VectorStoreIndexWrapper[source]¶
Create a vectorstore index from loaders.
Parameters
loaders (List[BaseLoader]) – 
Return type
VectorStoreIndexWrapper
classmethod from_orm(obj: Any) → Model¶
Parameters
obj (Any) – 
Return type
Model
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¶
Generate a JSON representation of the model, include and exclude arguments as per dict().
encoder is an optional function to supply as default to json.dumps(), other arguments as per json.dumps().
Parameters
include (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) – 
exclude (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) – 
by_alias (bool) – 
skip_defaults (Optional[bool]) – 
exclude_unset (bool) – 
exclude_defaults (bool) – 
exclude_none (bool) – 
encoder (Optional[Callable[[Any], Any]]) – 
models_as_dict (bool) – 
dumps_kwargs (Any) – 
Return type
unicode
langchain_core.messages.tool.default_tool_parser¶
langchain_core.messages.tool.default_tool_parser(raw_tool_calls: List[dict]) → Tuple[List[ToolCall], List[InvalidToolCall]][source]¶
Best-effort parsing of tools.
Parameters
raw_tool_calls (List[dict]) – 
Return type
Tuple[List[ToolCall], List[InvalidToolCall]]
langchain_core.messages.tool.ToolCall¶
class langchain_core.messages.tool.ToolCall[source]¶
Represents a request to call a tool.
name¶
(str) the name of the tool to be called
Type
str
args¶
(dict) the arguments to the tool call
Type
Dict[str, Any]
id¶
(str) if provided, an identifier associated with the tool call
Type
Optional[str]
Attributes
name
args
id
Methods
__init__(*args, **kwargs)
clear()
copy()
fromkeys([value])
Create a new dictionary with keys from iterable and values set to value.
get(key[, default])
Return the value for key if key is in the dictionary, else default.
items()
keys()
pop(k[,d])
If the key is not found, return the default if given; otherwise, raise a KeyError.
popitem()
Remove and return a (key, value) pair as a 2-tuple.
setdefault(key[, default])
Insert key with a value of default if key is not in the dictionary.
update([E, ]**F)
If E is present and has a .keys() method, then does:  for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does:  for k, v in E: D[k] = v In either case, this is followed by: for k in F:  D[k] = F[k]
values()
__init__(*args, **kwargs)¶
clear() → None.  Remove all items from D.¶
copy() → a shallow copy of D¶
fromkeys(value=None, /)¶
Create a new dictionary with keys from iterable and values set to value.
get(key, default=None, /)¶
get(key, default=None, /)¶
Return the value for key if key is in the dictionary, else default.
items() → a set-like object providing a view on D's items¶
keys() → a set-like object providing a view on D's keys¶
pop(k[, d]) → v, remove specified key and return the corresponding value.¶
If the key is not found, return the default if given; otherwise,
raise a KeyError.
popitem()¶
Remove and return a (key, value) pair as a 2-tuple.
Pairs are returned in LIFO (last-in, first-out) order.
Raises KeyError if the dict is empty.
setdefault(key, default=None, /)¶
Insert key with a value of default if key is not in the dictionary.
Return the value for key if key is in the dictionary, else default.
update([E, ]**F) → None.  Update D from dict/iterable E and F.¶
If E is present and has a .keys() method, then does:  for k in E: D[k] = E[k]
If E is present and lacks a .keys() method, then does:  for k, v in E: D[k] = v
In either case, this is followed by: for k in F:  D[k] = F[k]
values() → an object providing a view on D's values¶
Examples using ToolCall¶
How to handle tool errors
langchain_core.messages.base.merge_content¶
langchain_core.messages.base.merge_content(first_content: Union[str, List[Union[str, Dict]]], second_content: Union[str, List[Union[str, Dict]]]) → Union[str, List[Union[str, Dict]]][source]¶
Merge two message contents.
Parameters
first_content (Union[str, List[Union[str, Dict]]]) – The first content.
second_content (Union[str, List[Union[str, Dict]]]) – The second content.
Returns
The merged content.
Return type
Union[str, List[Union[str, Dict]]]
langchain_core.messages.human.HumanMessage¶
class langchain_core.messages.human.HumanMessage[source]¶
Bases: BaseMessage
Message from a human.
Pass in content as positional arg.
param additional_kwargs: dict [Optional]¶
Reserved for additional payload data associated with the message.
For example, for a message from an AI, this could include tool calls.
param content: Union[str, List[Union[str, Dict]]] [Required]¶
The string contents of the message.
param example: bool = False¶
Whether this Message is being passed in to the model as part of an example
conversation.
param id: Optional[str] = None¶
An optional unique identifier for the message. This should ideally be
provided by the provider/model which created the message.
param name: Optional[str] = None¶
param response_metadata: dict [Optional]¶
Response metadata. For example: response headers, logprobs, token counts.
param type: Literal['human'] = 'human'¶
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
path (Union[str, Path]) – 
content_type (unicode) – 
encoding (unicode) – 
proto (Protocol) – 
allow_pickle (bool) – 
Return type
Model
classmethod parse_obj(obj: Any) → Model¶
Parameters
obj (Any) – 
Return type
Model
classmethod parse_raw(b: Union[str, bytes], *, content_type: unicode = None, encoding: unicode = 'utf8', proto: Protocol = None, allow_pickle: bool = False) → Model¶
Parameters
b (Union[str, bytes]) – 
content_type (unicode) – 
encoding (unicode) – 
proto (Protocol) – 
allow_pickle (bool) – 
Return type
Model
pretty_print() → None¶
Return type
None
pretty_repr(html: bool = False) → str¶
Parameters
html (bool) – 
Return type
str
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
to_json() → Union[SerializedConstructor, SerializedNotImplemented]¶
Return type
Union[SerializedConstructor, SerializedNotImplemented]
to_json_not_implemented() → SerializedNotImplemented¶
Return type
SerializedNotImplemented
classmethod update_forward_refs(**localns: Any) → None¶
Try to update ForwardRefs on fields based on this Model, globalns and localns.
Parameters
Parameters
localns (Any) – 
Return type
None
classmethod validate(value: Any) → Model¶
Parameters
value (Any) – 
Return type
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”}
Examples using HumanMessage¶
-> content=’Hello! How can I assist you today?’
Activeloop Deep Memory
Alibaba Cloud PAI EAS
Arthur
Azure ML
AzureChatOpenAI
AzureMLChatOnlineEndpoint
Browserbase
Build a Chatbot
Build a Question/Answering system over SQL data
Build a Simple LLM Application
Build an Agent
Chat Bot Feedback Template
Chat with Baichuan-192K
Chat with Coze Bot
ChatAnthropic
ChatAnyscale
ChatBedrock
ChatEverlyAI
ChatFireworks
ChatFriendli
ChatKonko
ChatLiteLLM
ChatLiteLLMRouter
ChatOctoAI
ChatOllama
ChatPremAI
ChatTongyi
ChatVertexAI
ChatYandexGPT
Cohere
Conceptual guide
Context
Conversational RAG
Dappier AI
Databricks
DeepInfra
Discord
Eden AI
ErnieBotChat
Flyte
GPTRouter
GigaChat
Google
Google AI chat models
Google Cloud Vertex AI
Google Imagen
How to add a semantic layer over graph database
How to add chat history
How to add examples to the prompt for query analysis
How to add memory to chatbots
How to add message history
How to add retrieval to chatbots
How to add message history
How to add retrieval to chatbots
How to add tools to chatbots
How to compose prompts together
How to convert tools to OpenAI Functions
How to create a custom chat model class
How to do tool/function calling
How to handle tool errors
How to pass multimodal data directly to models
How to return structured data from a model
How to use a model to call tools
How to use callbacks in async environments
How to use reference examples when doing extraction
Hugging Face
Javelin AI Gateway
Javelin AI Gateway Tutorial
JinaChat
LLMonitor
Label Studio
LlamaEdge
Log10
MLX
MLflow AI Gateway
MLflow Deployments for LLMs
Maritalk
MiniMaxChat
MistralAI
MoonshotChat
NVIDIA NIMs
OllamaFunctions
PremAI
PromptLayer
PromptLayerChatOpenAI
QianfanChatEndpoint
SparkLLM Chat
Tencent Hunyuan
Trubrics
VolcEngineMaasChat
WeChat
Yuan2.0
ZHIPU AI
Zep Cloud
Zep Cloud Memory
Zep Open Source
Zep Open Source Memory
ZepCloudChatMessageHistory
solar.md
vLLM Chat
🦜️🏓 LangServe
langchain_core.messages.tool.ToolMessage¶
class langchain_core.messages.tool.ToolMessage[source]¶
Bases: BaseMessage
Message for passing the result of executing a tool back to a model.
Pass in content as positional arg.
param additional_kwargs: dict [Optional]¶
Reserved for additional payload data associated with the message.
For example, for a message from an AI, this could include tool calls.
param content: Union[str, List[Union[str, Dict]]] [Required]¶
The string contents of the message.
param id: Optional[str] = None¶
An optional unique identifier for the message. This should ideally be
provided by the provider/model which created the message.
param name: Optional[str] = None¶
param response_metadata: dict [Optional]¶
Response metadata. For example: response headers, logprobs, token counts.
param tool_call_id: str [Required]¶
Tool call that this message is responding to.
param type: Literal['tool'] = 'tool'¶
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
localns (Any) – 
Return type
None
classmethod validate(value: Any) → Model¶
Parameters
value (Any) – 
Return type
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”}
Examples using ToolMessage¶
ChatAnthropic
How to add examples to the prompt for query analysis
How to create a custom chat model class
How to do question answering over CSVs
How to do tool/function calling
How to handle tool errors
How to return structured data from a model
How to use a model to call tools
How to use reference examples when doing extraction
langchain_core.messages.utils.messages_from_dict¶
langchain_core.messages.utils.messages_from_dict(messages: Sequence[dict]) → List[BaseMessage][source]¶
Convert a sequence of messages from dicts to Message objects.
Parameters
messages (Sequence[dict]) – Sequence of messages (as dicts) to convert.
Returns
List of messages (BaseMessages).
Return type
List[BaseMessage]