> For the complete documentation index, see [llms.txt](https://mariadb.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mariadb.com/docs/connectors/other/langchain-mariadb.md).

# LangChain MariaDB

The **langchain-mariadb** package provides seamless integration between [LangChain](https://python.langchain.com/) and MariaDB, enabling advanced AI and machine learning workflows with persistent storage.

## Features

* **Vector Store** - Store and search embeddings using MariaDB's vector capabilities
* **Chat Message History** - Persistent conversation storage for chatbots and AI assistants
* **Expression Filters** - Advanced metadata filtering for vector search
* **Natural Language Queries** - Translate natural language to SQL queries

## Installation

```bash
pip install langchain-mariadb
```

## Quick Start

### Vector Store Example

```python
from langchain_mariadb import MariaDBStore
from langchain_openai import OpenAIEmbeddings

embeddings = OpenAIEmbeddings()
vectorstore = MariaDBStore(
    embeddings=embeddings,
    datasource="mariadb://user:password@localhost/database",
    collection_name="my_documents"
)

# Add documents
vectorstore.add_texts(["Hello world", "LangChain with MariaDB"])

# Search
results = vectorstore.similarity_search("greeting", k=1)
```

### Chat Message History Example

```python
from langchain_mariadb import MariaDBChatMessageHistory

history = MariaDBChatMessageHistory(
    session_id="user_123",
    connection_string="mariadb://user:password@localhost/database"
)

history.add_user_message("Hello!")
history.add_ai_message("Hi! How can I help you?")
```

## Documentation

For complete documentation, guides, and tutorials, visit the official LangChain documentation:

* [**LangChain MariaDB Documentation**](https://docs.langchain.com/oss/python/integrations/vectorstores/mariadb)

This section contains only the API reference:

* [**API Reference**](/docs/connectors/other/langchain-mariadb/api-reference.md) - Complete API documentation

## Resources

* [GitHub Repository](https://github.com/mariadb-corporation/langchain-mariadb)
* [PyPI Package](https://pypi.org/project/langchain-mariadb/)
* [LangChain Documentation](https://python.langchain.com/)

## Version

Current version: **v0.0.20**


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://mariadb.com/docs/connectors/other/langchain-mariadb.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
