An integration package connecting Couchbase and LangChain
Project description
langchain-couchbase
This package contains the LangChain integration with Couchbase
Installation
pip install -U langchain-couchbase
Vector Store
CouchbaseVectorStore
class enables the usage of Couchbase for Vector Search.
from langchain_couchbase import CouchbaseSearchVectorStore
To use this in an application:
import getpass
# Constants for the connection
COUCHBASE_CONNECTION_STRING = getpass.getpass(
"Enter the connection string for the Couchbase cluster: "
)
DB_USERNAME = getpass.getpass("Enter the username for the Couchbase cluster: ")
DB_PASSWORD = getpass.getpass("Enter the password for the Couchbase cluster: ")
# Create Couchbase connection object
from datetime import timedelta
from couchbase.auth import PasswordAuthenticator
from couchbase.cluster import Cluster
from couchbase.options import ClusterOptions
auth = PasswordAuthenticator(DB_USERNAME, DB_PASSWORD)
options = ClusterOptions(auth)
cluster = Cluster(COUCHBASE_CONNECTION_STRING, options)
# Wait until the cluster is ready for use.
cluster.wait_until_ready(timedelta(seconds=5))
vector_store = CouchbaseSearchVectorStore(
cluster=cluster,
bucket_name=BUCKET_NAME,
scope_name=SCOPE_NAME,
collection_name=COLLECTION_NAME,
embedding=my_embeddings,
index_name=SEARCH_INDEX_NAME,
)
See a usage example
LLM Caches
CouchbaseCache
Use Couchbase as a cache for prompts and responses.
See a usage example.
To import this cache:
from langchain_couchbase.cache import CouchbaseCache
To use this cache with your LLMs:
from langchain_core.globals import set_llm_cache
cluster = couchbase_cluster_connection_object
set_llm_cache(
CouchbaseCache(
cluster=cluster,
bucket_name=BUCKET_NAME,
scope_name=SCOPE_NAME,
collection_name=COLLECTION_NAME,
)
)
CouchbaseSemanticCache
Semantic caching allows users to retrieve cached prompts based on the semantic similarity between the user input and previously cached inputs. Under the hood it uses Couchbase as both a cache and a vectorstore. The CouchbaseSemanticCache
needs a Search Index defined to work. Please look at the usage example on how to set up the index.
See a usage example.
To import this cache:
from langchain_couchbase.cache import CouchbaseSemanticCache
To use this cache with your LLMs:
from langchain_core.globals import set_llm_cache
# use any embedding provider...
from langchain_openai.Embeddings import OpenAIEmbeddings
embeddings = OpenAIEmbeddings()
cluster = couchbase_cluster_connection_object
set_llm_cache(
CouchbaseSemanticCache(
cluster=cluster,
embedding = embeddings,
bucket_name=BUCKET_NAME,
scope_name=SCOPE_NAME,
collection_name=COLLECTION_NAME,
index_name=INDEX_NAME,
)
)
Chat Message History
Use Couchbase as the storage for your chat messages.
See a usage example.
To use the chat message history in your applications:
from langchain_couchbase.chat_message_histories import CouchbaseChatMessageHistory
message_history = CouchbaseChatMessageHistory(
cluster=cluster,
bucket_name=BUCKET_NAME,
scope_name=SCOPE_NAME,
collection_name=COLLECTION_NAME,
session_id="test-session",
)
message_history.add_user_message("hi!")
📢 Support Policy
We truly appreciate your interest in this project!
This project is community-maintained, which means it's not officially supported by our support team.
If you need help, have found a bug, or want to contribute improvements, the best place to do that is right here — by opening a GitHub issue.
Our support portal is unable to assist with requests related to this project, so we kindly ask that all inquiries stay within GitHub.
Your collaboration helps us all move forward together — thank you!
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
File details
Details for the file langchain_couchbase-0.4.0rc1.tar.gz
.
File metadata
- Download URL: langchain_couchbase-0.4.0rc1.tar.gz
- Upload date:
- Size: 18.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 24f0fb19ea6f35dbad25128775a0aaa4a29481d53e566c34ea3d07f9db688d56 |
|
MD5 | a7f02b7c9bb23abfa11e6264ff7e44fa |
|
BLAKE2b-256 | e8e29651f880381813bc72e58af2b945c86c471d0601099694d95e94efd898a1 |
File details
Details for the file langchain_couchbase-0.4.0rc1-py3-none-any.whl
.
File metadata
- Download URL: langchain_couchbase-0.4.0rc1-py3-none-any.whl
- Upload date:
- Size: 28.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d04c220da28969b0d4b19de5543eb676cd1773e4437fe006a1632306f473093 |
|
MD5 | 6737027c64e2d9bfee33fed98afe526b |
|
BLAKE2b-256 | 69cdf6432f43e5732962c820b629eb9c03dd1971d49e132a1ba741431a66f6a9 |