[PR #49] [MERGED] Fix Pinecone Async Performance Issue with Host Configuration #66

Closed
opened 2026-02-16 07:16:10 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/langchain-ai/langchain-pinecone/pull/49
Author: @bajajku
Created: 6/6/2025
Status: Merged
Merged: 7/23/2025
Merged by: @jamescalam

Base: james/async-perfHead: issue#39


📝 Commits (10+)

  • 7ecebc2 fix: exclude 'truncate' parameter for 'cohere-rerank-3.5' model in rerank functionality. Add respective unit test as well
  • 6ec8360 Merge branch 'main' into main
  • b669426 chore: fix lint issues
  • 00c36f2 fix: apply params
  • bfd1162 feat: add host parameter to PineconeVectorStore to avoid unnecessary sync index creation and improve async index handling
  • 684f1c0 fix: make integration tests more resilient by skipping when credentials are missing
  • 1d2aeb8 Merge branch 'main' into issue#39
  • c97a2cf fix: resolve PineconeEmbeddings validation errors in tests
  • 4c1262e make format
  • 6e39a9f refactor: update Pinecone client initialization to use convert_to_secret_str for API key handling

📊 Changes

5 files changed (+258 additions, -8 deletions)

View changed files

📝 libs/pinecone/README.md (+30 -0)
📝 libs/pinecone/langchain_pinecone/vectorstores.py (+26 -5)
📝 libs/pinecone/langchain_pinecone/vectorstores_sparse.py (+2 -0)
📝 libs/pinecone/tests/integration_tests/test_embeddings.py (+33 -3)
📝 libs/pinecone/tests/unit_tests/test_vectorstores.py (+167 -0)

📄 Description

Pull Request: Fix Pinecone Async Performance Issue with Host Configuration

Description

Fixed a critical performance issue in the Pinecone vector store where async operations were making unnecessary synchronous network calls. The async_index property was calling self.index.config.host on every access, which triggered sync API calls and violated Pinecone's best practices.

Changes made:

  • Added host parameter to constructor for direct host specification
  • Added support for PINECONE_HOST environment variable as fallback
  • Modified initialization logic to avoid creating sync index when host is provided
  • Updated async_index property to use cached host instead of making sync calls
  • Optimized performance by eliminating sync calls in async context

Type

🚀 Performance Enhancement / 🐛 Bug Fix

Testing

Added unit tests to verify:

  • Host parameter avoids unnecessary sync index creation
  • Async operations use cached host without sync calls
  • Proper error handling when no host is available
  • Environment variable fallback functionality

Relevant Issues

Issue #39

Code Changes

# Constructor now accepts host parameter
def __init__(self, ..., host: Optional[str] = None):
    # Store host parameter or get from environment
    self._index_host = host or os.environ.get("PINECONE_HOST")
    
    # Only create sync index if no host is provided
    if not self._index_host:
        client = PineconeClient(api_key=_pinecone_api_key, source_tag="langchain")
        self._index = client.Index(name=_index_name)
        self._index_host = self._index.config.host

# Async index now uses cached host (no sync calls)
@property
def async_index(self) -> _IndexAsyncio:
    if self._async_index is None:
        client = PineconeAsyncioClient(api_key=self._pinecone_api_key, source_tag="langchain")
        host = self._index_host  # Use cached host directly
        if not host:
            raise ValueError("Index host must be available...")
        return client.IndexAsyncio(host=host)
    return self._async_index

Performance Impact

  • Before: Every async operation triggered self.index.config.host sync network call
  • After: Host is cached once during initialization and reused for all async operations
  • Result: Eliminates performance bottleneck and follows Pinecone production best practices

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/langchain-ai/langchain-pinecone/pull/49 **Author:** [@bajajku](https://github.com/bajajku) **Created:** 6/6/2025 **Status:** ✅ Merged **Merged:** 7/23/2025 **Merged by:** [@jamescalam](https://github.com/jamescalam) **Base:** `james/async-perf` ← **Head:** `issue#39` --- ### 📝 Commits (10+) - [`7ecebc2`](https://github.com/langchain-ai/langchain-pinecone/commit/7ecebc264ccc1b96b8c6e408230f4a60a906dd2d) fix: exclude 'truncate' parameter for 'cohere-rerank-3.5' model in rerank functionality. Add respective unit test as well - [`6ec8360`](https://github.com/langchain-ai/langchain-pinecone/commit/6ec83607b7e83d487b539a39577746d88d6add9c) Merge branch 'main' into main - [`b669426`](https://github.com/langchain-ai/langchain-pinecone/commit/b66942632ec8bd1a0f258aebc2d61f8c410f75a5) chore: fix lint issues - [`00c36f2`](https://github.com/langchain-ai/langchain-pinecone/commit/00c36f24be2449f81df81ac19204435db9d60792) fix: apply params - [`bfd1162`](https://github.com/langchain-ai/langchain-pinecone/commit/bfd1162bcac3406aa7028eb4a40332a68822dc21) feat: add host parameter to PineconeVectorStore to avoid unnecessary sync index creation and improve async index handling - [`684f1c0`](https://github.com/langchain-ai/langchain-pinecone/commit/684f1c01a741bdc6c5e06a573ab3c1c4c8dd620e) fix: make integration tests more resilient by skipping when credentials are missing - [`1d2aeb8`](https://github.com/langchain-ai/langchain-pinecone/commit/1d2aeb811788f15ace7f09704dd85b3ac9fc9c4d) Merge branch 'main' into issue#39 - [`c97a2cf`](https://github.com/langchain-ai/langchain-pinecone/commit/c97a2cf44bd859de4febb51f45ed0f6b0f1dbd66) fix: resolve PineconeEmbeddings validation errors in tests - [`4c1262e`](https://github.com/langchain-ai/langchain-pinecone/commit/4c1262ef0423ef9ada2a66c0868b0f68a9b83eff) make format - [`6e39a9f`](https://github.com/langchain-ai/langchain-pinecone/commit/6e39a9faf906fdc259208ab25e4ca3e3c7c3a32d) refactor: update Pinecone client initialization to use convert_to_secret_str for API key handling ### 📊 Changes **5 files changed** (+258 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `libs/pinecone/README.md` (+30 -0) 📝 `libs/pinecone/langchain_pinecone/vectorstores.py` (+26 -5) 📝 `libs/pinecone/langchain_pinecone/vectorstores_sparse.py` (+2 -0) 📝 `libs/pinecone/tests/integration_tests/test_embeddings.py` (+33 -3) 📝 `libs/pinecone/tests/unit_tests/test_vectorstores.py` (+167 -0) </details> ### 📄 Description # Pull Request: Fix Pinecone Async Performance Issue with Host Configuration ## Description Fixed a critical performance issue in the Pinecone vector store where async operations were making unnecessary synchronous network calls. The `async_index` property was calling `self.index.config.host` on every access, which triggered sync API calls and violated Pinecone's best practices. Changes made: - Added `host` parameter to constructor for direct host specification - Added support for `PINECONE_HOST` environment variable as fallback - Modified initialization logic to avoid creating sync index when host is provided - Updated `async_index` property to use cached host instead of making sync calls - Optimized performance by eliminating sync calls in async context ## Type 🚀 Performance Enhancement / 🐛 Bug Fix ## Testing Added unit tests to verify: - Host parameter avoids unnecessary sync index creation - Async operations use cached host without sync calls - Proper error handling when no host is available - Environment variable fallback functionality ## Relevant Issues Issue #39 ## Code Changes ```python # Constructor now accepts host parameter def __init__(self, ..., host: Optional[str] = None): # Store host parameter or get from environment self._index_host = host or os.environ.get("PINECONE_HOST") # Only create sync index if no host is provided if not self._index_host: client = PineconeClient(api_key=_pinecone_api_key, source_tag="langchain") self._index = client.Index(name=_index_name) self._index_host = self._index.config.host # Async index now uses cached host (no sync calls) @property def async_index(self) -> _IndexAsyncio: if self._async_index is None: client = PineconeAsyncioClient(api_key=self._pinecone_api_key, source_tag="langchain") host = self._index_host # Use cached host directly if not host: raise ValueError("Index host must be available...") return client.IndexAsyncio(host=host) return self._async_index ``` ## Performance Impact - **Before**: Every async operation triggered `self.index.config.host` sync network call - **After**: Host is cached once during initialization and reused for all async operations - **Result**: Eliminates performance bottleneck and follows Pinecone production best practices --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-16 07:16:10 -05:00
yindo closed this issue 2026-02-16 07:16:10 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langchain-pinecone#66