An integration package connecting SingleStore and LangChain
Project description
langchain-singlestore
This package provides the LangChain integration with SingleStore, enabling efficient storage, retrieval, and management of documents, embeddings, and chat message history using SingleStore's high-performance distributed SQL database.
Installation
To install the package, run:
pip install -U langchain-singlestore
Features
This package includes the following components:
Chat Message History
The SingleStoreChatMessageHistory class allows you to store and retrieve chat message history in SingleStore.
from langchain_singlestore import SingleStoreChatMessageHistory
chat_history = SingleStoreChatMessageHistory(
host="127.0.0.1:3306/db",
table_name="chat_history"
)
# Add a message to the chat history
chat_history.add_message({"role": "user", "content": "Hello, how are you?"})
# Retrieve chat history
messages = chat_history.get_messages()
print(messages)
Semantic Cache
The SingleStoreSemanticCache class provides a semantic caching mechanism using SingleStore as the backend. It stores embeddings and allows for efficient retrieval based on similarity.
from langchain_singlestore import SingleStoreSemanticCache
from langchain_core.globals import set_llm_cache
set_llm_cache(
SingleStoreSemanticCache(
embedding=YourEmbeddings(),
host="root:pass@localhost:3306/db",
)
)
Vector Store
The SingleStoreVectorStore class enables storing document embeddings and performing fast vector and full-text searches. It supports advanced search strategies like VECTOR_ONLY, TEXT_ONLY, and hybrid approaches.
from langchain_singlestore.vectorstores import SingleStoreVectorStore
from langchain_core.documents import Document
vector_store = SingleStoreVectorStore(
embeddings=OpenAIEmbeddings(),
host="127.0.0.1:3306/db",
table_name="vector_store"
)
# Add documents to the vector store
documents = [
Document(page_content="The Eiffel Tower is in Paris.", metadata={"category": "landmark"}),
Document(page_content="The Louvre is a famous museum in Paris.", metadata={"category": "museum"})
]
vector_store.add_documents(documents)
# Perform a similarity search
results = vector_store.similarity_search(query="famous landmarks in Paris", k=1)
print(results[0].page_content)
Document Loader
The SingleStoreLoader class allows you to load documents directly from a SingleStore database table. This is useful for applications that need to process large datasets stored in SingleStore.
from langchain_singlestore.document_loaders import SingleStoreLoader
loader = SingleStoreLoader(
host="127.0.0.1:3306/db",
table_name="documents",
content_field="content",
metadata_field="metadata"
)
# Load documents
documents = loader.load()
print(documents[0].page_content)
For detailed documentation, visit the LangChain documentation.
Development and Testing
To set up the development environment and run tests, follow these steps:
Installation
Install all dependencies, including those for linting, typing, and testing, using poetry:
poetry install --with lint,typing,test,test_integration
Linting
Before committing any changes, ensure that the code passes all linting checks. Run the following command:
make lint
This will check the code for style and formatting issues.
Running Tests
Run all integration tests to verify that the code works as expected:
make integration_tests
Note on Integration Tests
The test_add_image2 integration test for SingleStoreVectorStore downloads data to your local machine. The first run may take a significant amount of time due to the data download process. Subsequent runs will be faster as the data will already be available locally.
Contribution
We welcome contributions to the langchain-singlestore project! Please refer to the CONTRIBUTE.md file for detailed guidelines on how to contribute, including instructions for running tests, linting, and publishing new package versions.
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_singlestore-1.1.0.tar.gz.
File metadata
- Download URL: langchain_singlestore-1.1.0.tar.gz
- Upload date:
- Size: 18.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.2 CPython/3.11.14 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5df66736ebabf91d488b08f92738252a47c1ef0b2c53b4317ff79f77a3390661
|
|
| MD5 |
76a9ee52ba3c5d417e9219257f6c4dd3
|
|
| BLAKE2b-256 |
e7fc0db12df1d0a920459b5ed7ffb0f69dd05ee4277d5631df911f1e1811bd9c
|
File details
Details for the file langchain_singlestore-1.1.0-py3-none-any.whl.
File metadata
- Download URL: langchain_singlestore-1.1.0-py3-none-any.whl
- Upload date:
- Size: 23.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.2 CPython/3.11.14 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
82a9c9f14dbd1c279d18c36d8ca21c055eecb1dab2a9acb10a67f983e13bca12
|
|
| MD5 |
d2e48c2ea07c4dcc52a8cb396c6b8445
|
|
| BLAKE2b-256 |
4519b14d139b6bc8052622890f17c1f116757078ba4266e47928870499e0e7dd
|