Couchbase는 수상 경력이 있는 분산 NoSQL 클라우드 데이터베이스로, 모든 클라우드, 모바일, AI 및 엣지 컴퓨팅 애플리케이션을 위한 탁월한 다양성, 성능, 확장성 및 경제적 가치를 제공합니다.

Installation and Setup

langchain-couchbase 패키지를 설치해야 합니다.
pip install langchain-couchbase

Vector Store

사용 예제를 참조하세요.
from langchain_couchbase import CouchbaseSearchVectorStore

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,
)

# Add documents
texts = ["Couchbase is a NoSQL database", "LangChain is a framework for LLM applications"]
vectorstore.add_texts(texts)

# Search
query = "What is Couchbase?"
docs = vectorstore.similarity_search(query)
API Reference: CouchbaseSearchVectorStore

Document loader

사용 예제를 참조하세요.
from langchain_community.document_loaders.couchbase import CouchbaseLoader

connection_string = "couchbase://localhost"  # valid Couchbase connection string
db_username = (
    "Administrator"  # valid database user with read access to the bucket being queried
)
db_password = "Password"  # password for the database user

# query is a valid SQL++ query
query = """
    SELECT h.* FROM `travel-sample`.inventory.hotel h
        WHERE h.country = 'United States'
        LIMIT 1
        """

loader = CouchbaseLoader(
    connection_string,
    db_username,
    db_password,
    query,
)

docs = loader.load()

LLM Caches

CouchbaseCache

프롬프트와 응답을 위한 캐시로 Couchbase를 사용합니다. 이 캐시를 import하려면:
from langchain_couchbase.cache import CouchbaseCache
LLM에서 이 캐시를 사용하려면:
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 Reference: CouchbaseCache

CouchbaseSemanticCache

Semantic caching을 사용하면 사용자 입력과 이전에 캐시된 입력 간의 의미적 유사성을 기반으로 캐시된 프롬프트를 검색할 수 있습니다. 내부적으로 Couchbase를 캐시와 vectorstore로 모두 사용합니다. CouchbaseSemanticCache가 작동하려면 Search Index가 정의되어 있어야 합니다. 인덱스 설정 방법은 사용 예제를 참조하세요. 이 캐시를 import하려면:
from langchain_couchbase.cache import CouchbaseSemanticCache
LLM에서 이 캐시를 사용하려면:
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 Reference: CouchbaseSemanticCache
Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.
I