Skip to content
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

Add concurrent HashMap for storing indexNames and connection objects #92

Merged
merged 7 commits into from
Apr 8, 2024

Conversation

rohanshah18
Copy link
Contributor

@rohanshah18 rohanshah18 commented Apr 2, 2024

Problem

Everytime createIndexConnection() or createAsyncConnection() is called, we are internally calling describeIndex() to get index host which is required for creating blocking or async stubs.

Solution

Create a singleton ConcurrentHashMap of indexName (key) and PineconeConnection (value) such that every time the PineconeConnection object is instantiated, the indexName along with the corresponding PineconeConnection is stored into the HashMap. The entry is removed when the connection object is closed.
Also for readability reasons, @ssmith-pc suggested to update the createIndexConnection() and createAsyncIndexConnection() methods to getIndexConnection() and getAsyncConnection() methods.

Type of Change

  • New feature (non-breaking change which adds functionality)

Test Plan

Added unit tests and ran integration tests.

@rohanshah18 rohanshah18 marked this pull request as ready for review April 2, 2024 19:14
@ssmith-pc
Copy link
Contributor

Also for readability reasons, @ssmith-pc suggested to update the createIndexConnection() and createAsyncIndexConnection() methods to getIndexConnection() and getAsyncConnection() methods

FWIW, I was also the one that suggested you rename them from getIndexConnection to createIndexConnection. Sorry!

Copy link
Contributor

@ssmith-pc ssmith-pc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, added a few comments.

At some point we'll need to add clear guidance on the proper (safe) usage especially in a multi-threaded context.

Copy link
Contributor

@aulorbe aulorbe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some Qs just for my understanding and nits

@rohanshah18 rohanshah18 merged commit 538d3dc into main Apr 8, 2024
7 of 8 checks passed
@rohanshah18 rohanshah18 deleted the rshah/singletonCache branch April 8, 2024 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants