Hi all, I am seeing an issue with the weaviate client - after every query the connection is closed but never reestablished. Reproducible example:
from agno.agent.agent import Agent
from agno.embedder.ollama import OllamaEmbedder
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='test',
search_type=SearchType.hybrid,
vector_index=VectorIndex.HNSW,
distance=Distance.COSINE,
embedder=OllamaEmbedder(id="mxbai-embed-large", dimensions=1024),
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)
# Create and use the agent
agent = Agent(
model=get_model(agno=True), # Just an AzureOpenAI instance
knowledge=knowledge_base,
search_knowledge=True,
show_tool_calls=True,
)
agent.print_response("How to make Thai curry?", markdown=True)
agent.print_response("How to make Thai curry?", markdown=True)
The first agent query works as expected, but the second fails on the knowledge tool call with:
ERROR Error searching for documents: The `WeaviateClient` is closed. Run `client.connect()` to (re)connect!
Quick fix could be in the get_client() of the weaviate class. Changing:
if self.client is not None:
return self.client
to:
if self.client is not None:
if not self.client.is_ready():
self.client.connect()
return self.client
If I am missing something with how a weaviate instance should be reused please let me know!