+ ScyllaDB also supports asynchronous operations, enabling concurrency and leading to better performance. +
+ + ```python async_scylladb.py + import asyncio + import os + + from agno.agent import Agent + from agno.knowledge.embedder.openai import OpenAIEmbedder + from agno.knowledge.knowledge import Knowledge + from agno.models.openai import OpenAIResponses + from agno.vectordb.cassandra import Cassandra + + try: + from cassandra.cluster import Cluster # type: ignore + except (ImportError, ModuleNotFoundError): + raise ImportError( + "Could not import scylla-driver. Install it with: uv pip install scylla-driver cassio" + ) + + SCYLLA_HOST = "127.0.0.1" + SCYLLA_PORT = 9042 + KEYSPACE = "agno_knowledge" + + cluster = Cluster([SCYLLA_HOST], port=SCYLLA_PORT) + session = cluster.connect() + session.execute( + f""" + CREATE KEYSPACE IF NOT EXISTS {KEYSPACE} + WITH REPLICATION = {{ 'class': 'SimpleStrategy', 'replication_factor': 1 }} + AND tablets = {{ 'enabled': false }} + """ + ) + + embedder = OpenAIEmbedder(id="text-embedding-3-small", dimensions=1024) + + knowledge_base = Knowledge( + vector_db=Cassandra( + table_name="recipes", + keyspace=KEYSPACE, + session=session, + embedder=embedder, + ), + ) + + agent = Agent( + model=OpenAIResponses(id="gpt-4o"), + knowledge=knowledge_base, + ) + + if __name__ == "__main__": + asyncio.run( + knowledge_base.ainsert( + url="https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf" + ) + ) + + asyncio.run( + agent.aprint_response("What Thai recipes do you know?", markdown=True) + ) + ``` + +ainsert() and aprint_response() with asyncio.run() for
+ non-blocking operations in high-throughput applications.
+