Skip to main content

A pipeline to transfer documents from Elasticsearch to Pinecone with threading support

Project description

ES to Pinecone Transfer Pipeline

A Python package for transferring documents from Elasticsearch to Pinecone with threading support for faster operations.

Features

  • Transfer documents from Elasticsearch to Pinecone with minimal configuration
  • Support for multiple embedding providers (OpenAI, HuggingFace)
  • Multi-threaded processing for faster operations
  • Configurable batch sizes and field selection
  • Progress tracking with tqdm
  • Comprehensive error handling

Installation

pip install es-to-pinecone-transfer

Quick Start

  1. Create a .env file with your configuration (see .env.example for reference)

  2. Use the pipeline directly in your code:

from es_to_pinecone_transfer.pipeline import ElasticsearchToPineconePipeline

# Initialize and run the pipeline
pipeline = ElasticsearchToPineconePipeline()
pipeline.run()
  1. Or use the command-line interface:
es-to-pinecone

Configuration

The pipeline can be configured using environment variables. Here are the key settings:

Elasticsearch Configuration

  • ES_HOST: Elasticsearch host URL
  • ES_USERNAME: Elasticsearch username (optional)
  • ES_PASSWORD: Elasticsearch password (optional)
  • ES_API_KEY: Elasticsearch API key (optional, preferred over username/password)
  • ES_INDEX: Source index name

Embedding Configuration

  • EMBEDDING_TYPE: Type of embedding to use (openai/huggingface/custom)
  • OPENAI_API_KEY: OpenAI API key (if using OpenAI embeddings)
  • OPENAI_MODEL: OpenAI model to use for embeddings
  • HUGGINGFACE_MODEL: HuggingFace model to use (if using HuggingFace)

Pinecone Configuration

  • PINECONE_API_KEY: Pinecone API key
  • PINECONE_ENVIRONMENT: Pinecone environment
  • PINECONE_INDEX_NAME: Target Pinecone index name

Pipeline Configuration

  • BATCH_SIZE: Number of documents to process in each batch
  • MAX_THREADS: Maximum number of threads to use
  • FIELDS_TO_EMBED: Comma-separated list of fields to embed from ES documents
  • METADATA_FIELDS: Comma-separated list of fields to include as metadata
  • DEFAULT_NAMESPACE: Pinecone namespace to use

Advanced Usage

Custom Field Mapping

from es_to_pinecone_transfer.pipeline import ElasticsearchToPineconePipeline

pipeline = ElasticsearchToPineconePipeline()
pipeline.set_field_mapping({
    'title': 'headline',
    'content': 'body',
    'author': 'writer',
    'timestamp': 'date'
})
pipeline.run()

Progress Callbacks

def on_batch_complete(batch_number, total_batches):
    print(f"Completed batch {batch_number} of {total_batches}")

pipeline = ElasticsearchToPineconePipeline()
pipeline.set_progress_callback(on_batch_complete)
pipeline.run()

Error Handling

The pipeline provides comprehensive error handling:

try:
    pipeline = ElasticsearchToPineconePipeline()
    pipeline.run()
except ElasticsearchConnectionError as e:
    print(f"Elasticsearch connection failed: {e}")
except PineconeConnectionError as e:
    print(f"Pinecone connection failed: {e}")
except EmbeddingError as e:
    print(f"Embedding generation failed: {e}")
except Exception as e:
    print(f"Unexpected error: {e}")

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

es_to_pinecone_transfer-0.1.0.tar.gz (18.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

es_to_pinecone_transfer-0.1.0-py3-none-any.whl (21.5 kB view details)

Uploaded Python 3

File details

Details for the file es_to_pinecone_transfer-0.1.0.tar.gz.

File metadata

  • Download URL: es_to_pinecone_transfer-0.1.0.tar.gz
  • Upload date:
  • Size: 18.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.6

File hashes

Hashes for es_to_pinecone_transfer-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e26f32c15bb40dfbccb5d1e961691a44784171f696ce66b11ffea972f0314454
MD5 051acfc88383f3edd29ed07abe5ef042
BLAKE2b-256 dde66d95fd3272352655a42098080ee5c628fa44296ca3d3ade447993e74e17f

See more details on using hashes here.

File details

Details for the file es_to_pinecone_transfer-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for es_to_pinecone_transfer-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 de712f33095ab398101416c89b069d836f2b01ef8122cb536f15668877583b19
MD5 bbe0cd86ad236183e584a652f698f45f
BLAKE2b-256 73f27f3cec20ffa79e53ea53f1364f2bf98ec8e9e43981e7a0c3c8a762273697

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page