Skip to main content

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.

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_singlestore-1.0.0.tar.gz (17.7 kB view details)

Uploaded Source

Built Distribution

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

langchain_singlestore-1.0.0-py3-none-any.whl (23.3 kB view details)

Uploaded Python 3

File details

Details for the file langchain_singlestore-1.0.0.tar.gz.

File metadata

  • Download URL: langchain_singlestore-1.0.0.tar.gz
  • Upload date:
  • Size: 17.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.11.11 Linux/6.8.0-1021-azure

File hashes

Hashes for langchain_singlestore-1.0.0.tar.gz
Algorithm Hash digest
SHA256 20cc18ffb2ab1aaaf7ec045482083814eacba6ddfc462e64798bb3d077e61d57
MD5 05d8cb0d4f98905f6831a19ce37c422a
BLAKE2b-256 eae59d2a34680dab223bc935622f76729d69561607d0ec7284f666b5f2ca42d5

See more details on using hashes here.

File details

Details for the file langchain_singlestore-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_singlestore-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 663010e1d06eb228a4c7e99d94dc84550f5e7305932e4c27498820e0dda7c3ec
MD5 15a7f6eaadc3c392aa5f83729edb84be
BLAKE2b-256 c6f3e69efd01fe7e368913b3fe6b41c9f5e5e441eb86c9b4997fd74823b3fe89

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