-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature Request]: Add close() function to chromadb.HttpClient #1865
Comments
@hamasurrehman, thank you for the elaborate description of your problem and possible alternatives. We do have a PR on this #1792. I would appreciate your feedback on it. |
I'm a little confused about the use-case here. I see two possible ways for this to be used:
I don't see much utility in the second case: when the object gets garbage collected it'll close all connections, and that happens relatively quickly. The first case is interesting, though. Chroma server currently defaults to Http/1.1 which has a default |
@beggers, how about proxies? Can they keep the connections open? A user in Discord reported this: tcp 1 0 testing00-alfredg:36892 staging-chromadb.i:8002 CLOSE_WAIT off (0.00/0/0)
tcp 1 0 testing00-alfredg:36412 staging-chromadb.i:8002 CLOSE_WAIT off (0.00/0/0) I think calling On top of that, we can provide a utility context manager. |
Describe the problem
Currently, the
chromadb.HttpClient
class lacks a method for explicitly closing the connection. This omission poses challenges for users in managing resources efficiently and ensuring proper cleanup after using the client. Without a designated way to close connections, users may encounter resource leaks or inefficient resource utilization, particularly in scenarios involving long-lived applications or numerous concurrent connections.Describe the proposed solution
I propose augmenting the
chromadb.HttpClient
class with aclose()
function to facilitate explicit closure of connections. This method would empower users to responsibly manage resources by enabling them to explicitly release connections when they are no longer needed. By integrating aclose()
function, users can uphold best practices for resource management in Python and mitigate potential issues associated with lingering connections.Alternatives considered
Automatic Connection Management: Rather than introducing a
close()
function, an alternative approach could involve implementing automatic connection management within thechromadb.HttpClient
. This would entail the client automatically closing connections after a certain period of inactivity or when they reach a predefined threshold. However, this approach might lack flexibility and could potentially lead to unexpected connection closures, especially in scenarios where users require precise control over connection lifetimes.Context Manager Support: Another option could be to add support for the context manager protocol (
__enter__
and__exit__
methods) to thechromadb.HttpClient
. By implementing this protocol, users could utilize thewith
statement to ensure proper resource cleanup, as connections would be automatically closed upon exiting thewith
block. While this approach offers convenience, it may not fully address cases where users need to explicitly manage connection lifetimes outside of awith
context.Manual Connection Management: Alternatively, users could manually manage connection lifetimes by explicitly calling a
disconnect()
orrelease()
method on thechromadb.HttpClient
to close connections. While this approach provides control over resource cleanup, it relies heavily on user diligence and may increase the risk of overlooking necessary cleanup steps, leading to potential resource leaks or inefficiencies.Importance
i cannot use Chroma without it
Additional Information
This feature would enhance the usability and robustness of the ChromaDB client library, providing users with more control over resource management. It would also contribute to better adherence to Pythonic conventions and standards for database client libraries.
The text was updated successfully, but these errors were encountered: