Skip to main content

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 custom Embeddings implementation).
  • 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=True during 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_texts when 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langchain_matrixone-0.1.0.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langchain_matrixone-0.1.0-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

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

Hashes for langchain_matrixone-0.1.0.tar.gz
Algorithm Hash digest
SHA256 58477f37e8cba4f8497d6ca33e544cd4813b5688d453b947b8e622c47e9765b8
MD5 78e721cc53a947e180f1f6c3df888eb4
BLAKE2b-256 952f93256ad46313add79403615bb4d588c3c9c149a648f2b61725016beebdd9

See more details on using hashes here.

File details

Details for the file langchain_matrixone-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_matrixone-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d442e6c5ca0b019ed024a6e2a1a0125296e8196c453266faaa0796efd8b1dc27
MD5 f71ab4feb39784957b0061c7122ccac0
BLAKE2b-256 624296c176b2317488eea025c4d529432c28a78232473680532e48b767f17694

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page