{"id":9063,"library":"langchain-astradb","title":"LangChain Astra DB Integration","description":"LangChain Astra DB is an integration package that connects DataStax Astra DB with the LangChain framework. It provides components such as a vector store, chat message history, and caching mechanisms, allowing developers to leverage Astra DB's serverless vector capabilities for their GenAI and RAG applications. The library is actively maintained, with a focus on seamless integration and compatibility within the LangChain ecosystem.","status":"active","version":"1.0.0","language":"en","source_language":"en","source_url":"https://github.com/langchain-ai/langchain-datastax","tags":["LangChain","AstraDB","vector store","chat history","caching","database","LLM","RAG","DataStax"],"install":[{"cmd":"pip install langchain-astradb langchain-openai astrapy","lang":"bash","label":"Install with OpenAI and AstraPy"}],"dependencies":[{"reason":"Core LangChain framework, required for building LLM applications.","package":"langchain"},{"reason":"Base abstractions for the LangChain ecosystem, a dependency of LangChain.","package":"langchain-core"},{"reason":"Pythonic client for DataStax Astra DB, used by langchain-astradb for database interactions.","package":"astrapy","optional":false},{"reason":"OpenAI embeddings or chat models, commonly used with vector stores.","package":"langchain-openai","optional":true}],"imports":[{"symbol":"AstraDBVectorStore","correct":"from langchain_astradb import AstraDBVectorStore"},{"symbol":"AstraDBChatMessageHistory","correct":"from langchain_astradb import AstraDBChatMessageHistory"},{"symbol":"AstraDBCache","correct":"from langchain_astradb import AstraDBCache"},{"symbol":"AstraDBSemanticCache","correct":"from langchain_astradb import AstraDBSemanticCache"},{"symbol":"AstraDBLoader","correct":"from langchain_astradb import AstraDBLoader"}],"quickstart":{"code":"import os\nfrom langchain_astradb import AstraDBVectorStore\nfrom langchain_openai import OpenAIEmbeddings\nfrom langchain_core.documents import Document\n\n# Ensure you have your Astra DB credentials and OpenAI API key set as environment variables\nASTRA_DB_API_ENDPOINT = os.environ.get('ASTRA_DB_API_ENDPOINT', 'https://your.api.endpoint')\nASTRA_DB_APPLICATION_TOKEN = os.environ.get('ASTRA_DB_APPLICATION_TOKEN', 'AstraCS:...')\nOPENAI_API_KEY = os.environ.get('OPENAI_API_KEY', 'sk-...')\n\nif not all([ASTRA_DB_API_ENDPOINT, ASTRA_DB_APPLICATION_TOKEN, OPENAI_API_KEY]):\n    print(\"Please set ASTRA_DB_API_ENDPOINT, ASTRA_DB_APPLICATION_TOKEN, and OPENAI_API_KEY environment variables.\")\nelse:\n    print(\"Connecting to Astra DB Vector Store...\")\n    embeddings = OpenAIEmbeddings(api_key=OPENAI_API_KEY)\n    \n    # Initialize the vector store\n    vector_store = AstraDBVectorStore(\n        embedding=embeddings,\n        collection_name=\"my_documents_collection\",\n        api_endpoint=ASTRA_DB_API_ENDPOINT,\n        token=ASTRA_DB_APPLICATION_TOKEN,\n    )\n\n    # Add documents\n    docs = [\n        Document(page_content=\"LangChain provides tools for building LLM applications.\", metadata={\"source\": \"langchain\"}),\n        Document(page_content=\"Astra DB is a serverless vector-capable database.\", metadata={\"source\": \"astradb\"})\n    ]\n    vector_store.add_documents(docs)\n\n    print(f\"Added {len(docs)} documents to the collection.\")\n\n    # Perform a similarity search\n    query = \"What is Astra DB?\"\n    results = vector_store.similarity_search(query, k=1)\n    \n    print(f\"\\nSimilarity search results for '{query}':\")\n    for doc in results:\n        print(f\"- Content: {doc.page_content}, Source: {doc.metadata.get('source')}\")","lang":"python","description":"This quickstart demonstrates how to initialize `AstraDBVectorStore` with OpenAI embeddings, add documents to a collection, and perform a similarity search. Ensure `ASTRA_DB_API_ENDPOINT`, `ASTRA_DB_APPLICATION_TOKEN`, and `OPENAI_API_KEY` are set as environment variables."},"warnings":[{"fix":"Update `langchain` to `0.1.x` or higher, and replace imports like `from langchain_community.vectorstores import AstraDBVectorStore` with `from langchain_astradb import AstraDBVectorStore`. Refer to the official migration guides.","message":"The `langchain-astradb` package replaces deprecated Astra DB classes previously found under `langchain_community.*`. Migrating to the dedicated `langchain-astradb` package is strongly advised for the latest features, fixes, and compatibility with modern `astrapy` versions.","severity":"breaking","affected_versions":"<1.0.0 of langchain-astradb; older versions of langchain"},{"fix":"Ensure the collection is created with compatible settings, or explicitly instruct the vector store not to create the collection if it exists. For example, `AstraDBVectorStore(..., setup_mode=langchain_astradb.utils.astradb.SetupMode.OFF)` will prevent collection creation, using it as-is.","message":"Initializing an `AstraDBVectorStore` on an existing collection may fail if the collection's configuration (e.g., indexing settings, hybrid search enablement) differs from the default or requested settings. The Data API returns an `EXISTING_COLLECTION_DIFFERENT_SETTINGS` error.","severity":"gotcha","affected_versions":"All versions of `langchain-astradb`"},{"fix":"Double-check that all connection parameters are correct and have sufficient permissions. If using an application token, ensure it's correctly provided and not confused with client ID/secret from older `cassandra-driver` setups.","message":"Incorrect or invalid credentials (`ASTRA_DB_API_ENDPOINT`, `ASTRA_DB_APPLICATION_TOKEN`) or issues with the secure bundle path for self-managed Cassandra can lead to connection errors.","severity":"gotcha","affected_versions":"All versions of `langchain-astradb`"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Either delete the existing collection and let `AstraDBVectorStore` create a new one, or pass `setup_mode=langchain_astradb.utils.astradb.SetupMode.OFF` to the `AstraDBVectorStore` constructor to connect to the existing collection without attempting to modify its creation parameters.","cause":"Attempting to create an Astra DB collection with `AstraDBVectorStore` when a collection with the same name already exists but with a different configuration (e.g., vector or hybrid search settings).","error":"Collection 'default_keyspace.my_testing_collection' already exists CollectionAlreadyExistsError: Collection 'default_keyspace.my_testing_collection' already exists"},{"fix":"Verify that `ASTRA_DB_API_ENDPOINT` and `ASTRA_DB_APPLICATION_TOKEN` are copied exactly from your Astra DB console. Check your internet connection and ensure the Astra DB instance is active and reachable.","cause":"This is a generic error often caused by incorrect `ASTRA_DB_API_ENDPOINT` or `ASTRA_DB_APPLICATION_TOKEN`, network issues, or database unavailability.","error":"Unable to connect to Cassandra (AstraDB)"}]}