Weaviate client connection closed after 1 query

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!

Hey @davhoy, thanks for reaching out and supporting Agno. I’ve shared this with the team, we’re working through all requests one by one and will get back to you soon.
If it’s urgent, please let us know. We appreciate your patience!

1 Like

Hi @davhoy , Thanks for raising this issue . We are looking into it and will get to a solution asap.

Hi @davhoy
I was able to run the following cookbooks on my end

Can you please confirm if you have done the local setup for Weaviate ?
You can refer to this doc for the setup Weaviate Agent Knowledge - Agno.
Thanks

Hi thanks for the response. Yes I have weaviate setup per the docs. The first query works as expected when doing:

agent.print_response("How to make Thai curry?", markdown=True)

I get a response from the agent based on the context.
It is the second one that the weaviate connection fails on. So if i reuse the agent and call print_response a second time like this:

agent.print_response("How to make Thai curry?", markdown=True)
agent.print_response("How to make Thai curry?", markdown=True)

The second call gives the error:

ERROR    Error searching for documents: The `WeaviateClient` is closed. Run `client.connect()` to (re)connect!       

If I add in the patch i mentioned above it works (I still see a warning, but it successfully reconnects and retrieves documents).

Let me know if you need more information

Hi @davhoy thanks a lot for raising this! Very valid issue. We’ve raised a fix and will release this with the next version- fix: weaviate-client closed error by kausmeows · Pull Request #3759 · agno-agi/agno · GitHub

Sounds good! Thanks!