# langchain-astradb
This package contains the LangChain integrations for using DataStax Astra DB.
> DataStax [Astra DB](https://docs.datastax.com/en/astra/home/astra.html) is a serverless vector-capable database built on Apache Cassandra® and made conveniently available
> through an easy-to-use JSON API.
## Installation and Setup
Installation of this partner package:
```bash
pip install langchain-astradb
```
## Integrations overview
See the [LangChain docs page](https://python.langchain.com/docs/integrations/providers/astradb) and the [API reference](https://api.python.langchain.com/en/latest/astradb_api_reference.html) for more details.
### Vector Store
```python
from langchain_astradb import AstraDBVectorStore
my_store = AstraDBVectorStore(
embedding=my_embedding,
collection_name="my_store",
api_endpoint="https://...",
token="AstraCS:...",
)
```
### Chat message history
```python
from langchain_astradb import AstraDBChatMessageHistory
message_history = AstraDBChatMessageHistory(
session_id="test-session",
api_endpoint="https://...",
token="AstraCS:...",
)
```
### LLM Cache
```python
from langchain_astradb import AstraDBCache
cache = AstraDBCache(
api_endpoint="https://...",
token="AstraCS:...",
)
```
### Semantic LLM Cache
```python
from langchain_astradb import AstraDBSemanticCache
cache = AstraDBSemanticCache(
embedding=my_embedding,
api_endpoint="https://...",
token="AstraCS:...",
)
```
### Document loader
```python
from langchain_astradb import AstraDBLoader
loader = AstraDBLoader(
collection_name="my_collection",
api_endpoint="https://...",
token="AstraCS:...",
)
```
### Store
```python
from langchain_astradb import AstraDBStore
store = AstraDBStore(
collection_name="my_kv_store",
api_endpoint="https://...",
token="AstraCS:...",
)
```
### Byte Store
```python
from langchain_astradb import AstraDBByteStore
store = AstraDBByteStore(
collection_name="my_kv_store",
api_endpoint="https://...",
token="AstraCS:...",
)
```
## Warnings about indexing
When creating an Astra DB object in LangChain, such as an `AstraDBVectorStore`, you may see a warning similar to the following:
> Astra DB collection '...' is detected as having indexing turned on for all fields (either created manually or by older versions of this plugin). This implies stricter limitations on the amount of text each string in a document can store. Consider reindexing anew on a fresh collection to be able to store longer texts.
The reason for the warning is that the requested collection already exists on the database, and it is configured to [index all of its fields for search](https://docs.datastax.com/en/astra-db-serverless/api-reference/collections.html#the-indexing-option), possibly implicitly, by default. When the LangChain object tries to create it, it attempts to enforce, instead, an indexing policy tailored to the prospected usage. For example, the LangChain vector store will index the metadata but leave the textual content out: this is both to enable storing very long texts and to avoid indexing fields that will never be used in filtering a search (indexing those would also have a slight performance cost for writes).
Typically there are two reasons why you may encounter the warning:
1. you have created a collection by other means than letting the `AstraDBVectorStore` do it for you: for example, through the Astra UI, or using AstraPy's `create_collection` method of class `Database` directly;
2. you have created the collection with a version of the Astra DB plugin that is not up-to-date (i.e. prior to the `langchain-astradb` partner package).
Keep in mind that this is a warning and your application will continue running just fine, as long as you don't store very long texts.
Should you need to add to a vector store, for example, a `Document` whose `page_content` exceeds ~8K in length, you will receive an indexing error from the database.
### Remediation
You have several options:
- you can ignore the warning because you know your application will never need to store very long textual contents;
- you can ignore the warning and explicitly instruct the plugin _not to_ create the collection, assuming it exists already (which suppresses the warning): `store = AstraDBVectorStore(..., setup_mode=langchain_astradb.utils.astradb.SetupMode.OFF)`. In this case the collection will be used as-is, no (indexing) questions asked;
- if you can afford populating the collection anew, you can drop it and re-run the LangChain application: the collection will be created with the optimized indexing settings. **This is the recommended option, when possible**.
Raw data
{
"_id": null,
"home_page": "https://github.com/langchain-ai/langchain-datastax",
"name": "langchain-astradb",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.9",
"maintainer_email": null,
"keywords": null,
"author": null,
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/c5/0e/6fc78ecc3af34cd044f97c5fd14ebde318920cdb9d2a0106e1ec194c42c9/langchain_astradb-0.5.3.tar.gz",
"platform": null,
"description": "# langchain-astradb\n\nThis package contains the LangChain integrations for using DataStax Astra DB.\n\n> DataStax [Astra DB](https://docs.datastax.com/en/astra/home/astra.html) is a serverless vector-capable database built on Apache Cassandra\u00ae and made conveniently available\n> through an easy-to-use JSON API.\n\n## Installation and Setup\n\nInstallation of this partner package:\n\n```bash\npip install langchain-astradb\n```\n\n## Integrations overview\n\nSee the [LangChain docs page](https://python.langchain.com/docs/integrations/providers/astradb) and the [API reference](https://api.python.langchain.com/en/latest/astradb_api_reference.html) for more details.\n\n### Vector Store\n\n```python\nfrom langchain_astradb import AstraDBVectorStore\n\nmy_store = AstraDBVectorStore(\n embedding=my_embedding,\n collection_name=\"my_store\",\n api_endpoint=\"https://...\",\n token=\"AstraCS:...\",\n)\n```\n\n### Chat message history\n\n```python\nfrom langchain_astradb import AstraDBChatMessageHistory\n\nmessage_history = AstraDBChatMessageHistory(\n session_id=\"test-session\",\n api_endpoint=\"https://...\",\n token=\"AstraCS:...\",\n)\n```\n\n### LLM Cache\n\n```python\nfrom langchain_astradb import AstraDBCache\n\ncache = AstraDBCache(\n api_endpoint=\"https://...\",\n token=\"AstraCS:...\",\n)\n```\n\n### Semantic LLM Cache\n\n```python\nfrom langchain_astradb import AstraDBSemanticCache\n\ncache = AstraDBSemanticCache(\n embedding=my_embedding,\n api_endpoint=\"https://...\",\n token=\"AstraCS:...\",\n)\n```\n\n### Document loader\n\n```python\nfrom langchain_astradb import AstraDBLoader\n\nloader = AstraDBLoader(\n collection_name=\"my_collection\",\n api_endpoint=\"https://...\",\n token=\"AstraCS:...\",\n)\n```\n\n### Store\n\n```python\nfrom langchain_astradb import AstraDBStore\n\nstore = AstraDBStore(\n collection_name=\"my_kv_store\",\n api_endpoint=\"https://...\",\n token=\"AstraCS:...\",\n)\n```\n\n### Byte Store\n\n```python\nfrom langchain_astradb import AstraDBByteStore\n\nstore = AstraDBByteStore(\n collection_name=\"my_kv_store\",\n api_endpoint=\"https://...\",\n token=\"AstraCS:...\",\n)\n```\n\n## Warnings about indexing\n\nWhen creating an Astra DB object in LangChain, such as an `AstraDBVectorStore`, you may see a warning similar to the following:\n\n> Astra DB collection '...' is detected as having indexing turned on for all fields (either created manually or by older versions of this plugin). This implies stricter limitations on the amount of text each string in a document can store. Consider reindexing anew on a fresh collection to be able to store longer texts.\n\nThe reason for the warning is that the requested collection already exists on the database, and it is configured to [index all of its fields for search](https://docs.datastax.com/en/astra-db-serverless/api-reference/collections.html#the-indexing-option), possibly implicitly, by default. When the LangChain object tries to create it, it attempts to enforce, instead, an indexing policy tailored to the prospected usage. For example, the LangChain vector store will index the metadata but leave the textual content out: this is both to enable storing very long texts and to avoid indexing fields that will never be used in filtering a search (indexing those would also have a slight performance cost for writes).\n\nTypically there are two reasons why you may encounter the warning:\n\n1. you have created a collection by other means than letting the `AstraDBVectorStore` do it for you: for example, through the Astra UI, or using AstraPy's `create_collection` method of class `Database` directly;\n2. you have created the collection with a version of the Astra DB plugin that is not up-to-date (i.e. prior to the `langchain-astradb` partner package).\n\nKeep in mind that this is a warning and your application will continue running just fine, as long as you don't store very long texts.\nShould you need to add to a vector store, for example, a `Document` whose `page_content` exceeds ~8K in length, you will receive an indexing error from the database.\n\n### Remediation\n\nYou have several options:\n\n- you can ignore the warning because you know your application will never need to store very long textual contents;\n- you can ignore the warning and explicitly instruct the plugin _not to_ create the collection, assuming it exists already (which suppresses the warning): `store = AstraDBVectorStore(..., setup_mode=langchain_astradb.utils.astradb.SetupMode.OFF)`. In this case the collection will be used as-is, no (indexing) questions asked;\n- if you can afford populating the collection anew, you can drop it and re-run the LangChain application: the collection will be created with the optimized indexing settings. **This is the recommended option, when possible**.\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "An integration package connecting Astra DB and LangChain",
"version": "0.5.3",
"project_urls": {
"Homepage": "https://github.com/langchain-ai/langchain-datastax",
"Repository": "https://github.com/langchain-ai/langchain-datastax",
"Source Code": "https://github.com/langchain-ai/langchain-datastax/tree/main/libs/astradb"
},
"split_keywords": [],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "9493469c6ef15198148df9309c7426a657c457d63e24ebb4af7182f49b5949d5",
"md5": "ad1727b1b4b622b6a317d58bf47b3098",
"sha256": "42b1baf690270d160caf90b6cbdb82e43e4ab224f3b2b6ffcb57bcd7d23bf265"
},
"downloads": -1,
"filename": "langchain_astradb-0.5.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "ad1727b1b4b622b6a317d58bf47b3098",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.9",
"size": 58672,
"upload_time": "2025-02-04T22:13:39",
"upload_time_iso_8601": "2025-02-04T22:13:39.758580Z",
"url": "https://files.pythonhosted.org/packages/94/93/469c6ef15198148df9309c7426a657c457d63e24ebb4af7182f49b5949d5/langchain_astradb-0.5.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "c50e6fc78ecc3af34cd044f97c5fd14ebde318920cdb9d2a0106e1ec194c42c9",
"md5": "5976eff84ef21dfa011f2c256834c5e9",
"sha256": "c9b05d6288d645416c9e867cb86d90d8ff15a679f50941dd59ffdf18d7dc1d27"
},
"downloads": -1,
"filename": "langchain_astradb-0.5.3.tar.gz",
"has_sig": false,
"md5_digest": "5976eff84ef21dfa011f2c256834c5e9",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.9",
"size": 52093,
"upload_time": "2025-02-04T22:13:41",
"upload_time_iso_8601": "2025-02-04T22:13:41.424113Z",
"url": "https://files.pythonhosted.org/packages/c5/0e/6fc78ecc3af34cd044f97c5fd14ebde318920cdb9d2a0106e1ec194c42c9/langchain_astradb-0.5.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-02-04 22:13:41",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "langchain-ai",
"github_project": "langchain-datastax",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "langchain-astradb"
}