Tony20100/langchain_full huggingface dataset:
langchain_experimental.graph_transformers.diffbot.NodesList¶
class langchain_experimental.graph_transformers.diffbot.NodesList[source]¶
List of nodes with associated properties.
nodes¶
Stores nodes as keys and their properties as values.
Each key is a tuple where the first element is the
node ID and the second is the node type.
Type
Dict[Tuple, Any]
Methods
__init__()
add_node_property(node, properties)
Adds or updates node properties.
return_node_list()
Returns the nodes as a list of Node objects.
__init__() → None[source]¶
Return type
None
add_node_property(node: Tuple[Union[str, int], str], properties: Dict[str, Any]) → None[source]¶
Adds or updates node properties.
If the node does not exist in the list, it’s added along with its properties.
If the node already exists, its properties are updated with the new values.
Parameters
node (Tuple) – A tuple containing the node ID and node type.
properties (Dict) – A dictionary of properties to add or update for the node.
Return type
None
return_node_list() → List[Node][source]¶
Returns the nodes as a list of Node objects.
Each Node object will have its ID, type, and properties populated.
Returns
A list of Node objects.
Return type
List[Node]
langchain_experimental.graph_transformers.diffbot.SimplifiedSchema¶
class langchain_experimental.graph_transformers.diffbot.SimplifiedSchema[source]¶
Simplified schema mapping.
schema¶
A dictionary containing the mapping to simplified schema types.
Type
Dict
Initializes the schema dictionary based on the predefined list.
Methods
__init__()
Initializes the schema dictionary based on the predefined list.
get_type(type)
Retrieves the simplified schema type for a given original type.
__init__() → None[source]¶
Initializes the schema dictionary based on the predefined list.
Return type
None
get_type(type: str) → str[source]¶
Retrieves the simplified schema type for a given original type.
Parameters
type (str) – The original schema type to find the simplified type for.
Returns
The simplified schema type if it exists;otherwise, returns the original type.
Return type
str
langchain_experimental.graph_transformers.llm.create_unstructured_prompt¶
langchain_experimental.graph_transformers.llm.create_unstructured_prompt(node_labels: Optional[List[str]] = None, rel_types: Optional[List[str]] = None) → ChatPromptTemplate[source]¶
Parameters
node_labels (Optional[List[str]]) – 
rel_types (Optional[List[str]]) – 
Return type
ChatPromptTemplate
langchain_experimental.graph_transformers.llm.LLMGraphTransformer¶
class langchain_experimental.graph_transformers.llm.LLMGraphTransformer(llm: BaseLanguageModel, allowed_nodes: List[str] = [], allowed_relationships: List[str] = [], prompt: Optional[ChatPromptTemplate] = None, strict_mode: bool = True, node_properties: Union[bool, List[str]] = False)[source]¶
Transform documents into graph-based documents using a LLM.
It allows specifying constraints on the types of nodes and relationships to include
in the output graph. The class doesn’t support neither extract and node or
relationship properties
Parameters
llm (BaseLanguageModel) – An instance of a language model supporting structured
output.
allowed_nodes (List[str], optional) – Specifies which node types are
allowed in the graph. Defaults to an empty list, allowing all node types.
allowed_relationships (List[str], optional) – Specifies which relationship types
are allowed in the graph. Defaults to an empty list, allowing all relationship
types.
prompt (Optional[ChatPromptTemplate], optional) – The prompt to pass to
the LLM with additional instructions.
strict_mode (bool, optional) – Determines whether the transformer should apply
filtering to strictly adhere to allowed_nodes and allowed_relationships.
Defaults to True.
node_properties (Union[bool, List[str]]) – 
Example
Methods
__init__(llm[, allowed_nodes, ...])
aconvert_to_graph_documents(documents)
Asynchronously convert a sequence of documents into graph documents.
aprocess_response(document)
Asynchronously processes a single document, transforming it into a graph document.
convert_to_graph_documents(documents)
Convert a sequence of documents into graph documents.
process_response(document)
Processes a single document, transforming it into a graph document using an LLM based on the model's schema and constraints.
__init__(llm: BaseLanguageModel, allowed_nodes: List[str] = [], allowed_relationships: List[str] = [], prompt: Optional[ChatPromptTemplate] = None, strict_mode: bool = True, node_properties: Union[bool, List[str]] = False) → None[source]¶
Parameters
llm (BaseLanguageModel) – 
allowed_nodes (List[str]) – 
allowed_relationships (List[str]) – 
prompt (Optional[ChatPromptTemplate]) – 
strict_mode (bool) – 
node_properties (Union[bool, List[str]]) – 
Return type
None
async aconvert_to_graph_documents(documents: Sequence[Document]) → List[GraphDocument][source]¶
Asynchronously convert a sequence of documents into graph documents.
Parameters
documents (Sequence[Document]) – 
Return type
List[GraphDocument]
async aprocess_response(document: Document) → GraphDocument[source]¶
Asynchronously processes a single document, transforming it into a
graph document.
Parameters
document (Document) – 
Return type
GraphDocument
convert_to_graph_documents(documents: Sequence[Document]) → List[GraphDocument][source]¶
Convert a sequence of documents into graph documents.
Parameters
documents (Sequence[Document]) – The original documents.
**kwargs – Additional keyword arguments.
Returns
The transformed documents as graphs.
Return type
Sequence[GraphDocument]
process_response(document: Document) → GraphDocument[source]¶
Processes a single document, transforming it into a graph document using
an LLM based on the model’s schema and constraints.
Parameters
document (Document) – 
Return type
GraphDocument
Examples using LLMGraphTransformer¶
How to construct knowledge graphs
langchain_experimental.graph_transformers.diffbot.DiffbotGraphTransformer¶
class langchain_experimental.graph_transformers.diffbot.DiffbotGraphTransformer(diffbot_api_key: ~typing.Optional[str] = None, fact_confidence_threshold: float = 0.7, include_qualifiers: bool = True, include_evidence: bool = True, simplified_schema: bool = True, extract_types: ~typing.List[~langchain_experimental.graph_transformers.diffbot.TypeOption] = [<TypeOption.FACTS: 'facts'>], *, include_confidence: bool = False)[source]¶
Transform documents into graph documents using Diffbot NLP API.
A graph document transformation system takes a sequence of Documents and returns a
sequence of Graph Documents.
Example
Initialize the graph transformer with various options.
Parameters
diffbot_api_key (str) – The API key for Diffbot’s NLP services.
fact_confidence_threshold (float) – Minimum confidence level for facts to be included.
include_qualifiers (bool) – Whether to include qualifiers in the relationships.
include_evidence (bool) – Whether to include evidence for the relationships.
simplified_schema (bool) – Whether to use a simplified schema for relationships.
extract_types (List[TypeOption]) – A list of data types to extract. Facts, entities, and
sentiment are supported. By default, the option is
set to facts. A fact represents a combination of
source and target nodes with a relationship type.
include_confidence (bool) – Whether to include confidence scores on nodes and rels
Methods
__init__([diffbot_api_key, ...])
Initialize the graph transformer with various options.
convert_to_graph_documents(documents)
Convert a sequence of documents into graph documents.
nlp_request(text)
Make an API request to the Diffbot NLP endpoint.
process_response(payload, document)
process_response(payload, document)
Transform the Diffbot NLP response into a GraphDocument.
__init__(diffbot_api_key: ~typing.Optional[str] = None, fact_confidence_threshold: float = 0.7, include_qualifiers: bool = True, include_evidence: bool = True, simplified_schema: bool = True, extract_types: ~typing.List[~langchain_experimental.graph_transformers.diffbot.TypeOption] = [<TypeOption.FACTS: 'facts'>], *, include_confidence: bool = False) → None[source]¶
Initialize the graph transformer with various options.
Parameters
diffbot_api_key (str) – The API key for Diffbot’s NLP services.
fact_confidence_threshold (float) – Minimum confidence level for facts to be included.
include_qualifiers (bool) – Whether to include qualifiers in the relationships.
include_evidence (bool) – Whether to include evidence for the relationships.
simplified_schema (bool) – Whether to use a simplified schema for relationships.
extract_types (List[TypeOption]) – A list of data types to extract. Facts, entities, and
sentiment are supported. By default, the option is
set to facts. A fact represents a combination of
source and target nodes with a relationship type.
include_confidence (bool) – Whether to include confidence scores on nodes and rels
Return type
None
convert_to_graph_documents(documents: Sequence[Document]) → List[GraphDocument][source]¶
Convert a sequence of documents into graph documents.
Parameters
documents (Sequence[Document]) – The original documents.
**kwargs – Additional keyword arguments.
Returns
The transformed documents as graphs.
Return type
Sequence[GraphDocument]
nlp_request(text: str) → Dict[str, Any][source]¶
Make an API request to the Diffbot NLP endpoint.
Parameters
Make an API request to the Diffbot NLP endpoint.
Parameters
text (str) – The text to be processed.
Returns
The JSON response from the API.
Return type
Dict[str, Any]
process_response(payload: Dict[str, Any], document: Document) → GraphDocument[source]¶
Transform the Diffbot NLP response into a GraphDocument.
Parameters
payload (Dict[str, Any]) – The JSON response from Diffbot’s NLP API.
document (Document) – The original document.
Returns
The transformed document as a graph.
Return type
GraphDocument
Examples using DiffbotGraphTransformer¶
Diffbot
Neo4j
langchain_experimental.graph_transformers.llm.UnstructuredRelation¶
class langchain_experimental.graph_transformers.llm.UnstructuredRelation[source]¶
Bases: BaseModel
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 head: str [Required]¶
extracted head entity like Microsoft, Apple, John. Must use human-readable unique identifier.
param head_type: str [Required]¶
type of the extracted head entity like Person, Company, etc
param relation: str [Required]¶
relation between the head and the tail entities
param tail: str [Required]¶
extracted tail entity like Microsoft, Apple, John. Must use human-readable unique identifier.
param tail_type: str [Required]¶
type of the extracted tail entity like Person, Company, etc
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
langchain_experimental.graph_transformers.llm.create_simple_model¶
langchain_experimental.graph_transformers.llm.create_simple_model(node_labels: Optional[List[str]] = None, rel_types: Optional[List[str]] = None, node_properties: Union[bool, List[str]] = False, llm_type: Optional[str] = None) → Type[_Graph][source]¶
Simple model allows to limit node and/or relationship types.
Doesn’t have any node or relationship properties.
Parameters
node_labels (Optional[List[str]]) – 
rel_types (Optional[List[str]]) – 
node_properties (Union[bool, List[str]]) – 
llm_type (Optional[str]) – 
Return type
Type[_Graph]
langchain_experimental.graph_transformers.llm.optional_enum_field¶
langchain_experimental.graph_transformers.llm.optional_enum_field(enum_values: Optional[List[str]] = None, description: str = '', input_type: str = 'node', llm_type: Optional[str] = None, **field_kwargs: Any) → Any[source]¶
Utility function to conditionally create a field with an enum constraint.
Parameters
enum_values (Optional[List[str]]) – 
description (str) – 
input_type (str) – 
llm_type (Optional[str]) – 
field_kwargs (Any) – 
Return type
Any
langchain_core.stores.InMemoryBaseStore¶
class langchain_core.stores.InMemoryBaseStore[source]¶
In-memory implementation of the BaseStore using a dictionary.
Initialize an empty store.
Methods
__init__()
Initialize an empty store.
amdelete(keys)
Delete the given keys and their associated values.
amget(keys)
Get the values associated with the given keys.
amset(key_value_pairs)
Set the values for the given keys.
ayield_keys([prefix])
Get an async iterator over keys that match the given prefix.
mdelete(keys)
Delete the given keys and their associated values.
mget(keys)
Get the values associated with the given keys.
mset(key_value_pairs)
Set the values for the given keys.
yield_keys([prefix])
Get an iterator over keys that match the given prefix.
__init__() → None[source]¶
Initialize an empty store.
Return type
None
async amdelete(keys: Sequence[str]) → None[source]¶
Delete the given keys and their associated values.
Parameters
keys (Sequence[str]) – A sequence of keys to delete.
Return type
None
async amget(keys: Sequence[str]) → List[Optional[V]][source]¶
Get the values associated with the given keys.
Parameters
keys (Sequence[str]) – A sequence of keys.
Returns
A sequence of optional values associated with the keys.
If a key is not found, the corresponding value will be None.
Return type
List[Optional[V]]
async amset(key_value_pairs: Sequence[Tuple[str, V]]) → None[source]¶
Set the values for the given keys.
Parameters
key_value_pairs (Sequence[Tuple[str, V]]) – A sequence of key-value pairs.
Returns
None
Return type
None
Returns
None
Return type
None
async ayield_keys(prefix: Optional[str] = None) → AsyncIterator[str][source]¶
Get an async iterator over keys that match the given prefix.
Parameters
prefix (str, optional) – The prefix to match. Defaults to None.
Returns
An async iterator over keys that match the given prefix.
Return type
AsyncIterator[str]
mdelete(keys: Sequence[str]) → None[source]¶
Delete the given keys and their associated values.
Parameters
keys (Sequence[str]) – A sequence of keys to delete.
Return type
None
mget(keys: Sequence[str]) → List[Optional[V]][source]¶
Get the values associated with the given keys.
Parameters
keys (Sequence[str]) – A sequence of keys.
Returns
A sequence of optional values associated with the keys.
If a key is not found, the corresponding value will be None.
Return type
List[Optional[V]]
mset(key_value_pairs: Sequence[Tuple[str, V]]) → None[source]¶
Set the values for the given keys.
Parameters
key_value_pairs (Sequence[Tuple[str, V]]) – A sequence of key-value pairs.
Returns
None
Return type
None
yield_keys(prefix: Optional[str] = None) → Iterator[str][source]¶
Get an iterator over keys that match the given prefix.
Parameters
prefix (str, optional) – The prefix to match. Defaults to None.
Returns
An iterator over keys that match the given prefix.
Return type
Iterator[str]
langchain_core.stores.BaseStore¶
class langchain_core.stores.BaseStore[source]¶
Abstract interface for a key-value store.
Methods
__init__()
amdelete(keys)
Delete the given keys and their associated values.
amget(keys)
Get the values associated with the given keys.
amset(key_value_pairs)
Set the values for the given keys.
ayield_keys(*[, prefix])
Get an iterator over keys that match the given prefix.
mdelete(keys)
Delete the given keys and their associated values.
mget(keys)
Get the values associated with the given keys.
mset(key_value_pairs)
Set the values for the given keys.
yield_keys(*[, prefix])
Get an iterator over keys that match the given prefix.
__init__()¶
async amdelete(keys: Sequence[K]) → None[source]¶
Delete the given keys and their associated values.
Parameters
keys (Sequence[K]) – A sequence of keys to delete.
Return type
None
async amget(keys: Sequence[K]) → List[Optional[V]][source]¶
Get the values associated with the given keys.
Parameters
keys (Sequence[K]) – A sequence of keys.
Returns
A sequence of optional values associated with the keys.
If a key is not found, the corresponding value will be None.
Return type
List[Optional[V]]
async amset(key_value_pairs: Sequence[Tuple[K, V]]) → None[source]¶
Set the values for the given keys.
Parameters
key_value_pairs (Sequence[Tuple[K, V]]) – A sequence of key-value pairs.
Return type
None
async ayield_keys(*, prefix: Optional[str] = None) → Union[AsyncIterator[K], AsyncIterator[str]][source]¶
Get an iterator over keys that match the given prefix.
Parameters
Get an iterator over keys that match the given prefix.
Parameters
prefix (str) – The prefix to match.
Returns
An iterator over keys that match the given prefix.
This method is allowed to return an iterator over either K or str
depending on what makes more sense for the given store.
Return type
Iterator[K | str]
abstract mdelete(keys: Sequence[K]) → None[source]¶
Delete the given keys and their associated values.
Parameters
keys (Sequence[K]) – A sequence of keys to delete.
Return type
None
abstract mget(keys: Sequence[K]) → List[Optional[V]][source]¶
Get the values associated with the given keys.
Parameters
keys (Sequence[K]) – A sequence of keys.
Returns
A sequence of optional values associated with the keys.
If a key is not found, the corresponding value will be None.
Return type
List[Optional[V]]
abstract mset(key_value_pairs: Sequence[Tuple[K, V]]) → None[source]¶
Set the values for the given keys.
Parameters
key_value_pairs (Sequence[Tuple[K, V]]) – A sequence of key-value pairs.
Return type
None
abstract yield_keys(*, prefix: Optional[str] = None) → Union[Iterator[K], Iterator[str]][source]¶
Get an iterator over keys that match the given prefix.
Parameters
prefix (str) – The prefix to match.
Returns
An iterator over keys that match the given prefix.
This method is allowed to return an iterator over either K or str
depending on what makes more sense for the given store.
Return type
Iterator[K | str]
Examples using BaseStore¶
Fleet AI Context
langchain_core.stores.InMemoryByteStore¶
class langchain_core.stores.InMemoryByteStore[source]¶
In-memory store for bytes.
store¶
The underlying dictionary that stores
the key-value pairs.
Type
Dict[str, bytes]
Examples
from langchain.storage import InMemoryByteStore
store = InMemoryByteStore()
store.mset([('key1', b'value1'), ('key2', b'value2')])
store.mget(['key1', 'key2'])
# [b'value1', b'value2']
store.mdelete(['key1'])
list(store.yield_keys())
# ['key2']
list(store.yield_keys(prefix='k'))
# ['key2']
Initialize an empty store.
Methods
__init__()
Initialize an empty store.
amdelete(keys)
Delete the given keys and their associated values.
amget(keys)
Get the values associated with the given keys.
amset(key_value_pairs)
Set the values for the given keys.
ayield_keys([prefix])
Get an async iterator over keys that match the given prefix.
mdelete(keys)
Delete the given keys and their associated values.
mget(keys)
Get the values associated with the given keys.
mset(key_value_pairs)
Set the values for the given keys.
yield_keys([prefix])
Get an iterator over keys that match the given prefix.
__init__() → None¶
Initialize an empty store.
Return type
None
async amdelete(keys: Sequence[str]) → None¶
Delete the given keys and their associated values.
Parameters
keys (Sequence[str]) – A sequence of keys to delete.
Return type
None
async amget(keys: Sequence[str]) → List[Optional[V]]¶
Get the values associated with the given keys.
Parameters
Get the values associated with the given keys.
Parameters
keys (Sequence[str]) – A sequence of keys.
Returns
A sequence of optional values associated with the keys.
If a key is not found, the corresponding value will be None.
Return type
List[Optional[V]]
async amset(key_value_pairs: Sequence[Tuple[str, V]]) → None¶
Set the values for the given keys.
Parameters
key_value_pairs (Sequence[Tuple[str, V]]) – A sequence of key-value pairs.
Returns
None
Return type
None
async ayield_keys(prefix: Optional[str] = None) → AsyncIterator[str]¶
Get an async iterator over keys that match the given prefix.
Parameters
prefix (str, optional) – The prefix to match. Defaults to None.
Returns
An async iterator over keys that match the given prefix.
Return type
AsyncIterator[str]
mdelete(keys: Sequence[str]) → None¶
Delete the given keys and their associated values.
Parameters
keys (Sequence[str]) – A sequence of keys to delete.
Return type
None
mget(keys: Sequence[str]) → List[Optional[V]]¶
Get the values associated with the given keys.
Parameters
keys (Sequence[str]) – A sequence of keys.
Returns
A sequence of optional values associated with the keys.
If a key is not found, the corresponding value will be None.
Return type
List[Optional[V]]
mset(key_value_pairs: Sequence[Tuple[str, V]]) → None¶
Set the values for the given keys.
Parameters
key_value_pairs (Sequence[Tuple[str, V]]) – A sequence of key-value pairs.
Returns
None
Return type
None
yield_keys(prefix: Optional[str] = None) → Iterator[str]¶
Get an iterator over keys that match the given prefix.
Parameters
langchain_core.stores.InMemoryStore¶
class langchain_core.stores.InMemoryStore[source]¶
In-memory store for any type of data.
store¶
The underlying dictionary that stores
the key-value pairs.
Type
Dict[str, Any]
Examples
from langchain.storage import InMemoryStore
store = InMemoryStore()
store.mset([('key1', 'value1'), ('key2', 'value2')])
store.mget(['key1', 'key2'])
# ['value1', 'value2']
store.mdelete(['key1'])
list(store.yield_keys())
# ['key2']
list(store.yield_keys(prefix='k'))
# ['key2']
Initialize an empty store.
Methods
__init__()
Initialize an empty store.
amdelete(keys)
Delete the given keys and their associated values.
amget(keys)
Get the values associated with the given keys.
amset(key_value_pairs)
Set the values for the given keys.
ayield_keys([prefix])
Get an async iterator over keys that match the given prefix.
mdelete(keys)
Delete the given keys and their associated values.
mget(keys)
Get the values associated with the given keys.
mset(key_value_pairs)
Set the values for the given keys.
yield_keys([prefix])
Get an iterator over keys that match the given prefix.
__init__() → None¶
Initialize an empty store.
Return type
None
async amdelete(keys: Sequence[str]) → None¶
Delete the given keys and their associated values.
Parameters
keys (Sequence[str]) – A sequence of keys to delete.
Return type
None
async amget(keys: Sequence[str]) → List[Optional[V]]¶
Get the values associated with the given keys.
Parameters