Couchbase
Couchbase is an award-winning distributed NoSQL cloud database that delivers unmatched versatility, performance, scalability, and financial value for all of your cloud, mobile, AI, and edge computing applications.
安装与设置
我们必须安装 langchain-couchbase 包。
pip install langchain-couchbase
向量存储
查看一个 使用示例。
from langchain_couchbase import CouchbaseSearchVectorStore
文档加载器
查看一个 使用示例。
from langchain_community.document_loaders.couchbase import CouchbaseLoader
API 参考:CouchbaseLoader
大型语言模型缓存
CouchbaseCache
将 Couchbase 用作提示和响应的缓存。
查看一个 使用示例。
要导入此缓存:
from langchain_couchbase.cache import CouchbaseCache
要将此缓存与您的大语言模型一起使用:
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,
)
)
API 参考:set_llm_cache
CouchbaseSemanticCache
语义缓存允许用户根据用户输入与先前缓存输入之间的语义相似性来检索缓存的提示。其内部使用 Couchbase 作为缓存和向量存储。 CouchbaseSemanticCache 需要定义一个搜索索引才能工作。请查看 使用示例 了解如何设置索引。
查看一个 使用示例。
要导入此缓存:
from langchain_couchbase.cache import CouchbaseSemanticCache
要将此缓存与您的大语言模型一起使用:
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,
)
)
API 参考:set_llm_cache
聊天消息历史记录
将 Couchbase 用作聊天消息的存储。
查看一个 使用示例。
在您的应用程序中使用聊天消息历史记录:
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!")