haystack-core-integrations
haystack-core-integrations copied to clipboard
Weaviate: make client an external param to WeaviateDocumentStore
Is your feature request related to a problem? Please describe. It is the responsibility of the user to make sure the client connections are closed. However, the client is created inside WeaviateDocumentStore so user may forget this step.
Describe the solution you'd like
Remove all the client related config e.g. url and replace it with a param called client: weaviate.WeaviateClient.
The user will initialize the client outside WeaviateDocumentStore according to their preference and then pass it to WeaviateDocumentStore.
Describe alternatives you've considered
Expect user will remember to run WeaviateDocumentStore(...)._client.close()
Additional context See official docs about closing connections
This is not feasible.
All Document Stores and Components must be serialisable to JSON, in turn all their inputs must be serialisable too.
If we pass the Weaviate Client in the constructor the WeaviateDocumentStore won't be able to support serialization in any case.
I would suggest implementing __del__ if we need to explicitly close the connection.
__del__ isn't a destructor.
If it is not feasible, then I'd rather we document to tell users to run WeaviateDocumentStore(...)._client.close() when they are done. Otherwise, they might encounter weird memory leak bugs.
I know it's not a destructor but it's called when the garbage collection runs for that object. If written properly it can safely close an existing connection. So in my book it's good enough as a failsafe in case the user forgets to explictly close the client or just doesn't want to.
Also I wouldn't tell the user to access the _client field as it's meant to be part of the private interface of the Document Store, we could add an explicit WeaviateDocumentStore.close_connection() though.