LangChain VectorStore integrations for Azure Database for PostgreSQL
Project description
langchain-azure-postgresql
langchain-azure-postgresql is a Python package that implements both asynchronous
and synchronous VectorStore support for Azure Database for PostgreSQL. Specifically,
this package adds support for
- Microsoft Entra ID (formerly Azure AD) authentication when connecting to your Azure Database for PostgreSQL instances, and,
- DiskANN indexing algorithm when indexing your (semantic) vectors.
This way, you can leverage your Azure Database for PostgreSQL instances as secure and fast vector stores for your LangChain workflows.
[!NOTE]
langchain-azure-postgresqlcurrently supports Python 3.10 and above.
Installation
To install langchain-azure-postgresql, you need to install the necessary Python
packages:
$ python3 -m pip install langchain langchain-azure-postgresql langchain-openai
# logs stripped for brevity
Usage
Once the packages are installed, you can use Azure Database for PostgreSQL instances as vector stores:
import os
from langchain_core.documents import Document
from langchain_openai import OpenAIEmbeddings
from langchain_azure_postgresql.common import AzurePGConnectionPool, ConnectionInfo
from langchain_azure_postgresql.langchain import AzurePGVectorStore
documents = [
Document(
page_content="Dogs are great companions, known for their loyalty and friendliness.",
metadata={"source": "mammal-pets-doc"},
),
Document(
page_content="Cats are independent pets that often enjoy their own space.",
metadata={"source": "mammal-pets-doc"},
),
]
host = os.getenv("PGHOST", "localhost")
connection_pool = AzurePGConnectionPool(azure_conn_info=ConnectionInfo(host=host))
embedding = OpenAIEmbeddings(model="text-embedding-3-small")
vector_store = AzurePGVectorStore(connection_pool=connection_pool, embedding=embedding)
vector_store.add_documents(documents)
The code snippet above will try to connect to your PostgreSQL host, as defined
by the environment variable PGHOST, and fall back to connecting to localhost
if the environment variable is not defined. By default, ConnectionInfo objects
try to use Microsoft Entra ID to login to the PostgreSQL instances/hosts.
Please see the documentation for more details on configuring various classes
provided by langchain-azure-postgresql.
Development
The development environment for this package is managed by uv, an
up-and-coming and versatile Python package and project manager.
To create the development environment, you first need to install uv in your
development environment (unless you are using the development container setup
as provided by this repository). Once uv is properly installed and set up,
you can run the following commands to synchronize and activate the development
environment:
$ uv sync --all-extras # synchronize the development environment from uv.lock
# logs stripped for brevity
$ source .venv/bin/activate # or, as appropriate for your shell, e.g., fish
Once the development environment is synchronized and activated, you can start
contributing changes to the package. For test automation, the package leverages
tox, a test automation and standardization framework in Python.
There are some pre-defined test environments and labels managed by tox:
$ tox list
default environments:
lint -> Run lint checks on the code base
package -> Run packaging checks on the code base
type -> Run type checks on the code base
3.10 -> Run tests under Python 3.10
3.11 -> Run tests under Python 3.11
3.12 -> Run tests under Python 3.12
3.13 -> Run tests under Python 3.13
The default environments are for running lint checks, packaging checks, type
checks, and end-to-end tests for different Python versions, respectively. You
can selectively run an environment via, e.g., tox run -e lint, or, otherwise,
run the full suite of tests via tox. There is a special label called test,
which will run only the end-to-end tests for all the supported Python versions
and can be run via the following:
$ PGHOST=<host>.postgres.database.azure.com PGPASSWORD='your_password' tox run -m test
# logs stripped for brevity
For more information on the supported test flags and environment variables, please
check the output of pytest --help.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file langchain_azure_postgresql-1.0.1.tar.gz.
File metadata
- Download URL: langchain_azure_postgresql-1.0.1.tar.gz
- Upload date:
- Size: 36.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
842bcb0e0da19ea04e5c9e915bf74dc3c4f869ccd9616f1a905e8fe81f55ad61
|
|
| MD5 |
75e2daf593ee7c4992645a80cbdeda85
|
|
| BLAKE2b-256 |
c44766ce982b9a6c49ac3abf0ea019b39a5626f868dd3755036b7bb75137cfb9
|
File details
Details for the file langchain_azure_postgresql-1.0.1-py3-none-any.whl.
File metadata
- Download URL: langchain_azure_postgresql-1.0.1-py3-none-any.whl
- Upload date:
- Size: 41.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
668734648b2ebf93d28d960d29dd80fafd8c46a4e9133c8141805c6e5f752cc7
|
|
| MD5 |
e339e659a1379e136a1ffcb0a12d78c5
|
|
| BLAKE2b-256 |
bf87fd9469337421cb3764f347f6505a0c9f5c10215d88a2c1e8036e7ecda96b
|