langchain
langchain copied to clipboard
Adding shared chromaDB client option
This pull request addresses the need to share a single chromadb.Client instance across multiple instances of the Chroma class. By implementing a shared client, we can maintain consistency and reduce resource usage when multiple instances of the Chroma classes are created. This is especially relevant in a web app, where having multiple Chroma instances with a persist_directory leads to these clients not being synced.
This PR implements this option while keeping the rest of the architecture unchanged.
Changes:
- Add a client attribute to the
Chromaclass to store the sharedchromadb.Clientinstance. - Modify the
from_documentsmethod to accept an optional client parameter. - Update the
from_documentsmethod to use the shared client if provided or create a new client if not provided.
Let me know if anything needs to be modified - thanks again for your work on this incredible repo