viruPVS/langchain-docs huggingface dataset:
query(query[, params])
Query Neptune database.
__init__(host: str, port: int = 8182, use_https: bool = True, client: Any = None, credentials_profile_name: Optional[str] = None, region_name: Optional[str] = None, service: str = 'neptunedata', sign: bool = True) → None[source]¶
Create a new Neptune graph wrapper instance.
query(query: str, params: dict = {}) → Dict[str, Any][source]¶
Query Neptune database.
Examples using NeptuneGraph¶
Neptune Open Cypher QA Chain
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_triple(knowledge_triple)
Add a triple to the graph.
clear()
Clear the graph.
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_topological_sort()
Get a list of entity names in the graph sorted by causal dependence.
get_triples()
Get all triples in the graph.
write_to_gml(path)
__init__(graph: Optional[Any] = None) → None[source]¶
Create a new graph.
add_triple(knowledge_triple: KnowledgeTriple) → None[source]¶
Add a triple to the graph.
clear() → None[source]¶
Clear the graph.
delete_triple(knowledge_triple: KnowledgeTriple) → None[source]¶
Delete a triple from the graph.
Delete a triple from the graph.
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')
classmethod from_gml(gml_path: str) → NetworkxEntityGraph[source]¶
get_entity_knowledge(entity: str, depth: int = 1) → List[str][source]¶
Get information about an entity.
get_topological_sort() → List[str][source]¶
Get a list of entity names in the graph sorted by causal dependence.
get_triples() → List[Tuple[str, str, str]][source]¶
Get all triples in the graph.
write_to_gml(path: str) → None[source]¶
Examples using NetworkxEntityGraph¶
Graph QA
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)[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 – either a path for a local file or a URL
serialization – serialization of the input
query_endpoint – SPARQL endpoint for queries, read access
update_endpoint – SPARQL endpoint for UPDATE queries, write access
standard – RDF, RDFS, or OWL
local_copy – new local copy for storing changes
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.
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) → None[source]¶
Set up the RDFlib graph
Parameters
source_file – either a path for a local file or a URL
serialization – serialization of the input
query_endpoint – SPARQL endpoint for queries, read access
update_endpoint – SPARQL endpoint for UPDATE queries, write access
standard – RDF, RDFS, or OWL
local_copy – new local copy for storing changes
load_schema() → None[source]¶
Load the graph schema information.
query(query: str) → List[rdflib.query.ResultRow][source]¶
Query the graph.
update(query: str) → None[source]¶
Update the graph.
Examples using RdfGraph¶
GraphSparqlQAChain
langchain_community.graphs.graph_store.GraphStore¶
class langchain_community.graphs.graph_store.GraphStore[source]¶
An abstract class wrapper for graph operations.
Attributes
get_schema
Returns the schema of the Graph database
get_structured_schema
Returns the schema of the Graph database
Methods
__init__()
add_graph_documents(graph_documents[, ...])
Take GraphDocument as input as uses it to construct a graph.
query(query[, params])
Query the graph.
refresh_schema()
Refreshes the graph schema information.
__init__()¶
abstract add_graph_documents(graph_documents: List[GraphDocument], include_source: bool = False) → None[source]¶
Take GraphDocument as input as uses it to construct a graph.
abstract query(query: str, params: dict = {}) → List[Dict[str, Any]][source]¶
Query the graph.
abstract refresh_schema() → None[source]¶
Refreshes the graph schema information.
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.
__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.
Create a new NebulaGraph wrapper instance.
execute(query: str, params: Optional[dict] = None, retry: int = 0) → Any[source]¶
Query NebulaGraph database.
query(query: str, retry: int = 0) → Dict[str, Any][source]¶
refresh_schema() → None[source]¶
Refreshes the NebulaGraph schema information.
Examples using NebulaGraph¶
NebulaGraphQAChain
langchain_community.graphs.arangodb_graph.ArangoGraph¶
class langchain_community.graphs.arangodb_graph.ArangoGraph(db: Any)[source]¶
ArangoDB wrapper for 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 ArangoDB graph wrapper instance.
Attributes
db
schema
Methods
__init__(db)
Create a new ArangoDB graph wrapper instance.
from_db_credentials([url, dbname, username, ...])
Convenience constructor that builds Arango DB from credentials.
generate_schema([sample_ratio])
Generates the schema of the ArangoDB Database and returns it User can specify a sample_ratio (0 to 1) to determine the ratio of documents/edges used (in relation to the Collection size) to render each Collection Schema.
query(query[, top_k])
Query the ArangoDB database.
set_db(db)
set_schema([schema])
Set the schema of the ArangoDB Database.
__init__(db: Any) → None[source]¶
Create a new ArangoDB graph wrapper instance.
classmethod from_db_credentials(url: Optional[str] = None, dbname: Optional[str] = None, username: Optional[str] = None, password: Optional[str] = None) → Any[source]¶
Convenience constructor that builds Arango DB from credentials.
Parameters
Convenience constructor that builds Arango DB from credentials.
Parameters
url – Arango DB url. Can be passed in as named arg or set as environment
var ARANGODB_URL. Defaults to “http://localhost:8529”.
dbname – Arango DB name. Can be passed in as named arg or set as
environment var ARANGODB_DBNAME. Defaults to “_system”.
username – Can be passed in as named arg or set as environment var
ARANGODB_USERNAME. Defaults to “root”.
password – Can be passed ni as named arg or set as environment var
ARANGODB_PASSWORD. Defaults to “”.
Returns
An arango.database.StandardDatabase.
generate_schema(sample_ratio: float = 0) → Dict[str, List[Dict[str, Any]]][source]¶
Generates the schema of the ArangoDB Database and returns it
User can specify a sample_ratio (0 to 1) to determine the
ratio of documents/edges used (in relation to the Collection size)
to render each Collection Schema.
query(query: str, top_k: Optional[int] = None, **kwargs: Any) → List[Dict[str, Any]][source]¶
Query the ArangoDB database.
set_db(db: Any) → None[source]¶
set_schema(schema: Optional[Dict[str, Any]] = None) → None[source]¶
Set the schema of the ArangoDB Database.
Auto-generates Schema if schema is None.
Examples using ArangoGraph¶
ArangoDB QA chain
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 – Arango DB url. Can be passed in as named arg or set as environment
var ARANGODB_URL. Defaults to “http://localhost:8529”.
dbname – Arango DB name. Can be passed in as named arg or set as
environment var ARANGODB_DBNAME. Defaults to “_system”.
username – Can be passed in as named arg or set as environment var
ARANGODB_USERNAME. Defaults to “root”.
password – Can be passed ni as named arg or set as environment var
ARANGODB_PASSWORD. Defaults to “”.
Returns
An arango.database.StandardDatabase.
langchain_community.graphs.graph_document.Relationship¶
class langchain_community.graphs.graph_document.Relationship[source]¶
Bases: Serializable
Represents a directed relationship between two nodes in a graph.
source¶
The source node of the relationship.
Type
Node
target¶
The target node of the relationship.
Type
Node
type¶
The type of the relationship.
Type
str
properties¶
Additional properties associated with the relationship.
Type
dict
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 properties: dict [Optional]¶
param source: langchain_community.graphs.graph_document.Node [Required]¶
param target: langchain_community.graphs.graph_document.Node [Required]¶
param type: str [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
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 – fields to include in new model
exclude – fields to exclude from new model, as with values this takes precedence over include
update – values to change/add in the new model. Note: the data is not validated before creating
the new model: you should trust this data
langchain.hub.pull¶
langchain.hub.pull(owner_repo_commit: str, *, api_url: Optional[str] = None, api_key: Optional[str] = None) → Any[source]¶
Pulls an object from the hub and returns it as a LangChain object.
Parameters
owner_repo_commit – The full name of the repo to pull from in the format of
owner/repo:commit_hash.
api_url – The URL of the LangChain Hub API. Defaults to the hosted API service
if you have an api key set, or a localhost instance if not.
api_key – The API key to use to authenticate with the LangChain Hub API.
langchain.hub.push¶
langchain.hub.push(repo_full_name: str, object: Any, *, api_url: Optional[str] = None, api_key: Optional[str] = None, parent_commit_hash: Optional[str] = 'latest', new_repo_is_public: bool = True, new_repo_description: str = '') → str[source]¶
Pushes an object to the hub and returns the URL it can be viewed at in a browser.
Parameters
repo_full_name – The full name of the repo to push to in the format of
owner/repo.
object – The LangChain to serialize and push to the hub.
api_url – The URL of the LangChain Hub API. Defaults to the hosted API service
if you have an api key set, or a localhost instance if not.
api_key – The API key to use to authenticate with the LangChain Hub API.
parent_commit_hash – The commit hash of the parent commit to push to. Defaults
to the latest commit automatically.
new_repo_is_public – Whether the repo should be public. Defaults to
True (Public by default).
new_repo_description – The description of the repo. Defaults to an empty
string.
langchain_community.storage.upstash_redis.UpstashRedisStore¶
class langchain_community.storage.upstash_redis.UpstashRedisStore(*, client: Any = None, url: Optional[str] = None, token: Optional[str] = None, ttl: Optional[int] = None, namespace: Optional[str] = None)[source]¶
[Deprecated]  BaseStore implementation using Upstash Redis
as the underlying store to store strings.
Deprecated in favor of the more generic UpstashRedisByteStore.[Deprecated] BaseStore implementation using Upstash Redis
as the underlying store to store strings.
Deprecated in favor of the more generic UpstashRedisByteStore.
Notes
Deprecated since version 0.0.335: Use UpstashRedisByteStore instead.
Initialize the UpstashRedisStore with HTTP API.
Must provide either an Upstash Redis client or a url.
Parameters
client – An Upstash Redis instance
url – UPSTASH_REDIS_REST_URL
token – UPSTASH_REDIS_REST_TOKEN
ttl – time to expire keys in seconds if provided,
if None keys will never expire
namespace – if provided, all keys will be prefixed with this namespace
Methods
__init__(*[, client, url, token, ttl, namespace])
Initialize the UpstashRedisStore with HTTP API.
mdelete(keys)
Delete the given keys.
mget(keys)
Get the values associated with the given keys.
mset(key_value_pairs)
Set the given key-value pairs.
yield_keys(*[, prefix])
Yield keys in the store.
__init__(*, client: Any = None, url: Optional[str] = None, token: Optional[str] = None, ttl: Optional[int] = None, namespace: Optional[str] = None) → None¶
Initialize the UpstashRedisStore with HTTP API.
Initialize the UpstashRedisStore with HTTP API.
Must provide either an Upstash Redis client or a url.
Parameters
client – An Upstash Redis instance
url – UPSTASH_REDIS_REST_URL
token – UPSTASH_REDIS_REST_TOKEN
ttl – time to expire keys in seconds if provided,
if None keys will never expire
namespace – if provided, all keys will be prefixed with this namespace
mdelete(keys: Sequence[str]) → None¶
Delete the given keys.
mget(keys: Sequence[str]) → List[Optional[str]]¶
Get the values associated with the given keys.
mset(key_value_pairs: Sequence[Tuple[str, str]]) → None¶
Set the given key-value pairs.
yield_keys(*, prefix: Optional[str] = None) → Iterator[str]¶
Yield keys in the store.
langchain.storage.file_system.LocalFileStore¶
class langchain.storage.file_system.LocalFileStore(root_path: Union[str, Path])[source]¶
BaseStore interface that works on the local file system.
Examples
Create a LocalFileStore instance and perform operations on it:
from langchain.storage import LocalFileStore
# Instantiate the LocalFileStore with the root path
file_store = LocalFileStore("/path/to/root")
# Set values for keys
file_store.mset([("key1", b"value1"), ("key2", b"value2")])
# Get values for keys
values = file_store.mget(["key1", "key2"])  # Returns [b"value1", b"value2"]
# Delete keys
file_store.mdelete(["key1"])
# Iterate over keys
for key in file_store.yield_keys():
    print(key)
Implement the BaseStore interface for the local file system.
Parameters
root_path (Union[str, Path]) – The root path of the file store. All keys are
interpreted as paths relative to this root.
Methods
__init__(root_path)
Implement the BaseStore interface for the local file system.
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__(root_path: Union[str, Path]) → None[source]¶
Implement the BaseStore interface for the local file system.
Parameters
root_path (Union[str, Path]) – The root path of the file store. All keys are
interpreted as paths relative to this root.
mdelete(keys: Sequence[str]) → None[source]¶
Delete the given keys and their associated values.
Parameters
Delete the given keys and their associated values.
Parameters
keys (Sequence[str]) – A sequence of keys to delete.
Returns
None
mget(keys: Sequence[str]) → List[Optional[bytes]][source]¶
Get the values associated with the given keys.
Parameters
keys – 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.
mset(key_value_pairs: Sequence[Tuple[str, bytes]]) → None[source]¶
Set the values for the given keys.
Parameters
key_value_pairs – A sequence of key-value pairs.
Returns
None
yield_keys(prefix: Optional[str] = None) → Iterator[str][source]¶
Get an iterator over keys that match the given prefix.
Parameters
prefix (Optional[str]) – The prefix to match.
Returns
An iterator over keys that match the given prefix.
Return type
Iterator[str]
Examples using LocalFileStore¶
Caching
langchain_community.storage.upstash_redis.UpstashRedisByteStore¶
class langchain_community.storage.upstash_redis.UpstashRedisByteStore(*, client: Any = None, url: Optional[str] = None, token: Optional[str] = None, ttl: Optional[int] = None, namespace: Optional[str] = None)[source]¶
BaseStore implementation using Upstash Redis
as the underlying store to store raw bytes.
Methods
__init__(*[, client, url, token, ttl, namespace])
mdelete(keys)
Delete the given keys.
mget(keys)
Get the values associated with the given keys.
mset(key_value_pairs)
Set the given key-value pairs.
yield_keys(*[, prefix])
Yield keys in the store.
__init__(*, client: Any = None, url: Optional[str] = None, token: Optional[str] = None, ttl: Optional[int] = None, namespace: Optional[str] = None) → None[source]¶
mdelete(keys: Sequence[str]) → None[source]¶
Delete the given keys.
mget(keys: Sequence[str]) → List[Optional[bytes]][source]¶
Get the values associated with the given keys.
mset(key_value_pairs: Sequence[Tuple[str, bytes]]) → None[source]¶
Set the given key-value pairs.
yield_keys(*, prefix: Optional[str] = None) → Iterator[str][source]¶
Yield keys in the store.
langchain.storage.encoder_backed.EncoderBackedStore¶
class langchain.storage.encoder_backed.EncoderBackedStore(store: BaseStore[str, Any], key_encoder: Callable[[K], str], value_serializer: Callable[[V], bytes], value_deserializer: Callable[[Any], V])[source]¶
Wraps a store with key and value encoders/decoders.
Examples that uses JSON for encoding/decoding:
import json
def key_encoder(key: int) -> str:
    return json.dumps(key)
def value_serializer(value: float) -> str:
    return json.dumps(value)
def value_deserializer(serialized_value: str) -> float:
    return json.loads(serialized_value)
# Create an instance of the abstract store
abstract_store = MyCustomStore()
# Create an instance of the encoder-backed store
store = EncoderBackedStore(
    store=abstract_store,
    key_encoder=key_encoder,
    value_serializer=value_serializer,
    value_deserializer=value_deserializer
)
# Use the encoder-backed store methods
store.mset([(1, 3.14), (2, 2.718)])
values = store.mget([1, 2])  # Retrieves [3.14, 2.718]
store.mdelete([1, 2])  # Deletes the keys 1 and 2
Initialize an EncodedStore.
Methods
__init__(store, key_encoder, ...)
Initialize an EncodedStore.
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.
yield_keys(*[, prefix])
Get an iterator over keys that match the given prefix.
__init__(store: BaseStore[str, Any], key_encoder: Callable[[K], str], value_serializer: Callable[[V], bytes], value_deserializer: Callable[[Any], V]) → None[source]¶
Initialize an EncodedStore.
mdelete(keys: Sequence[K]) → None[source]¶
Delete the given keys and their associated values.
mget(keys: Sequence[K]) → List[Optional[V]][source]¶
Get the values associated with the given keys.
mset(key_value_pairs: Sequence[Tuple[K, V]]) → None[source]¶
Set the values for the given keys.
yield_keys(*, prefix: Optional[str] = None) → Union[Iterator[K], Iterator[str]][source]¶
Get an iterator over keys that match the given prefix.