Chain for question-answering against a Neptune graph by generating openCypher statements.
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.
Chain for question-answering against a Neptune graph by generating SPARQL statements.
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.
A chat model that uses the Bedrock API.
Bedrock chat model integration built on the Bedrock converse API.
This implementation will eventually replace the existing ChatBedrock implementation once the Bedrock converse API has feature parity with older Bedrock API. Specifically the converse API does not yet support custom Bedrock models.
Document compressor that uses AWS Bedrock Rerank API.
Bedrock embedding models.
To authenticate, the AWS client uses the following methods to automatically load credentials: https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html
If a specific credential profile should be used, you must pass the name of the profile from the ~/.aws/credentials file that is to be used.
Make sure the credentials / roles used have the required policies to access the Bedrock service.
Neptune Analytics wrapper for graph operations.
Neptune wrapper for graph operations.
Bedrock models.
To authenticate, the AWS client uses the following methods to automatically load credentials: https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html
If a specific credential profile should be used, you must pass the name of the profile from the ~/.aws/credentials file that is to be used.
Make sure the credentials / roles used have the required policies to access the Bedrock service.
Sagemaker Inference Endpoint models.
To use, you must supply the endpoint name from your deployed Sagemaker model & the region where it is deployed.
To authenticate, the AWS client uses the following methods to automatically load credentials: https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html
If a specific credential profile should be used, you must pass the name of the profile from the ~/.aws/credentials file that is to be used.
Make sure the credentials / roles used have the required policies to access the Sagemaker endpoint. See: https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html
Amazon Kendra Index retriever.
Amazon Bedrock Knowledge Bases retrieval.
See https://aws.amazon.com/bedrock/knowledge-bases for more info.
Args:
knowledge_base_id: Knowledge Base ID.
region_name: The aws region e.g., `us-west-2`.
Fallback to AWS_DEFAULT_REGION env variable or region specified in
~/.aws/config.
credentials_profile_name: The name of the profile in the ~/.aws/credentials
or ~/.aws/config files, which has either access keys or role information
specified. If not specified, the default credential profile or, if on an
EC2 instance, credentials from IMDS will be used.
client: boto3 client for bedrock agent runtime.
retrieval_config: Optional configuration for retrieval specified as a
Python object (RetrievalConfig) or as a dictionary
Example:
.. code-block:: python
from langchain_community.retrievers import AmazonKnowledgeBasesRetriever
retriever = AmazonKnowledgeBasesRetriever(
knowledge_base_id="
Cache that uses MemoryDB as a vector-store backend.
InMemoryVectorStore vector database.
To use, you should have the redis python package installed
for AWS MemoryDB
.. code-block:: bash
Once running, you can connect to the MemoryDB server with the following url schemas:
Examples:
The following examples show various ways to use the Redis VectorStore with LangChain.
For all the following examples assume we have the following imports:
.. code-block:: python
from langchain_aws.vectorstores import InMemoryVectorStore
Initialize, create index, and load Documents .. code-block:: python
from langchain_aws.vectorstores import InMemoryVectorStore
rds = InMemoryVectorStore.from_documents(
documents, # a list of Document objects from loaders or created
embeddings, # an Embeddings object
redis_url="redis://cluster_endpoint:6379",
)
Initialize, create index, and load Documents with metadata .. code-block:: python
rds = InMemoryVectorStore.from_texts(
texts, # a list of strings
metadata, # a list of metadata dicts
embeddings, # an Embeddings object
redis_url="redis://cluster_endpoint:6379",
)
Initialize, create index, and load Documents with metadata and return keys
.. code-block:: python
rds, keys = InMemoryVectorStore.from_texts_return_keys(
texts, # a list of strings
metadata, # a list of metadata dicts
embeddings, # an Embeddings object
redis_url="redis://cluster_endpoint:6379",
)
For use cases where the index needs to stay alive, you can initialize with an index name such that it's easier to reference later
.. code-block:: python
rds = InMemoryVectorStore.from_texts(
texts, # a list of strings
metadata, # a list of metadata dicts
embeddings, # an Embeddings object
index_name="my-index",
redis_url="redis://cluster_endpoint:6379",
)
Initialize and connect to an existing index (from above)
.. code-block:: python
# must pass in schema and key_prefix from another index
existing_rds = InMemoryVectorStore.from_existing_index(
embeddings, # an Embeddings object
index_name="my-index",
schema=rds.schema, # schema dumped from another index
key_prefix=rds.key_prefix, # key prefix from another index
redis_url="redis://cluster_endpoint:6379",
)
Advanced examples:
Custom vector schema can be supplied to change the way that MemoryDB creates the underlying vector schema. This is useful for production use cases where you want to optimize the vector schema for your use case. ex. using HNSW instead of FLAT (knn) which is the default
.. code-block:: python
vector_schema = {
"algorithm": "HNSW"
}
rds = InMemoryVectorStore.from_texts(
texts, # a list of strings
metadata, # a list of metadata dicts
embeddings, # an Embeddings object
vector_schema=vector_schema,
redis_url="redis://cluster_endpoint:6379",
)
Custom index schema can be supplied to change the way that the metadata is indexed. This is useful for you would like to use the hybrid querying (filtering) capability of MemoryDB.
By default, this implementation will automatically generate the index schema according to the following rules: - All strings are indexed as text fields - All numbers are indexed as numeric fields - All lists of strings are indexed as tag fields (joined by langchain_aws.vectorstores.inmemorydb.constants.INMEMORYDB_TAG_SEPARATOR) - All None values are not indexed but still stored in MemoryDB these are not retrievable through the interface here, but the raw MemoryDB client can be used to retrieve them. - All other types are not indexed
To override these rules, you can pass in a custom index schema like the following
.. code-block:: yaml
tag:
- name: credit_score
text:
- name: user
- name: job
Typically, the credit_score field would be a text field since it's a string,
however, we can override this behavior by specifying the field type as shown with
the yaml config (can also be a dictionary) above and the code below.
.. code-block:: python
rds = InMemoryVectorStore.from_texts(
texts, # a list of strings
metadata, # a list of metadata dicts
embeddings, # an Embeddings object
index_schema="path/to/index_schema.yaml", # can also be a dictionary
redis_url="redis://cluster_endpoint:6379",
)
When connecting to an existing index where a custom schema has been applied, it's
important to pass in the same schema to the from_existing_index method.
Otherwise, the schema for newly added samples will be incorrect and metadata
will not be returned.
Methods for creating function specs in the style of Bedrock Functions for supported model providers