Query Cassandra Data with LLMs
A LlamaIndex toolkit that lets LLM agents safely query Apache Cassandra, DataStax Enterprise, and Astra databases via schema-aware tools.
Maintainer of this project? Claim this page to edit the listing.
0.14.23Add to Favorites
Why it matters
Enable Large Language Models to efficiently and safely interact with Apache Cassandra databases, including various deployments like DataStax Enterprise and Astra.
Outcomes
What it gets done
Fetch schema information for LLM reasoning.
Select data from specified Cassandra tables.
Execute custom CQL queries via LLM invocation.
Ensure fast data access with optimized queries.
Install
Add it to your toolbox
Run in your project directory:
curl -fsSL https://spark.entire.vc/get/li-tool-tools-cassandra | bash Overview
Cassandra Database Tools
A LlamaIndex toolkit that lets LLM agents safely query Apache Cassandra, DataStax Enterprise, and Astra databases via schema-aware, SELECT-only tools. Use it when an agent needs read access to Cassandra-family data with schema awareness - not for write operations, which the toolkit intentionally excludes.
What it does
Integrates LLMs with Apache Cassandra data - including DataStax Enterprise and DataStax Astra deployments - through a safety-scoped toolkit: fast, optimized queries that typically complete in milliseconds, schema introspection that gives the LLM detailed schema context to reason about, and safety measures that limit operations to SELECT queries and schema introspection to protect data integrity. It exposes three tools: cassandra_db_schema (fetches schema information the agent needs to operate), cassandra_db_select_table_data (selects data from a specific keyspace and table), and an experimental cassandra_db_query that accepts fully formed query strings from the agent. Query-path determination runs through CQL (Cassandra Query Language), and the LLM invokes these functions rather than composing custom queries by hand, giving faster and more efficient data access than freeform querying.
When to use - and when NOT to
Use it when an agent needs read access to Cassandra, DataStax Enterprise, or DataStax Astra data with schema-aware querying - not for write operations, since the toolkit intentionally restricts itself to SELECT queries and schema introspection.
Inputs and outputs
Input is Cassandra or Astra connection configuration - contact points and credentials, or an Astra application token and database ID - plus the agent's natural-language request. Output is schema information, selected table data, or query results returned to the agent for reasoning.
Integrations
Built on cassio and llama-index-tools-cassandra, connecting to Apache Cassandra via CASSANDRA_CONTACT_POINTS/CASSANDRA_USERNAME/CASSANDRA_PASSWORD/CASSANDRA_KEYSPACE or to DataStax Astra via ASTRA_DB_APPLICATION_TOKEN/ASTRA_DB_DATABASE_ID/ASTRA_DB_KEYSPACE, configured through a .env file.
Who it's for
For AI engineers building LlamaIndex agents that need efficient, safe access to Cassandra-family databases without letting the LLM write arbitrary destructive queries - it is designed to work with an already-initialized CassandraDatabase object, which the agent's tools operate against rather than opening their own connections.
pip install python-dotenv cassio llama-index-tools-cassandra
Source README
Cassandra Database Tools
Overview
The Cassandra Database Tools project is designed to help AI engineers efficiently integrate Large Language Models (LLMs) with Apache Cassandra® data. It facilitates optimized and safe interactions with Cassandra databases, supporting various deployments like Apache Cassandra®, DataStax Enterprise™, and DataStax Astra™.
Key Features
- Fast Data Access: Optimized queries ensure most operations complete in milliseconds.
- Schema Introspection: Enhances the reasoning capabilities of LLMs by providing detailed schema information.
- Compatibility: Supports various Cassandra deployments, ensuring wide applicability.
- Safety Measures: Limits operations to SELECT queries and schema introspection to prioritize data integrity.
Installation
Ensure your system has Python installed and proceed with the following installations via pip:
pip install python-dotenv cassio llama-index-tools-cassandra
Create a .env file for environmental variables related to Cassandra and Astra configurations, following the example structure provided in the notebook.
Environment Setup
- For Cassandra: Configure
CASSANDRA_CONTACT_POINTS,CASSANDRA_USERNAME,CASSANDRA_PASSWORD, andCASSANDRA_KEYSPACE. - For DataStax Astra: Set
ASTRA_DB_APPLICATION_TOKEN,ASTRA_DB_DATABASE_ID, andASTRA_DB_KEYSPACE.
How It Works
The toolkit leverages the Cassandra Query Language (CQL) and integrates with LLMs to provide an efficient query path determination for the user's requests, ensuring best practices for querying are followed. Using functions, the LLMs decision making can invoke the tool instead of designing custom queries. The result is faster and efficient access to Cassandra data for agents.
Tools Included
cassandra_db_schema: Fetches schema information, essential for the agent’s operation.cassandra_db_select_table_data: Allows selection of data from a specific keyspace and table.cassandra_db_query: An experimental tool that accepts fully formed query strings from the agent.
Example Usage
Initialize the CassandraDatabase and set up the agent with the tools provided. Query the database by interacting with the agent as shown in the example notebook.
FAQ
Common questions
Discussion
Questions & comments · 0
Sign In Sign in to leave a comment.