Tony20100/langchain_full huggingface dataset:
query_endpoint (str) – 
query_ontology (Optional[str]) – 
local_file_format (Optional[str]) – 
Return type
None
Supported RDF formats:
Turtle, RDF/XML, JSON-LD, N-Triples, Notation-3, Trig, Trix, N-Quads.
If the rdf format can’t be determined from the file extension,
pass explicitly the rdf format in local_file_format param.
Parameters
local_file_format (Optional[str]) – Used if the rdf format can’t be determined
query_endpoint (str) – 
query_ontology (Optional[str]) – 
local_file (Optional[str]) – 
Return type
None
from the local file extension.
One of “json-ld”, “xml”, “n3”, “turtle”, “nt”, “trig”, “nquads”, “trix”
Either query_ontology or local_file should be passed.
query(query: str) → List[rdflib.query.ResultRow][source]¶
Query the graph.
Parameters
query (str) – 
Return type
List[rdflib.query.ResultRow]
Examples using OntotextGraphDBGraph¶
Ontotext GraphDB
langchain_community.graphs.index_creator.GraphIndexCreator¶
class langchain_community.graphs.index_creator.GraphIndexCreator[source]¶
Bases: BaseModel
Functionality to create graph index.
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 graph_type: Type[NetworkxEntityGraph] = <class 'langchain_community.graphs.networkx_graph.NetworkxEntityGraph'>¶
param llm: Optional[BaseLanguageModel] = None¶
param llm: Optional[BaseLanguageModel] = None¶
async afrom_text(text: str, prompt: BasePromptTemplate = PromptTemplate(input_variables=['text'], template="You are a networked intelligence helping a human track knowledge triples about all relevant people, things, concepts, etc. and integrating them with your knowledge stored within your weights as well as that stored in a knowledge graph. Extract all of the knowledge triples from the text. A knowledge triple is a clause that contains a subject, a predicate, and an object. The subject is the entity being described, the predicate is the property of the subject that is being described, and the object is the value of the property.\n\nEXAMPLE\nIt's a state in the US. It's also the number 1 producer of gold in the US.\n\nOutput: (Nevada, is a, state)<|>(Nevada, is in, US)<|>(Nevada, is the number 1 producer of, gold)\nEND OF EXAMPLE\n\nEXAMPLE\nI'm going to the store.\n\nOutput: NONE\nEND OF EXAMPLE\n\nEXAMPLE\nOh huh. I know Descartes likes to drive antique scooters and play the mandolin.\nOutput: (Descartes, likes to drive, antique scooters)<|>(Descartes, plays, mandolin)\nEND OF EXAMPLE\n\nEXAMPLE\n{text}Output:")) → NetworkxEntityGraph[source]¶
Create graph index from text asynchronously.
Parameters
text (str) – 
prompt (BasePromptTemplate) – 
Return type
NetworkxEntityGraph
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.
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
classmethod from_orm(obj: Any) → Model¶
Parameters
obj (Any) – 
Return type
Model
from_text(text: str, prompt: BasePromptTemplate = PromptTemplate(input_variables=['text'], template="You are a networked intelligence helping a human track knowledge triples about all relevant people, things, concepts, etc. and integrating them with your knowledge stored within your weights as well as that stored in a knowledge graph. Extract all of the knowledge triples from the text. A knowledge triple is a clause that contains a subject, a predicate, and an object. The subject is the entity being described, the predicate is the property of the subject that is being described, and the object is the value of the property.\n\nEXAMPLE\nIt's a state in the US. It's also the number 1 producer of gold in the US.\n\nOutput: (Nevada, is a, state)<|>(Nevada, is in, US)<|>(Nevada, is the number 1 producer of, gold)\nEND OF EXAMPLE\n\nEXAMPLE\nI'm going to the store.\n\nOutput: NONE\nEND OF EXAMPLE\n\nEXAMPLE\nOh huh. I know Descartes likes to drive antique scooters and play the mandolin.\nOutput: (Descartes, likes to drive, antique scooters)<|>(Descartes, plays, mandolin)\nEND OF EXAMPLE\n\nEXAMPLE\n{text}Output:")) → NetworkxEntityGraph[source]¶
Create graph index from text.
Parameters
text (str) – 
prompt (BasePromptTemplate) – 
Return type
NetworkxEntityGraph
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
classmethod parse_file(path: Union[str, Path], *, content_type: unicode = None, encoding: unicode = 'utf8', proto: Protocol = None, allow_pickle: bool = False) → Model¶
Parameters
path (Union[str, Path]) – 
content_type (unicode) – 
encoding (unicode) – 
proto (Protocol) – 
allow_pickle (bool) – 
Return type
Model
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
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
classmethod update_forward_refs(**localns: Any) → None¶
Try to update ForwardRefs on fields based on this Model, globalns and localns.
Parameters
localns (Any) – 
Return type
None
classmethod validate(value: Any) → Model¶
Parameters
value (Any) – 
Return type
Model
Examples using GraphIndexCreator¶
NetworkX
langchain_community.graphs.memgraph_graph.MemgraphGraph¶
class langchain_community.graphs.memgraph_graph.MemgraphGraph(url: str, username: str, password: str, *, database: str = 'memgraph')[source]¶
Memgraph 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 Memgraph graph wrapper instance.
Attributes
get_schema
Returns the schema of the Graph
get_structured_schema
Returns the structured schema of the Graph
Methods
__init__(url, username, password, *[, database])
Create a new Memgraph graph wrapper instance.
add_graph_documents(graph_documents[, ...])
This method constructs nodes and relationships in the graph based on the provided GraphDocument objects.
query(query[, params])
Query Neo4j database.
refresh_schema()
Refreshes the Memgraph graph schema information.
Parameters
url (str) – 
username (str) – 
password (str) – 
database (str) – 
__init__(url: str, username: str, password: str, *, database: str = 'memgraph') → None[source]¶
Create a new Memgraph graph wrapper instance.
Parameters
url (str) – 
username (str) – 
password (str) – 
database (str) – 
Return type
None
password (str) – 
database (str) – 
Return type
None
add_graph_documents(graph_documents: List[GraphDocument], include_source: bool = False, baseEntityLabel: bool = False) → None¶
This method constructs nodes and relationships in the graph based on the
provided GraphDocument objects.
Parameters:
- graph_documents (List[GraphDocument]): A list of GraphDocument objects
that contain the nodes and relationships to be added to the graph. Each
GraphDocument should encapsulate the structure of part of the graph,
including nodes, relationships, and the source document information.
- include_source (bool, optional): If True, stores the source document
and links it to nodes in the graph using the MENTIONS relationship.
This is useful for tracing back the origin of data. Merges source
documents based on the id property from the source document metadata
if available; otherwise it calculates the MD5 hash of page_content
for merging process. Defaults to False.
- baseEntityLabel (bool, optional): If True, each newly created node
gets a secondary __Entity__ label, which is indexed and improves import
speed and performance. Defaults to False.
Parameters
graph_documents (List[GraphDocument]) – 
include_source (bool) – 
baseEntityLabel (bool) – 
Return type
None
query(query: str, params: dict = {}) → List[Dict[str, Any]]¶
Query Neo4j database.
Parameters
query (str) – 
params (dict) – 
Return type
List[Dict[str, Any]]
refresh_schema() → None[source]¶
Refreshes the Memgraph graph schema information.
Return type
None
Examples using MemgraphGraph¶
Memgraph
langchain_community.graphs.hugegraph.HugeGraph¶
class langchain_community.graphs.hugegraph.HugeGraph(username: str = 'default', password: str = 'default', address: str = '127.0.0.1', port: int = 8081, graph: str = 'hugegraph')[source]¶
HugeGraph 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 HugeGraph wrapper instance.
Attributes
get_schema
Returns the schema of the HugeGraph database
Methods
__init__([username, password, address, ...])
Create a new HugeGraph wrapper instance.
query(query)
refresh_schema()
Refreshes the HugeGraph schema information.
Parameters
username (str) – 
password (str) – 
address (str) – 
port (int) – 
graph (str) – 
__init__(username: str = 'default', password: str = 'default', address: str = '127.0.0.1', port: int = 8081, graph: str = 'hugegraph') → None[source]¶
Create a new HugeGraph wrapper instance.
Parameters
username (str) – 
password (str) – 
address (str) – 
port (int) – 
graph (str) – 
Return type
port (int) – 
graph (str) – 
Return type
None
query(query: str) → List[Dict[str, Any]][source]¶
Parameters
query (str) – 
Return type
List[Dict[str, Any]]
refresh_schema() → None[source]¶
Refreshes the HugeGraph schema information.
Return type
None
Examples using HugeGraph¶
HugeGraph
langchain_community.graphs.graph_store.GraphStore¶
class langchain_community.graphs.graph_store.GraphStore[source]¶
Abstract class for graph operations.
Attributes
get_schema
Return the schema of the Graph database
get_structured_schema
Return 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()
Refresh 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.
Parameters
graph_documents (List[GraphDocument]) – 
include_source (bool) – 
Return type
None
abstract query(query: str, params: dict = {}) → List[Dict[str, Any]][source]¶
Query the graph.
Parameters
query (str) – 
params (dict) – 
Return type
List[Dict[str, Any]]
abstract refresh_schema() → None[source]¶
Refresh the graph schema information.
Return type
None
langchain_community.graphs.neptune_graph.NeptuneGraph¶
class langchain_community.graphs.neptune_graph.NeptuneGraph(host: str, port: int = 8182, use_https: bool = True, client: Optional[Any] = None, credentials_profile_name: Optional[str] = None, region_name: Optional[str] = None, sign: bool = True)[source]¶
Neptune wrapper for graph operations.
Parameters
host (str) – endpoint for the database instance
port (int) – port number for the database instance, default is 8182
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 – optional service name, default is neptunedata
sign (bool) – optional, whether to sign the request payload, default is True
Example
graph = NeptuneGraph(host=’<my-cluster>’,
port=8182
)
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 graph wrapper instance.
Attributes
get_schema
Return the schema of the Neptune database
Methods
__init__(host[, port, use_https, client, ...])
Create a new Neptune graph wrapper instance.
Create a new Neptune graph wrapper instance.
query(query[, params])
Query Neptune database.
__init__(host: str, port: int = 8182, use_https: bool = True, client: Optional[Any] = None, credentials_profile_name: Optional[str] = None, region_name: Optional[str] = None, sign: bool = True) → None[source]¶
Create a new Neptune graph wrapper instance.
Parameters
host (str) – 
port (int) – 
use_https (bool) – 
client (Optional[Any]) – 
credentials_profile_name (Optional[str]) – 
region_name (Optional[str]) – 
sign (bool) – 
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 NeptuneGraph¶
AWS
Amazon Neptune with Cypher
langchain_aws.graphs.neptune_graph.BaseNeptuneGraph¶
class langchain_aws.graphs.neptune_graph.BaseNeptuneGraph[source]¶
Attributes
get_schema
Returns the schema of the Neptune database
Methods
__init__()
query(query[, params])
__init__()¶
abstract query(query: str, params: dict = {}) → dict[source]¶
Parameters
query (str) – 
params (dict) – 
Return type
dict
langchain_community.graphs.graph_document.Node¶
class langchain_community.graphs.graph_document.Node[source]¶
Bases: Serializable
Represents a node in a graph with associated properties.
id¶
A unique identifier for the node.
Type
Union[str, int]
type¶
The type or label of the node, default is “Node”.
Type
str
properties¶
Additional properties and metadata associated with the node.
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 id: Union[str, int] [Required]¶
param properties: dict [Optional]¶
param type: str = 'Node'¶
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
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 Node¶
Azure Cosmos DB for Apache Gremlin
Microsoft
langchain_text_splitters.nltk.NLTKTextSplitter¶
class langchain_text_splitters.nltk.NLTKTextSplitter(separator: str = '\n\n', language: str = 'english', **kwargs: Any)[source]¶
Splitting text using NLTK package.
Initialize the NLTK splitter.
Methods
__init__([separator, language])
Initialize the NLTK splitter.
atransform_documents(documents, **kwargs)
Asynchronously transform a list of documents.
create_documents(texts[, metadatas])
Create documents from a list of texts.
from_huggingface_tokenizer(tokenizer, **kwargs)
Text splitter that uses HuggingFace tokenizer to count length.
from_tiktoken_encoder([encoding_name, ...])
Text splitter that uses tiktoken encoder to count length.
split_documents(documents)
Split documents.
split_text(text)
Split incoming text and return chunks.
transform_documents(documents, **kwargs)
Transform sequence of documents by splitting them.
Parameters
separator (str) – 
language (str) – 
kwargs (Any) – 
__init__(separator: str = '\n\n', language: str = 'english', **kwargs: Any) → None[source]¶
Initialize the NLTK splitter.
Parameters
separator (str) – 
language (str) – 
kwargs (Any) – 
Return type
None
async atransform_documents(documents: Sequence[Document], **kwargs: Any) → Sequence[Document]¶
Asynchronously transform a list of documents.
Parameters
documents (Sequence[Document]) – A sequence of Documents to be transformed.
kwargs (Any) – 
Returns
A list of transformed Documents.
Return type
Sequence[Document]
Returns
A list of transformed Documents.
Return type
Sequence[Document]
create_documents(texts: List[str], metadatas: Optional[List[dict]] = None) → List[Document]¶
Create documents from a list of texts.
Parameters
texts (List[str]) – 
metadatas (Optional[List[dict]]) – 
Return type
List[Document]
classmethod from_huggingface_tokenizer(tokenizer: Any, **kwargs: Any) → TextSplitter¶
Text splitter that uses HuggingFace tokenizer to count length.
Parameters
tokenizer (Any) – 
kwargs (Any) – 
Return type
TextSplitter
classmethod from_tiktoken_encoder(encoding_name: str = 'gpt2', model_name: Optional[str] = None, allowed_special: Union[Literal['all'], AbstractSet[str]] = {}, disallowed_special: Union[Literal['all'], Collection[str]] = 'all', **kwargs: Any) → TS¶
Text splitter that uses tiktoken encoder to count length.
Parameters
encoding_name (str) – 
model_name (Optional[str]) – 
allowed_special (Union[Literal['all'], ~typing.AbstractSet[str]]) – 
disallowed_special (Union[Literal['all'], ~typing.Collection[str]]) – 
kwargs (Any) – 
Return type
TS
split_documents(documents: Iterable[Document]) → List[Document]¶
Split documents.
Parameters
documents (Iterable[Document]) – 
Return type
List[Document]
split_text(text: str) → List[str][source]¶
Split incoming text and return chunks.
Parameters
text (str) – 
Return type
List[str]
transform_documents(documents: Sequence[Document], **kwargs: Any) → Sequence[Document]¶
Transform sequence of documents by splitting them.
Parameters
langchain_ai21.contextual_answers.AI21ContextualAnswers¶
class langchain_ai21.contextual_answers.AI21ContextualAnswers[source]¶
Bases: RunnableSerializable[ContextualAnswerInput, str], AI21Base
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 api_host: Optional[str] = None¶
param api_key: Optional[SecretStr] = None¶
Constraints
type = string
writeOnly = True
format = password
param num_retries: Optional[int] = None¶
param timeout_sec: Optional[float] = None¶
async abatch(inputs: List[Input], config: Optional[Union[RunnableConfig, List[RunnableConfig]]] = None, *, return_exceptions: bool = False, **kwargs: Optional[Any]) → List[Output]¶
Default implementation runs ainvoke in parallel using asyncio.gather.
The default implementation of batch works well for IO bound runnables.
Subclasses should override this method if they can batch more efficiently;
e.g., if the underlying runnable uses an API which supports a batch mode.
Parameters
inputs (List[Input]) – 
config (Optional[Union[RunnableConfig, List[RunnableConfig]]]) – 
return_exceptions (bool) – 
kwargs (Optional[Any]) – 
Return type
List[Output]
async abatch_as_completed(inputs: Sequence[Input], config: Optional[Union[RunnableConfig, Sequence[RunnableConfig]]] = None, *, return_exceptions: bool = False, **kwargs: Optional[Any]) → AsyncIterator[Tuple[int, Union[Output, Exception]]]¶
Run ainvoke in parallel on a list of inputs,
yielding results as they complete.
Parameters
inputs (Sequence[Input]) –
# Output is 'One two'
Parameters
kwargs (Any) – 
Return type
Runnable[Input, Output]
config_schema(*, include: Optional[Sequence[str]] = None) → Type[BaseModel]¶
The type of config this runnable accepts specified as a pydantic model.
To mark a field as configurable, see the configurable_fields
and configurable_alternatives methods.
Parameters
include (Optional[Sequence[str]]) – A list of fields to include in the config schema.
Returns
A pydantic model that can be used to validate config.
Return type
Type[BaseModel]
configurable_alternatives(which: ConfigurableField, *, default_key: str = 'default', prefix_keys: bool = False, **kwargs: Union[Runnable[Input, Output], Callable[[], Runnable[Input, Output]]]) → RunnableSerializable[Input, Output]¶
Configure alternatives for runnables that can be set at runtime.
from langchain_anthropic import ChatAnthropic
from langchain_core.runnables.utils import ConfigurableField
from langchain_openai import ChatOpenAI
model = ChatAnthropic(
    model_name="claude-3-sonnet-20240229"
).configurable_alternatives(
    ConfigurableField(id="llm"),
    default_key="anthropic",
    openai=ChatOpenAI()
)
# uses the default model ChatAnthropic
print(model.invoke("which organization created you?").content)
# uses ChatOpenAI
print(
    model.with_config(
        configurable={"llm": "openai"}
    ).invoke("which organization created you?").content
)
Parameters
which (ConfigurableField) – 
default_key (str) – 
prefix_keys (bool) –