ChromaDB 也支持异步操作,可以实现并发并带来更好的性能。
# install chromadb - `pip install chromadb`
import asyncio
from agno.agent import Agent
from agno.knowledge.pdf_url import PDFUrlKnowledgeBase
from agno.vectordb.chroma import ChromaDb
# Initialize ChromaDB
vector_db = ChromaDb(collection="recipes", path="tmp/chromadb", persistent_client=True)
# Create knowledge base
knowledge_base = PDFUrlKnowledgeBase(
urls=["https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"],
vector_db=vector_db,
)
# Create and use the agent
agent = Agent(knowledge=knowledge_base, show_tool_calls=True)
if __name__ == "__main__":
# Comment out after first run
asyncio.run(knowledge_base.aload(recreate=False))
# Create and use the agent
asyncio.run(agent.aprint_response("How to make Tom Kha Gai", markdown=True))
在吞吐量高的应用程序中使用 aload() 和 aprint_response() 方法配合 asyncio.run() 进行非阻塞操作。