Astra DB
DataStax Astra DB 是一個以
Apache Cassandra®
為基礎建構的無伺服器向量資料庫,並透過易於使用的 JSON API 便捷地提供使用。
請參閱 DataStax 提供的教學。
安裝與設定
安裝下列 Python 套件
pip install "langchain-astradb>=0.1.0"
取得連線密碼。設定以下環境變數
ASTRA_DB_APPLICATION_TOKEN="TOKEN"
ASTRA_DB_API_ENDPOINT="API_ENDPOINT"
向量儲存庫
from langchain_astradb import AstraDBVectorStore
vector_store = AstraDBVectorStore(
embedding=my_embedding,
collection_name="my_store",
api_endpoint=ASTRA_DB_API_ENDPOINT,
token=ASTRA_DB_APPLICATION_TOKEN,
)
API 參考:AstraDBVectorStore
在範例筆記本中了解更多資訊。
請參閱 DataStax 提供的範例。
聊天訊息歷史記錄
from langchain_astradb import AstraDBChatMessageHistory
message_history = AstraDBChatMessageHistory(
session_id="test-session",
api_endpoint=ASTRA_DB_API_ENDPOINT,
token=ASTRA_DB_APPLICATION_TOKEN,
)
API 參考:AstraDBChatMessageHistory
請參閱使用範例。
LLM 快取
from langchain.globals import set_llm_cache
from langchain_astradb import AstraDBCache
set_llm_cache(AstraDBCache(
api_endpoint=ASTRA_DB_API_ENDPOINT,
token=ASTRA_DB_APPLICATION_TOKEN,
))
API 參考:set_llm_cache | AstraDBCache
在範例筆記本中了解更多資訊(捲動至 Astra DB 章節)。
語意 LLM 快取
from langchain.globals import set_llm_cache
from langchain_astradb import AstraDBSemanticCache
set_llm_cache(AstraDBSemanticCache(
embedding=my_embedding,
api_endpoint=ASTRA_DB_API_ENDPOINT,
token=ASTRA_DB_APPLICATION_TOKEN,
))
API 參考:set_llm_cache | AstraDBSemanticCache
在範例筆記本中了解更多資訊(捲動至適當章節)。
在範例筆記本中了解更多資訊。
文件載入器
from langchain_astradb import AstraDBLoader
loader = AstraDBLoader(
collection_name="my_collection",
api_endpoint=ASTRA_DB_API_ENDPOINT,
token=ASTRA_DB_APPLICATION_TOKEN,
)
API 參考:AstraDBLoader
在範例筆記本中了解更多資訊。
自我查詢檢索器
from langchain_astradb import AstraDBVectorStore
from langchain.retrievers.self_query.base import SelfQueryRetriever
vector_store = AstraDBVectorStore(
embedding=my_embedding,
collection_name="my_store",
api_endpoint=ASTRA_DB_API_ENDPOINT,
token=ASTRA_DB_APPLICATION_TOKEN,
)
retriever = SelfQueryRetriever.from_llm(
my_llm,
vector_store,
document_content_description,
metadata_field_info
)
API 參考:AstraDBVectorStore | SelfQueryRetriever
在範例筆記本中了解更多資訊。
儲存庫
from langchain_astradb import AstraDBStore
store = AstraDBStore(
collection_name="my_kv_store",
api_endpoint=ASTRA_DB_API_ENDPOINT,
token=ASTRA_DB_APPLICATION_TOKEN,
)
API 參考:AstraDBStore
請參閱 AstraDBStore 的 API 參考。
位元組儲存庫
from langchain_astradb import AstraDBByteStore
store = AstraDBByteStore(
collection_name="my_kv_store",
api_endpoint=ASTRA_DB_API_ENDPOINT,
token=ASTRA_DB_APPLICATION_TOKEN,
)
API 參考:AstraDBByteStore
請參閱 AstraDBByteStore 的 API 參考。