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 authentication

or 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 credentials

that 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.

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

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¶