-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
It's not covered in the docs, but I believe the client is thread safe as it uses HttpClient under the covers for everything and that's thread safe.
Can you confirm that the client is indeed thread safe?
If so, I'd recommend adding a "best practices" section to the docs. All of the examples show newing up a client every time. That ends up doing expensive init and dns lookups every time. Reusing a single client (both the base PineconeClient and the IndexClient for an individual index) avoids that several second init.
I'm using something like this:
public class PineconeService
{
static readonly ConcurrentDictionary<string, IndexClient> _indexClients = new();
static readonly string PineconeToken = ConfigurationManager.AppSettings["PineconeToken"];
static readonly Lazy<PineconeClient> _client = new(() => new PineconeClient(PineconeToken));
public static PineconeClient Client => _client.Value;
public static IndexClient GetIndexClient(string indexName)
{
return _indexClients.GetOrAdd(indexName, name => Client.Index(name: name));
}
public static void ClearIndexCache() => _indexClients.Clear();
}Metadata
Metadata
Assignees
Labels
No labels