pinecone.config.pinecone_config

 1from typing import Optional, Dict
 2import logging
 3import json
 4import os
 5from .config import ConfigBuilder, Config
 6
 7logger = logging.getLogger(__name__)
 8
 9DEFAULT_CONTROLLER_HOST = "https://api.pinecone.io"
10
11
12class PineconeConfig:
13    @staticmethod
14    def build(
15        api_key: Optional[str] = None,
16        host: Optional[str] = None,
17        additional_headers: Optional[Dict[str, str]] = {},
18        **kwargs,
19    ) -> Config:
20        host = (
21            host
22            or kwargs.get("host")
23            or os.getenv("PINECONE_CONTROLLER_HOST")
24            or DEFAULT_CONTROLLER_HOST
25        )
26        headers_json = os.getenv("PINECONE_ADDITIONAL_HEADERS")
27        if headers_json:
28            try:
29                headers = json.loads(headers_json)
30                additional_headers = additional_headers or headers
31            except Exception as e:
32                logger.warn(f"Ignoring PINECONE_ADDITIONAL_HEADERS: {e}")
33
34        return ConfigBuilder.build(
35            api_key=api_key, host=host, additional_headers=additional_headers, **kwargs
36        )
logger = <Logger pinecone.config.pinecone_config (WARNING)>
DEFAULT_CONTROLLER_HOST = 'https://api.pinecone.io'
class PineconeConfig:
13class PineconeConfig:
14    @staticmethod
15    def build(
16        api_key: Optional[str] = None,
17        host: Optional[str] = None,
18        additional_headers: Optional[Dict[str, str]] = {},
19        **kwargs,
20    ) -> Config:
21        host = (
22            host
23            or kwargs.get("host")
24            or os.getenv("PINECONE_CONTROLLER_HOST")
25            or DEFAULT_CONTROLLER_HOST
26        )
27        headers_json = os.getenv("PINECONE_ADDITIONAL_HEADERS")
28        if headers_json:
29            try:
30                headers = json.loads(headers_json)
31                additional_headers = additional_headers or headers
32            except Exception as e:
33                logger.warn(f"Ignoring PINECONE_ADDITIONAL_HEADERS: {e}")
34
35        return ConfigBuilder.build(
36            api_key=api_key, host=host, additional_headers=additional_headers, **kwargs
37        )
@staticmethod
def build( api_key: Optional[str] = None, host: Optional[str] = None, additional_headers: Optional[Dict[str, str]] = {}, **kwargs) -> pinecone.config.config.Config:
14    @staticmethod
15    def build(
16        api_key: Optional[str] = None,
17        host: Optional[str] = None,
18        additional_headers: Optional[Dict[str, str]] = {},
19        **kwargs,
20    ) -> Config:
21        host = (
22            host
23            or kwargs.get("host")
24            or os.getenv("PINECONE_CONTROLLER_HOST")
25            or DEFAULT_CONTROLLER_HOST
26        )
27        headers_json = os.getenv("PINECONE_ADDITIONAL_HEADERS")
28        if headers_json:
29            try:
30                headers = json.loads(headers_json)
31                additional_headers = additional_headers or headers
32            except Exception as e:
33                logger.warn(f"Ignoring PINECONE_ADDITIONAL_HEADERS: {e}")
34
35        return ConfigBuilder.build(
36            api_key=api_key, host=host, additional_headers=additional_headers, **kwargs
37        )