LangChain integration for MatrixOne
Project description
LangChain MatrixOne
This package contains the LangChain integration for MatrixOne.
Installation
You can install this package using pip or uv:
pip install langchain-matrixone
# or
uv pip install langchain-matrixone
Prerequisites
- A running MatrixOne instance that you can reach over MySQL protocol.
- Network credentials (host, port, user, password, database) with permission to create tables.
- An embedding model supported by LangChain (e.g.,
OpenAIEmbeddings,HuggingFaceEmbeddings, or a customEmbeddingsimplementation). - The MatrixOne Python SDK (installed automatically with this package) must be able to connect with vector operations enabled.
Development
This project uses uv for dependency management.
# Install dependencies
uv sync
# Run tests
uv run pytest
Usage
from langchain_matrixone import MatrixOneVectorStore
from langchain_community.embeddings import HuggingFaceEmbeddings
from langchain_text_splitters import RecursiveCharacterTextSplitter
from langchain_core.documents import Document
connection_args = {
"host": "127.0.0.1",
"port": 6001,
"user": "root",
"password": "111",
"database": "langchain_demo",
}
embedder = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-L6-v2")
vector_store = MatrixOneVectorStore(
embedding=embedder,
connection_args=connection_args,
table_name="langchain_vectors",
)
# Ensure you have a running MatrixOne deployment accessible via MySQL.
splitter = RecursiveCharacterTextSplitter(chunk_size=400, chunk_overlap=20)
docs = splitter.split_documents(
[
Document(page_content="MatrixOne is a scalable cloud-native database."),
Document(page_content="LangChain provides common interfaces for LLM apps."),
]
)
vector_store.add_texts([doc.page_content for doc in docs], metadatas=[doc.metadata for doc in docs])
query = "What is LangChain?"
similar = vector_store.similarity_search(query, k=2)
for doc in similar:
print(doc.page_content, doc.metadata)
Using an existing MatrixOne Client
If you already manage a matrixone.Client elsewhere in your application, pass it
directly to the vector store to reuse pooled connections:
from matrixone import Client
client = Client()
client.connect(**connection_args)
vector_store = MatrixOneVectorStore(
embedding=embedder,
client=client,
table_name="langchain_vectors",
)
Notes
- The vector table schema is created automatically if it does not exist. Set
drop_old=Trueduring initialization to recreate it. - Any additional metadata stored alongside texts must be JSON serializable.
- MatrixOne currently expects embeddings as
VECF32. Ensure the embedding dimension stays constant for a given table. - Use
MatrixOneVectorStore.from_textswhen you want a single call that both creates the store and inserts documents. - For advanced vector indexing (IVF/HNSW) or additional capabilities review the MatrixOne vector operations guide.
Features
- Vector Search with MatrixOne
- Metadata filtering (if supported)
- Add/Delete documents
Project details
Release history Release notifications | RSS feed
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_matrixone-0.1.0.tar.gz.
File metadata
- Download URL: langchain_matrixone-0.1.0.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
58477f37e8cba4f8497d6ca33e544cd4813b5688d453b947b8e622c47e9765b8
|
|
| MD5 |
78e721cc53a947e180f1f6c3df888eb4
|
|
| BLAKE2b-256 |
952f93256ad46313add79403615bb4d588c3c9c149a648f2b61725016beebdd9
|
File details
Details for the file langchain_matrixone-0.1.0-py3-none-any.whl.
File metadata
- Download URL: langchain_matrixone-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d442e6c5ca0b019ed024a6e2a1a0125296e8196c453266faaa0796efd8b1dc27
|
|
| MD5 |
f71ab4feb39784957b0061c7122ccac0
|
|
| BLAKE2b-256 |
624296c176b2317488eea025c4d529432c28a78232473680532e48b767f17694
|