Follow steps mentioned in Weaviate setup guide to setup Weaviate.
Setup
Install weaviate packages
pip install weaviate-client
Run weaviate
docker run -d \
-p 8080:8080 \
-p 50051:50051 \
--name weaviate \
cr.weaviate.io/semitechnologies/weaviate:1.28.4
or
./cookbook/scripts/run_weaviate.sh
Example
from agno.agent import Agent
from agno.knowledge.pdf_url import PDFUrlKnowledgeBase
from agno.vectordb.search import SearchType
from agno.vectordb.weaviate import Distance, VectorIndex, Weaviate
vector_db = Weaviate(
collection="recipes",
search_type=SearchType.hybrid,
vector_index=VectorIndex.HNSW,
distance=Distance.COSINE,
local=True, # Set to False if using Weaviate Cloud and True if using local instance
)
# Create knowledge base
knowledge_base = PDFUrlKnowledgeBase(
urls=["https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"],
vector_db=vector_db,
)
knowledge_base.load(recreate=False) # Comment out after first run
# Create and use the agent
agent = Agent(
knowledge=knowledge_base,
search_knowledge=True,
show_tool_calls=True,
)
agent.print_response("How to make Thai curry?", markdown=True)
Async Support ⚡
Weaviate also supports asynchronous operations, enabling concurrency and leading to better performance.
import asyncio
from agno.agent import Agent
from agno.knowledge.pdf_url import PDFUrlKnowledgeBase
from agno.vectordb.search import SearchType
from agno.vectordb.weaviate import Distance, VectorIndex, Weaviate
vector_db = Weaviate(
collection="recipes_async",
search_type=SearchType.hybrid,
vector_index=VectorIndex.HNSW,
distance=Distance.COSINE,
local=True, # Set to False if using Weaviate Cloud and True if using local instance
)
# Create knowledge base
knowledge_base = PDFUrlKnowledgeBase(
urls=["https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"],
vector_db=vector_db,
)
agent = Agent(
knowledge=knowledge_base,
search_knowledge=True,
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))
Weaviate’s async capabilities leverage WeaviateAsyncClient
to provide non-blocking vector operations. This is particularly valuable for applications requiring high concurrency and throughput.
Weaviate Params
Parameter | Type | Description | Default |
---|
wcd_url | Optional[str] | Weaviate Cloud URL (or use WCD_URL env var) | None |
wcd_api_key | Optional[str] | Weaviate Cloud API key (or use WCD_API_KEY env var) | None |
client | Optional[weaviate.WeaviateClient] | Pre-configured Weaviate client | None |
local | bool | Whether to use a local Weaviate instance | False |
collection | str | Name of the Weaviate collection | "default" |
vector_index | VectorIndex | Type of vector index (HNSW, FLAT, DYNAMIC) | VectorIndex.HNSW |
distance | Distance | Distance metric (COSINE, DOT, etc.) | Distance.COSINE |
embedder | Optional[Embedder] | Embedder to use for generating embeddings | OpenAIEmbedder() |
search_type | SearchType | Search type (vector, keyword, hybrid) | SearchType.vector |
reranker | Optional[Reranker] | Reranker to refine search results | None |
hybrid_search_alpha | float | Weighting factor for hybrid search | 0.5 |
Developer Resources