Apache Cassandra®는 트랜잭션 애플리케이션 데이터를 저장하는 데 널리 사용되는 데이터베이스입니다. Large Language Model에 함수와 도구가 도입되면서 생성형 AI 애플리케이션에서 기존 데이터를 활용할 수 있는 흥미로운 사용 사례들이 열렸습니다.
Cassandra DB agent 생성에 대한 자세한 내용은 CQL agent cookbook을 참조하세요Cassandra Databasetoolkit은 AI 엔지니어가 Cassandra 데이터와 agent를 효율적으로 통합할 수 있도록 하며, 다음과 같은 기능을 제공합니다:
- 최적화된 쿼리를 통한 빠른 데이터 액세스. 대부분의 쿼리는 한 자릿수 ms 이하로 실행됩니다.
- LLM 추론 능력을 향상시키는 스키마 introspection
- Apache Cassandra®, DataStax Enterprise™, DataStax Astra™를 포함한 다양한 Cassandra 배포와의 호환성
- 현재 toolkit은 SELECT 쿼리와 스키마 introspection 작업으로 제한됩니다. (안전 우선)
Quick Start
cassio라이브러리 설치- 연결할 Cassandra 데이터베이스에 대한 환경 변수 설정
CassandraDatabase초기화toolkit.get_tools()로 agent에 도구 전달- 편히 앉아서 모든 작업이 자동으로 수행되는 것을 지켜보세요
Theory of Operation
Cassandra Query Language (CQL)는 Cassandra 데이터베이스와 상호작용하는 주요 인간 중심 방법입니다. 쿼리 생성 시 어느 정도의 유연성을 제공하지만, Cassandra 데이터 모델링 모범 사례에 대한 지식이 필요합니다. LLM function calling은 agent에게 추론한 후 요청을 충족할 도구를 선택할 수 있는 능력을 제공합니다. LLM을 사용하는 Agent는 적절한 toolkit 또는 toolkit 체인을 선택할 때 Cassandra 특정 로직을 사용하여 추론해야 합니다. 이는 LLM이 하향식 솔루션을 제공하도록 강요될 때 발생하는 무작위성을 줄입니다. LLM이 데이터베이스에 완전히 제한 없이 액세스하도록 하시겠습니까? 네. 아마 아닐 겁니다. 이를 달성하기 위해 agent에 대한 질문을 구성할 때 사용할 prompt를 제공합니다:
You are an Apache Cassandra expert query analysis bot with the following features
and rules:
- You will take a question from the end user about finding specific data in the database.
- You will examine the schema of the database and create a query path.
- You will provide the user with the correct query to find the data they are looking for, showing the steps provided by the query path.
- You will use best practices for querying Apache Cassandra using partition keys and clustering columns.
- Avoid using ALLOW FILTERING in the query.
- The goal is to find a query path, so it may take querying other tables to get to the final answer.
Tools Provided
cassandra_db_schema
연결된 데이터베이스 또는 특정 스키마에 대한 모든 스키마 정보를 수집합니다. Agent가 작업을 결정할 때 중요합니다.
cassandra_db_select_table_data
특정 keyspace와 table에서 데이터를 선택합니다. Agent는 predicate와 반환되는 레코드 수 제한에 대한 매개변수를 전달할 수 있습니다.
cassandra_db_query
매개변수 대신 agent가 완전히 구성한 쿼리 문자열을 받는 cassandra_db_select_table_data의 실험적 대안입니다. 경고: 이는 성능이 떨어지거나(또는 작동하지 않을 수도 있는) 비정상적인 쿼리로 이어질 수 있습니다. 향후 릴리스에서 제거될 수 있습니다. 멋진 작업을 수행한다면 그것도 알고 싶습니다. 알 수 없는 일이죠!
Environment Setup
다음 Python 모듈을 설치하세요:.env file
연결은auto=True 매개변수를 사용하는 cassio를 통해 이루어지며, notebook은 OpenAI를 사용합니다. 이에 따라 .env 파일을 생성해야 합니다.
Cassandra의 경우 다음을 설정하세요:
cassio로 직접 연결할 수도 있습니다.)
Connect to a Cassandra Database
Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.