langchain-yugabytedb
The langchain-yugabytedb package implementations of core LangChain abstractions using YugabyteDB Distributed SQL Database.
The package is released under the MIT license.
Feel free to use the abstraction as provided or else modify them / extend them as appropriate for your own application.
Requirements
The package supports the asyncpg and psycopg3 drivers.
Installation
pip install -U langchain-yugabytedb
Documentation
Example
from langchain_core.documents import Document
from langchain_core.embeddings import DeterministicFakeEmbedding
from langchain_yugabytedb import YBEngine, YugabyteDBVectorStore
# Replace the connection string with your own YugabyteDB connection string
CONNECTION_STRING = "postgresql+psycopg://yugabyte:@localhost:5433/yugabyte"
engine = YBEngine.from_connection_string(url=CONNECTION_STRING)
# Replace the vector size with your own vector size
VECTOR_SIZE = 768
embedding = DeterministicFakeEmbedding(size=VECTOR_SIZE)
TABLE_NAME = "my_doc_collection"
engine.init_vectorstore_table(
table_name=TABLE_NAME,
vector_size=VECTOR_SIZE,
)
store = YugabyteDBVectorStore.create_sync(
engine=engine,
table_name=TABLE_NAME,
embedding_service=embedding,
)
docs = [
Document(page_content="Apples and oranges"),
Document(page_content="Cars and airplanes"),
Document(page_content="Train")
]
store.add_documents(docs)
query = "I'd like a fruit."
docs = store.similarity_search(query)
print(docs)
ChatMessageHistory
The chat message history abstraction helps to persist chat message history in a YugabyteDB table.
YugabyteDBChatMessageHistory is parameterized using a table_name and a session_id.
The table_name is the name of the table in the database where
the chat messages will be stored.
The session_id is a unique identifier for the chat session. It can be assigned
by the caller using uuid.uuid4().
import uuid
from langchain_core.messages import SystemMessage, AIMessage, HumanMessage
from langchain_yugabytedb import YugabyteDBChatMessageHistory
import psycopg
# Establish a synchronous connection to the database
# (or use psycopg.AsyncConnection for async)
conn_info = ... # Fill in with your connection info
sync_connection = psycopg.connect(conn_info)
# Create the table schema (only needs to be done once)
table_name = "chat_history"
YugabyteDBChatMessageHistory.create_tables(sync_connection, table_name)
session_id = str(uuid.uuid4())
# Initialize the chat history manager
chat_history = YugabyteDBChatMessageHistory(
table_name,
session_id,
sync_connection=sync_connection
)
# Add messages to the chat history
chat_history.add_messages([
SystemMessage(content="Meow"),
AIMessage(content="woof"),
HumanMessage(content="bark"),
])
print(chat_history.messages)
Metadata
Release files for langchain-yugabytedb 0.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| langchain_yugabytedb-0.0.4.tar.gz | 248.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| langchain_yugabytedb-0.0.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 259.6 kB
Release files / langchain_yugabytedb-0.0.4.tar.gz
| Download URL | langchain_yugabytedb-0.0.4.tar.gz |
|---|---|
| Size | 248.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
caf05f930b7ba0a006ea4e3515b62404d7b42b42eaf2e2eb7a9398da45cc3b0d
|
|
BLAKE2b-256 checksum How to use checksums |
8275a1eee8590bd76a920201c51a9b8f26fa6f25c786d79818aa8e4cae8c10f8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.5
|
Release files / langchain_yugabytedb-0.0.4-py3-none-any.whl
| Download URL | langchain_yugabytedb-0.0.4-py3-none-any.whl |
|---|---|
| Size | 11.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0e4990954c4c04c3323a33be2a00f777c38b0b15a8d8e86f95498a92b7fdc42f
|
|
BLAKE2b-256 checksum How to use checksums |
aed38a13dcb4d0a4ad90487e88c50c3d2b3d37c3e173b98d064332f1f793b4ae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.5
|
Security for langchain-yugabytedb 0.0.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.