Build a reusable Pinecone integration module with batch upsert, metadata filtering, namespace management, and hybrid search.
You are a vector database specialist. Create a production-ready Pinecone integration module in Python.
## Configuration
- **Index Name**: [INDEX_NAME]
- **Dimension**: [DIMENSION e.g. 1536 / 3072]
- **Metric**: [METRIC e.g. cosine / dotproduct / euclidean]
- **Cloud/Region**: [CLOUD e.g. aws / gcp] / [REGION e.g. us-east-1]
- **Pod Type**: [POD_TYPE e.g. p2.x1 / s1.x1] (or serverless)
## Module Structure
### `pinecone_client.py` - Core Client
```
class PineconeManager:
- __init__(api_key, environment, index_name)
- create_index(dimension, metric, pod_type, replicas)
- delete_index()
- get_index_stats() -> IndexStats
```
### `embeddings.py` - Embedding Pipeline
- Support multiple embedding providers: OpenAI, Cohere, HuggingFace local
- Batch embedding with configurable batch_size=[BATCH_SIZE e.g. 100]
- Automatic retry with exponential backoff
- Token counting and cost estimation
### `operations.py` - CRUD Operations
- `upsert_documents(docs, namespace, batch_size)` - Parallel batch upsert with progress bar
- `query(vector, top_k, filter, namespace, include_metadata)` - Similarity search with metadata filtering
- `hybrid_query(dense_vector, sparse_vector, alpha)` - Hybrid dense+sparse search
- `delete_by_filter(filter_dict, namespace)` - Conditional deletion
- `fetch_vectors(ids, namespace)` - Direct vector retrieval
- `update_metadata(id, metadata, namespace)` - Metadata-only updates
### `filters.py` - Filter Builder
- Fluent API for building Pinecone metadata filters
- Support $eq, $ne, $gt, $gte, $lt, $lte, $in, $nin operators
- Combine with $and, $or logic
- Type validation for filter values
### `namespaces.py` - Namespace Management
- List all namespaces with vector counts
- Copy vectors between namespaces
- Delete entire namespace
- Namespace-aware backup/restore
Include comprehensive error handling, structured logging, connection pooling, and unit tests with mocked Pinecone responses. Add a CLI tool for common operations.Free to copy and use. Compatible with Claude 4 Opus, GPT-5, Gemini 2.0 Flash, Llama 4 Maverick.
Set your Pinecone API key and index configuration parameters. Install pinecone-client and required embedding libraries. Test with a small dataset before bulk operations.
Initial release
Sign in and download this prompt to leave a review.