Tony20100/langchain_full huggingface dataset:
langchain_aws.graphs.neptune_rdf_graph.NeptuneRdfGraph¶
class langchain_aws.graphs.neptune_rdf_graph.NeptuneRdfGraph(host: str, port: int = 8182, use_https: bool = True, use_iam_auth: bool = False, client: Optional[Any] = None, credentials_profile_name: Optional[str] = None, region_name: Optional[str] = None, service: str = 'neptunedata', sign: bool = True)[source]¶
Neptune wrapper for RDF graph operations.
Parameters
host (str) – endpoint for the database instance
port (int) – port number for the database instance, default is 8182
use_iam_auth (bool) – boolean indicating IAM auth is enabled in Neptune cluster
use_https (bool) – whether to use secure connection, default is True
client (Any) – optional boto3 Neptune client
credentials_profile_name (Optional[str]) – optional AWS profile name
region_name (Optional[str]) – optional AWS region, e.g., us-west-2
service (str) – optional service name, default is neptunedata
sign (bool) – optional, whether to sign the request payload, default is True
Example
graph = NeptuneRdfGraph(host=’<SPARQL host’>,
port=<SPARQL port>
)
schema = graph.get_schema()
OR
graph = NeptuneRdfGraph(
host=’<SPARQL host’>,
port=<SPARQL port>
)
schema_elem = graph.get_schema_elements()
#… change schema_elements …
graph.load_schema(schema_elem)
Security note: Make sure that the database connection uses credentialsthat are narrowly-scoped to only include necessary permissions.
Failure to do so may result in data corruption or loss, since the calling
langchain_community.graphs.age_graph.AGEGraph¶
class langchain_community.graphs.age_graph.AGEGraph(graph_name: str, conf: Dict[str, Any], create: bool = True)[source]¶
Apache AGE wrapper for graph operations.
Parameters
graph_name (str) – the name of the graph to connect to or create
conf (Dict[str, Any]) – the pgsql connection config passed directly
to psycopg2.connect
create (bool) – if True and graph doesn’t exist, attempt to create it
Security note: Make sure that the database connection uses credentialsthat are narrowly-scoped to only include necessary permissions.
Failure to do so may result in data corruption or loss, since the calling
code may attempt commands that would result in deletion, mutation
of data if appropriately prompted or reading sensitive data if such
data is present in the database.
The best way to guard against such negative outcomes is to (as appropriate)
limit the permissions granted to the credentials used with this tool.
See https://python.langchain.com/docs/security for more information.
Create a new AGEGraph instance.
Attributes
get_schema
Returns the schema of the Graph
get_structured_schema
Returns the structured schema of the Graph
label_regex
types
Methods
__init__(graph_name, conf[, create])
Create a new AGEGraph instance.
add_graph_documents(graph_documents[, ...])
insert a list of graph documents into the graph
clean_graph_labels(label)
remove any disallowed characters from a label and replace with '_'
query(query[, params])
Query the graph by taking a cypher query, converting it to an age compatible query, executing it and converting the result
refresh_schema()
Refresh the graph schema information by updating the available labels, relationships, and properties
refresh_schema()
Refresh the graph schema information by updating the available labels, relationships, and properties
__init__(graph_name: str, conf: Dict[str, Any], create: bool = True) → None[source]¶
Create a new AGEGraph instance.
Parameters
graph_name (str) – 
conf (Dict[str, Any]) – 
create (bool) – 
Return type
None
add_graph_documents(graph_documents: List[GraphDocument], include_source: bool = False) → None[source]¶
insert a list of graph documents into the graph
Parameters
graph_documents (List[GraphDocument]) – the list of documents to be inserted
include_source (bool) – if True add nodes for the sources
with MENTIONS edges to the entities they mention
Returns
None
Return type
None
static clean_graph_labels(label: str) → str[source]¶
remove any disallowed characters from a label and replace with ‘_’
Parameters
label (str) – the original label
Returns
the sanitized version of the label
Return type
str
query(query: str, params: dict = {}) → List[Dict[str, Any]][source]¶
Query the graph by taking a cypher query, converting it to an
age compatible query, executing it and converting the result
Parameters
query (str) – a cypher query to be executed
params (dict) – parameters for the query (not used in this implementation)
Returns
a list of dictionaries containing the result set
Return type
List[Dict[str, Any]]
refresh_schema() → None[source]¶
Refresh the graph schema information by updating the available
labels, relationships, and properties
Return type
None
Examples using AGEGraph¶
Apache AGE
langchain_community.graphs.arangodb_graph.get_arangodb_client¶
langchain_community.graphs.arangodb_graph.get_arangodb_client(url: Optional[str] = None, dbname: Optional[str] = None, username: Optional[str] = None, password: Optional[str] = None) → Any[source]¶
Get the Arango DB client from credentials.
Parameters
url (Optional[str]) – Arango DB url. Can be passed in as named arg or set as environment
var ARANGODB_URL. Defaults to “http://localhost:8529”.
dbname (Optional[str]) – Arango DB name. Can be passed in as named arg or set as
environment var ARANGODB_DBNAME. Defaults to “_system”.
username (Optional[str]) – Can be passed in as named arg or set as environment var
ARANGODB_USERNAME. Defaults to “root”.
password (Optional[str]) – Can be passed ni as named arg or set as environment var
ARANGODB_PASSWORD. Defaults to “”.
Returns
An arango.database.StandardDatabase.
Return type
Any
langchain_community.graphs.rdf_graph.RdfGraph¶
class langchain_community.graphs.rdf_graph.RdfGraph(source_file: Optional[str] = None, serialization: Optional[str] = 'ttl', query_endpoint: Optional[str] = None, update_endpoint: Optional[str] = None, standard: Optional[str] = 'rdf', local_copy: Optional[str] = None, graph_kwargs: Optional[Dict] = None, store_kwargs: Optional[Dict] = None)[source]¶
RDFlib wrapper for graph operations.
Modes:
* local: Local file - can be queried and changed
* online: Online file - can only be queried, changes can be stored locally
* store: Triple store - can be queried and changed if update_endpoint available
Together with a source file, the serialization should be specified.
Security note: Make sure that the database connection uses credentialsthat are narrowly-scoped to only include necessary permissions.
Failure to do so may result in data corruption or loss, since the calling
code may attempt commands that would result in deletion, mutation
of data if appropriately prompted or reading sensitive data if such
data is present in the database.
The best way to guard against such negative outcomes is to (as appropriate)
limit the permissions granted to the credentials used with this tool.
See https://python.langchain.com/docs/security for more information.
Set up the RDFlib graph
Parameters
source_file (Optional[str]) – either a path for a local file or a URL
serialization (Optional[str]) – serialization of the input
query_endpoint (Optional[str]) – SPARQL endpoint for queries, read access
update_endpoint (Optional[str]) – SPARQL endpoint for UPDATE queries, write access
standard (Optional[str]) – RDF, RDFS, or OWL
local_copy (Optional[str]) – new local copy for storing changes
local_copy (Optional[str]) – new local copy for storing changes
graph_kwargs (Optional[Dict]) – Additional rdflib.Graph specific kwargs
store_kwargs (Optional[Dict]) – 
that will be used to initialize it,
if query_endpoint is provided.
:param store_kwargs: Additional sparqlstore.SPARQLStore specific kwargs
that will be used to initialize it,
if query_endpoint is provided.
Attributes
get_schema
Returns the schema of the graph database.
Methods
__init__([source_file, serialization, ...])
Set up the RDFlib graph
load_schema()
Load the graph schema information.
query(query)
Query the graph.
update(query)
Update the graph.
__init__(source_file: Optional[str] = None, serialization: Optional[str] = 'ttl', query_endpoint: Optional[str] = None, update_endpoint: Optional[str] = None, standard: Optional[str] = 'rdf', local_copy: Optional[str] = None, graph_kwargs: Optional[Dict] = None, store_kwargs: Optional[Dict] = None) → None[source]¶
Set up the RDFlib graph
Parameters
source_file (Optional[str]) – either a path for a local file or a URL
serialization (Optional[str]) – serialization of the input
query_endpoint (Optional[str]) – SPARQL endpoint for queries, read access
update_endpoint (Optional[str]) – SPARQL endpoint for UPDATE queries, write access
standard (Optional[str]) – RDF, RDFS, or OWL
local_copy (Optional[str]) – new local copy for storing changes
graph_kwargs (Optional[Dict]) – Additional rdflib.Graph specific kwargs
store_kwargs (Optional[Dict]) – 
Return type
None
that will be used to initialize it,
if query_endpoint is provided.
:param store_kwargs: Additional sparqlstore.SPARQLStore specific kwargs
:param store_kwargs: Additional sparqlstore.SPARQLStore specific kwargs
that will be used to initialize it,
if query_endpoint is provided.
load_schema() → None[source]¶
Load the graph schema information.
Return type
None
query(query: str) → List[rdflib.query.ResultRow][source]¶
Query the graph.
Parameters
query (str) – 
Return type
List[rdflib.query.ResultRow]
update(query: str) → None[source]¶
Update the graph.
Parameters
query (str) – 
Return type
None
Examples using RdfGraph¶
RDFLib
langchain_community.graphs.nebula_graph.NebulaGraph¶
class langchain_community.graphs.nebula_graph.NebulaGraph(space: str, username: str = 'root', password: str = 'nebula', address: str = '127.0.0.1', port: int = 9669, session_pool_size: int = 30)[source]¶
NebulaGraph wrapper for graph operations.
NebulaGraph inherits methods from Neo4jGraph to bring ease to the user space.
Security note: Make sure that the database connection uses credentialsthat are narrowly-scoped to only include necessary permissions.
Failure to do so may result in data corruption or loss, since the calling
code may attempt commands that would result in deletion, mutation
of data if appropriately prompted or reading sensitive data if such
data is present in the database.
The best way to guard against such negative outcomes is to (as appropriate)
limit the permissions granted to the credentials used with this tool.
See https://python.langchain.com/docs/security for more information.
Create a new NebulaGraph wrapper instance.
Attributes
get_schema
Returns the schema of the NebulaGraph database
Methods
__init__(space[, username, password, ...])
Create a new NebulaGraph wrapper instance.
execute(query[, params, retry])
Query NebulaGraph database.
query(query[, retry])
refresh_schema()
Refreshes the NebulaGraph schema information.
Parameters
space (str) – 
username (str) – 
password (str) – 
address (str) – 
port (int) – 
session_pool_size (int) –
port (int) – 
session_pool_size (int) – 
__init__(space: str, username: str = 'root', password: str = 'nebula', address: str = '127.0.0.1', port: int = 9669, session_pool_size: int = 30) → None[source]¶
Create a new NebulaGraph wrapper instance.
Parameters
space (str) – 
username (str) – 
password (str) – 
address (str) – 
port (int) – 
session_pool_size (int) – 
Return type
None
execute(query: str, params: Optional[dict] = None, retry: int = 0) → Any[source]¶
Query NebulaGraph database.
Parameters
query (str) – 
params (Optional[dict]) – 
retry (int) – 
Return type
Any
query(query: str, retry: int = 0) → Dict[str, Any][source]¶
Parameters
query (str) – 
retry (int) – 
Return type
Dict[str, Any]
refresh_schema() → None[source]¶
Refreshes the NebulaGraph schema information.
Return type
None
Examples using NebulaGraph¶
NebulaGraph
langchain_community.graphs.gremlin_graph.GremlinGraph¶
class langchain_community.graphs.gremlin_graph.GremlinGraph(url: Optional[str] = None, username: Optional[str] = None, password: Optional[str] = None, traversal_source: str = 'g', message_serializer: Optional[Any] = None)[source]¶
Gremlin wrapper for graph operations.
Parameters:
url (Optional[str]): The URL of the Gremlin database server or env GREMLIN_URI
username (Optional[str]): The collection-identifier like ‘/dbs/database/colls/graph’
or env GREMLIN_USERNAME if none provided
password (Optional[str]): The connection-key for database authenticationor env GREMLIN_PASSWORD if none provided
traversal_source (str): The traversal source to use for queries. Defaults to ‘g’.
message_serializer (Optional[Any]): The message serializer to use for requests.
Defaults to serializer.GraphSONSerializersV2d0()
Security note: Make sure that the database connection uses credentialsthat are narrowly-scoped to only include necessary permissions.
Failure to do so may result in data corruption or loss, since the calling
code may attempt commands that would result in deletion, mutation
of data if appropriately prompted or reading sensitive data if such
data is present in the database.
The best way to guard against such negative outcomes is to (as appropriate)
limit the permissions granted to the credentials used with this tool.
See https://python.langchain.com/docs/security for more information.
Implementation details:The Gremlin queries are designed to work with Azure CosmosDB limitations
Create a new Gremlin graph wrapper instance.
Attributes
get_schema
Returns the schema of the Gremlin database
get_structured_schema
Return the schema of the Graph database
Methods
__init__([url, username, password, ...])
Create a new Gremlin graph wrapper instance.
Create a new Gremlin graph wrapper instance.
add_edge(relationship)
add_graph_documents(graph_documents[, ...])
Take GraphDocument as input as uses it to construct a graph.
add_node(node[, node_cache])
build_edge_query(relationship)
build_vertex_query(node)
query(query[, params])
Query the graph.
refresh_schema()
Refreshes the Gremlin graph schema information.
Parameters
url (Optional[str]) – 
username (Optional[str]) – 
password (Optional[str]) – 
traversal_source (str) – 
message_serializer (Optional[Any]) – 
__init__(url: Optional[str] = None, username: Optional[str] = None, password: Optional[str] = None, traversal_source: str = 'g', message_serializer: Optional[Any] = None) → None[source]¶
Create a new Gremlin graph wrapper instance.
Parameters
url (Optional[str]) – 
username (Optional[str]) – 
password (Optional[str]) – 
traversal_source (str) – 
message_serializer (Optional[Any]) – 
Return type
None
add_edge(relationship: Relationship) → Any[source]¶
Parameters
relationship (Relationship) – 
Return type
Any
add_graph_documents(graph_documents: List[GraphDocument], include_source: bool = False) → None[source]¶
Take GraphDocument as input as uses it to construct a graph.
Parameters
graph_documents (List[GraphDocument]) – 
include_source (bool) – 
Return type
None
add_node(node: Node, node_cache: dict = {}) → Node[source]¶
Parameters
node (Node) – 
node_cache (dict) – 
Return type
Node
build_edge_query(relationship: Relationship) → str[source]¶
Parameters
relationship (Relationship) – 
Return type
str
Parameters
relationship (Relationship) – 
Return type
str
build_vertex_query(node: Node) → str[source]¶
Parameters
node (Node) – 
Return type
str
query(query: str, params: dict = {}) → List[Dict[str, Any]][source]¶
Query the graph.
Parameters
query (str) – 
params (dict) – 
Return type
List[Dict[str, Any]]
refresh_schema() → None[source]¶
Refreshes the Gremlin graph schema information.
Return type
None
Examples using GremlinGraph¶
Azure Cosmos DB for Apache Gremlin
Microsoft
langchain_community.graphs.neptune_graph.NeptuneAnalyticsGraph¶
class langchain_community.graphs.neptune_graph.NeptuneAnalyticsGraph(graph_identifier: str, client: Optional[Any] = None, credentials_profile_name: Optional[str] = None, region_name: Optional[str] = None)[source]¶
Neptune Analytics wrapper for graph operations.
Parameters
client (Any) – optional boto3 Neptune client
credentials_profile_name (Optional[str]) – optional AWS profile name
region_name (Optional[str]) – optional AWS region, e.g., us-west-2
graph_identifier (str) – the graph identifier for a Neptune Analytics graph
Example
graph = NeptuneAnalyticsGraph(graph_identifier=’<my-graph-id>’
)
Security note: Make sure that the database connection uses credentialsthat are narrowly-scoped to only include necessary permissions.
Failure to do so may result in data corruption or loss, since the calling
code may attempt commands that would result in deletion, mutation
of data if appropriately prompted or reading sensitive data if such
data is present in the database.
The best way to guard against such negative outcomes is to (as appropriate)
limit the permissions granted to the credentials used with this tool.
See https://python.langchain.com/docs/security for more information.
Create a new Neptune Analytics graph wrapper instance.
Attributes
get_schema
Return the schema of the Neptune database
Methods
__init__(graph_identifier[, client, ...])
Create a new Neptune Analytics graph wrapper instance.
query(query[, params])
Query Neptune database.
__init__(graph_identifier: str, client: Optional[Any] = None, credentials_profile_name: Optional[str] = None, region_name: Optional[str] = None) → None[source]¶
Create a new Neptune Analytics graph wrapper instance.
Parameters
graph_identifier (str) – 
client (Optional[Any]) –
Parameters
graph_identifier (str) – 
client (Optional[Any]) – 
credentials_profile_name (Optional[str]) – 
region_name (Optional[str]) – 
Return type
None
query(query: str, params: dict = {}) → Dict[str, Any][source]¶
Query Neptune database.
Parameters
query (str) – 
params (dict) – 
Return type
Dict[str, Any]
Examples using NeptuneAnalyticsGraph¶
AWS
Amazon Neptune with Cypher
langchain_community.graphs.networkx_graph.NetworkxEntityGraph¶
class langchain_community.graphs.networkx_graph.NetworkxEntityGraph(graph: Optional[Any] = None)[source]¶
Networkx wrapper for entity graph operations.
Security note: Make sure that the database connection uses credentialsthat are narrowly-scoped to only include necessary permissions.
Failure to do so may result in data corruption or loss, since the calling
code may attempt commands that would result in deletion, mutation
of data if appropriately prompted or reading sensitive data if such
data is present in the database.
The best way to guard against such negative outcomes is to (as appropriate)
limit the permissions granted to the credentials used with this tool.
See https://python.langchain.com/docs/security for more information.
Create a new graph.
Methods
__init__([graph])
Create a new graph.
add_node(node)
Add node in the graph.
add_triple(knowledge_triple)
Add a triple to the graph.
clear()
Clear the graph.
clear_edges()
Clear the graph edges.
delete_triple(knowledge_triple)
Delete a triple from the graph.
draw_graphviz(**kwargs)
Provides better drawing
from_gml(gml_path)
get_entity_knowledge(entity[, depth])
Get information about an entity.
get_neighbors(node)
Return the neighbor nodes of the given node.
get_number_of_nodes()
Get number of nodes in the graph.
get_topological_sort()
Get a list of entity names in the graph sorted by causal dependence.
get_triples()
Get all triples in the graph.
has_edge(source_node, destination_node)
Return if graph has an edge between the given nodes.
has_node(node)
Return if graph has the given node.
remove_edge(source_node, destination_node)
Remove edge from the graph.
remove_edge(source_node, destination_node)
Remove edge from the graph.
remove_node(node)
Remove node from the graph.
write_to_gml(path)
Parameters
graph (Optional[Any]) – 
__init__(graph: Optional[Any] = None) → None[source]¶
Create a new graph.
Parameters
graph (Optional[Any]) – 
Return type
None
add_node(node: str) → None[source]¶
Add node in the graph.
Parameters
node (str) – 
Return type
None
add_triple(knowledge_triple: KnowledgeTriple) → None[source]¶
Add a triple to the graph.
Parameters
knowledge_triple (KnowledgeTriple) – 
Return type
None
clear() → None[source]¶
Clear the graph.
Return type
None
clear_edges() → None[source]¶
Clear the graph edges.
Return type
None
delete_triple(knowledge_triple: KnowledgeTriple) → None[source]¶
Delete a triple from the graph.
Parameters
knowledge_triple (KnowledgeTriple) – 
Return type
None
draw_graphviz(**kwargs: Any) → None[source]¶
Provides better drawing
Usage in a jupyter notebook:
>>> from IPython.display import SVG
>>> self.draw_graphviz_svg(layout="dot", filename="web.svg")
>>> SVG('web.svg')
Parameters
kwargs (Any) – 
Return type
None
classmethod from_gml(gml_path: str) → NetworkxEntityGraph[source]¶
Parameters
gml_path (str) – 
Return type
NetworkxEntityGraph
get_entity_knowledge(entity: str, depth: int = 1) → List[str][source]¶
Get information about an entity.
Parameters
entity (str) – 
depth (int) – 
Return type
Parameters
entity (str) – 
depth (int) – 
Return type
List[str]
get_neighbors(node: str) → List[str][source]¶
Return the neighbor nodes of the given node.
Parameters
node (str) – 
Return type
List[str]
get_number_of_nodes() → int[source]¶
Get number of nodes in the graph.
Return type
int
get_topological_sort() → List[str][source]¶
Get a list of entity names in the graph sorted by causal dependence.
Return type
List[str]
get_triples() → List[Tuple[str, str, str]][source]¶
Get all triples in the graph.
Return type
List[Tuple[str, str, str]]
has_edge(source_node: str, destination_node: str) → bool[source]¶
Return if graph has an edge between the given nodes.
Parameters
source_node (str) – 
destination_node (str) – 
Return type
bool
has_node(node: str) → bool[source]¶
Return if graph has the given node.
Parameters
node (str) – 
Return type
bool
remove_edge(source_node: str, destination_node: str) → None[source]¶
Remove edge from the graph.
Parameters
source_node (str) – 
destination_node (str) – 
Return type
None
remove_node(node: str) → None[source]¶
Remove node from the graph.
Parameters
node (str) – 
Return type
None
write_to_gml(path: str) → None[source]¶
Parameters
path (str) – 
Return type
None
Examples using NetworkxEntityGraph¶
NetworkX
langchain_community.graphs.graph_document.GraphDocument¶
class langchain_community.graphs.graph_document.GraphDocument[source]¶
Bases: Serializable
Represents a graph document consisting of nodes and relationships.
nodes¶
A list of nodes in the graph.
Type
List[Node]
relationships¶
A list of relationships in the graph.
Type
List[Relationship]
source¶
The document from which the graph information is derived.
Type
Document
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 nodes: List[Node] [Required]¶
param relationships: List[Relationship] [Required]¶
param source: Document [Required]¶
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
exclude (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) – fields to exclude from new model, as with values this takes precedence over include