pinecone.grpc.pinecone
1from ..control.pinecone import Pinecone 2from ..config.config import ConfigBuilder 3from .index_grpc import GRPCIndex 4 5 6class PineconeGRPC(Pinecone): 7 """ 8 An alternative version of the Pinecone client that uses gRPC instead of HTTP for 9 data operations. 10 11 ### Installing the gRPC client 12 13 You must install extra dependencies in order to install the GRPC client. 14 15 #### Installing with pip 16 17 ```bash 18 # Install the latest version 19 pip3 install pinecone[grpc] 20 21 # Install a specific version 22 pip3 install "pinecone[grpc]"==3.0.0 23 ``` 24 25 #### Installing with poetry 26 27 ```bash 28 # Install the latest version 29 poetry add pinecone --extras grpc 30 31 # Install a specific version 32 poetry add pinecone==3.0.0 --extras grpc 33 ``` 34 35 ### Using the gRPC client 36 37 ```python 38 import os 39 from pinecone.grpc import PineconeGRPC 40 41 client = PineconeGRPC(api_key=os.environ.get("PINECONE_API_KEY")) 42 43 # From this point on, usage is identical to the HTTP client. 44 index = client.Index("my-index", host=os.environ("PINECONE_INDEX_HOST")) 45 index.query(...) 46 ``` 47 48 """ 49 50 def Index(self, name: str = "", host: str = "", **kwargs): 51 """ 52 Target an index for data operations. 53 54 ### Target an index by host url 55 56 In production situations, you want to uspert or query your data as quickly 57 as possible. If you know in advance the host url of your index, you can 58 eliminate a round trip to the Pinecone control plane by specifying the 59 host of the index. 60 61 ```python 62 import os 63 from pinecone.grpc import PineconeGRPC 64 65 api_key = os.environ.get("PINECONE_API_KEY") 66 index_host = os.environ.get("PINECONE_INDEX_HOST") 67 68 pc = PineconeGRPC(api_key=api_key) 69 index = pc.Index(host=index_host) 70 71 # Now you're ready to perform data operations 72 index.query(vector=[...], top_k=10) 73 ``` 74 75 To find your host url, you can use the Pinecone control plane to describe 76 the index. The host url is returned in the response. Or, alternatively, the 77 host is displayed in the Pinecone web console. 78 79 ```python 80 import os 81 from pinecone import Pinecone 82 83 pc = Pinecone( 84 api_key=os.environ.get("PINECONE_API_KEY") 85 ) 86 87 host = pc.describe_index('index-name').host 88 ``` 89 90 ### Target an index by name (not recommended for production) 91 92 For more casual usage, such as when you are playing and exploring with Pinecone 93 in a notebook setting, you can also target an index by name. If you use this 94 approach, the client may need to perform an extra call to the Pinecone control 95 plane to get the host url on your behalf to get the index host. 96 97 The client will cache the index host for future use whenever it is seen, so you 98 will only incur the overhead of only one call. But this approach is not 99 recommended for production usage. 100 101 ```python 102 import os 103 from pinecone import ServerlessSpec 104 from pinecone.grpc import PineconeGRPC 105 106 api_key = os.environ.get("PINECONE_API_KEY") 107 108 pc = PineconeGRPC(api_key=api_key) 109 pc.create_index( 110 name='my-index', 111 dimension=1536, 112 metric='cosine', 113 spec=ServerlessSpec(cloud='aws', region='us-west-2') 114 ) 115 index = pc.Index('my-index') 116 117 # Now you're ready to perform data operations 118 index.query(vector=[...], top_k=10) 119 ``` 120 """ 121 if name == "" and host == "": 122 raise ValueError("Either name or host must be specified") 123 124 # Use host if it is provided, otherwise get host from describe_index 125 index_host = host or self.index_host_store.get_host(self.index_api, self.config, name) 126 127 config = ConfigBuilder.build( 128 api_key=self.config.api_key, 129 host=index_host, 130 source_tag=self.config.source_tag, 131 proxy_url=self.config.proxy_url, 132 ssl_ca_certs=self.config.ssl_ca_certs, 133 ) 134 return GRPCIndex(index_name=name, config=config, **kwargs)
7class PineconeGRPC(Pinecone): 8 """ 9 An alternative version of the Pinecone client that uses gRPC instead of HTTP for 10 data operations. 11 12 ### Installing the gRPC client 13 14 You must install extra dependencies in order to install the GRPC client. 15 16 #### Installing with pip 17 18 ```bash 19 # Install the latest version 20 pip3 install pinecone[grpc] 21 22 # Install a specific version 23 pip3 install "pinecone[grpc]"==3.0.0 24 ``` 25 26 #### Installing with poetry 27 28 ```bash 29 # Install the latest version 30 poetry add pinecone --extras grpc 31 32 # Install a specific version 33 poetry add pinecone==3.0.0 --extras grpc 34 ``` 35 36 ### Using the gRPC client 37 38 ```python 39 import os 40 from pinecone.grpc import PineconeGRPC 41 42 client = PineconeGRPC(api_key=os.environ.get("PINECONE_API_KEY")) 43 44 # From this point on, usage is identical to the HTTP client. 45 index = client.Index("my-index", host=os.environ("PINECONE_INDEX_HOST")) 46 index.query(...) 47 ``` 48 49 """ 50 51 def Index(self, name: str = "", host: str = "", **kwargs): 52 """ 53 Target an index for data operations. 54 55 ### Target an index by host url 56 57 In production situations, you want to uspert or query your data as quickly 58 as possible. If you know in advance the host url of your index, you can 59 eliminate a round trip to the Pinecone control plane by specifying the 60 host of the index. 61 62 ```python 63 import os 64 from pinecone.grpc import PineconeGRPC 65 66 api_key = os.environ.get("PINECONE_API_KEY") 67 index_host = os.environ.get("PINECONE_INDEX_HOST") 68 69 pc = PineconeGRPC(api_key=api_key) 70 index = pc.Index(host=index_host) 71 72 # Now you're ready to perform data operations 73 index.query(vector=[...], top_k=10) 74 ``` 75 76 To find your host url, you can use the Pinecone control plane to describe 77 the index. The host url is returned in the response. Or, alternatively, the 78 host is displayed in the Pinecone web console. 79 80 ```python 81 import os 82 from pinecone import Pinecone 83 84 pc = Pinecone( 85 api_key=os.environ.get("PINECONE_API_KEY") 86 ) 87 88 host = pc.describe_index('index-name').host 89 ``` 90 91 ### Target an index by name (not recommended for production) 92 93 For more casual usage, such as when you are playing and exploring with Pinecone 94 in a notebook setting, you can also target an index by name. If you use this 95 approach, the client may need to perform an extra call to the Pinecone control 96 plane to get the host url on your behalf to get the index host. 97 98 The client will cache the index host for future use whenever it is seen, so you 99 will only incur the overhead of only one call. But this approach is not 100 recommended for production usage. 101 102 ```python 103 import os 104 from pinecone import ServerlessSpec 105 from pinecone.grpc import PineconeGRPC 106 107 api_key = os.environ.get("PINECONE_API_KEY") 108 109 pc = PineconeGRPC(api_key=api_key) 110 pc.create_index( 111 name='my-index', 112 dimension=1536, 113 metric='cosine', 114 spec=ServerlessSpec(cloud='aws', region='us-west-2') 115 ) 116 index = pc.Index('my-index') 117 118 # Now you're ready to perform data operations 119 index.query(vector=[...], top_k=10) 120 ``` 121 """ 122 if name == "" and host == "": 123 raise ValueError("Either name or host must be specified") 124 125 # Use host if it is provided, otherwise get host from describe_index 126 index_host = host or self.index_host_store.get_host(self.index_api, self.config, name) 127 128 config = ConfigBuilder.build( 129 api_key=self.config.api_key, 130 host=index_host, 131 source_tag=self.config.source_tag, 132 proxy_url=self.config.proxy_url, 133 ssl_ca_certs=self.config.ssl_ca_certs, 134 ) 135 return GRPCIndex(index_name=name, config=config, **kwargs)
An alternative version of the Pinecone client that uses gRPC instead of HTTP for data operations.
Installing the gRPC client
You must install extra dependencies in order to install the GRPC client.
Installing with pip
# Install the latest version
pip3 install pinecone[grpc]
# Install a specific version
pip3 install "pinecone[grpc]"==3.0.0
Installing with poetry
# Install the latest version
poetry add pinecone --extras grpc
# Install a specific version
poetry add pinecone==3.0.0 --extras grpc
Using the gRPC client
import os
from pinecone.grpc import PineconeGRPC
client = PineconeGRPC(api_key=os.environ.get("PINECONE_API_KEY"))
# From this point on, usage is identical to the HTTP client.
index = client.Index("my-index", host=os.environ("PINECONE_INDEX_HOST"))
index.query(...)
51 def Index(self, name: str = "", host: str = "", **kwargs): 52 """ 53 Target an index for data operations. 54 55 ### Target an index by host url 56 57 In production situations, you want to uspert or query your data as quickly 58 as possible. If you know in advance the host url of your index, you can 59 eliminate a round trip to the Pinecone control plane by specifying the 60 host of the index. 61 62 ```python 63 import os 64 from pinecone.grpc import PineconeGRPC 65 66 api_key = os.environ.get("PINECONE_API_KEY") 67 index_host = os.environ.get("PINECONE_INDEX_HOST") 68 69 pc = PineconeGRPC(api_key=api_key) 70 index = pc.Index(host=index_host) 71 72 # Now you're ready to perform data operations 73 index.query(vector=[...], top_k=10) 74 ``` 75 76 To find your host url, you can use the Pinecone control plane to describe 77 the index. The host url is returned in the response. Or, alternatively, the 78 host is displayed in the Pinecone web console. 79 80 ```python 81 import os 82 from pinecone import Pinecone 83 84 pc = Pinecone( 85 api_key=os.environ.get("PINECONE_API_KEY") 86 ) 87 88 host = pc.describe_index('index-name').host 89 ``` 90 91 ### Target an index by name (not recommended for production) 92 93 For more casual usage, such as when you are playing and exploring with Pinecone 94 in a notebook setting, you can also target an index by name. If you use this 95 approach, the client may need to perform an extra call to the Pinecone control 96 plane to get the host url on your behalf to get the index host. 97 98 The client will cache the index host for future use whenever it is seen, so you 99 will only incur the overhead of only one call. But this approach is not 100 recommended for production usage. 101 102 ```python 103 import os 104 from pinecone import ServerlessSpec 105 from pinecone.grpc import PineconeGRPC 106 107 api_key = os.environ.get("PINECONE_API_KEY") 108 109 pc = PineconeGRPC(api_key=api_key) 110 pc.create_index( 111 name='my-index', 112 dimension=1536, 113 metric='cosine', 114 spec=ServerlessSpec(cloud='aws', region='us-west-2') 115 ) 116 index = pc.Index('my-index') 117 118 # Now you're ready to perform data operations 119 index.query(vector=[...], top_k=10) 120 ``` 121 """ 122 if name == "" and host == "": 123 raise ValueError("Either name or host must be specified") 124 125 # Use host if it is provided, otherwise get host from describe_index 126 index_host = host or self.index_host_store.get_host(self.index_api, self.config, name) 127 128 config = ConfigBuilder.build( 129 api_key=self.config.api_key, 130 host=index_host, 131 source_tag=self.config.source_tag, 132 proxy_url=self.config.proxy_url, 133 ssl_ca_certs=self.config.ssl_ca_certs, 134 ) 135 return GRPCIndex(index_name=name, config=config, **kwargs)
Target an index for data operations.
Target an index by host url
In production situations, you want to uspert or query your data as quickly as possible. If you know in advance the host url of your index, you can eliminate a round trip to the Pinecone control plane by specifying the host of the index.
import os
from pinecone.grpc import PineconeGRPC
api_key = os.environ.get("PINECONE_API_KEY")
index_host = os.environ.get("PINECONE_INDEX_HOST")
pc = PineconeGRPC(api_key=api_key)
index = pc.Index(host=index_host)
# Now you're ready to perform data operations
index.query(vector=[...], top_k=10)
To find your host url, you can use the Pinecone control plane to describe the index. The host url is returned in the response. Or, alternatively, the host is displayed in the Pinecone web console.
import os
from pinecone import Pinecone
pc = Pinecone(
api_key=os.environ.get("PINECONE_API_KEY")
)
host = pc.describe_index('index-name').host
Target an index by name (not recommended for production)
For more casual usage, such as when you are playing and exploring with Pinecone in a notebook setting, you can also target an index by name. If you use this approach, the client may need to perform an extra call to the Pinecone control plane to get the host url on your behalf to get the index host.
The client will cache the index host for future use whenever it is seen, so you will only incur the overhead of only one call. But this approach is not recommended for production usage.
import os
from pinecone import ServerlessSpec
from pinecone.grpc import PineconeGRPC
api_key = os.environ.get("PINECONE_API_KEY")
pc = PineconeGRPC(api_key=api_key)
pc.create_index(
name='my-index',
dimension=1536,
metric='cosine',
spec=ServerlessSpec(cloud='aws', region='us-west-2')
)
index = pc.Index('my-index')
# Now you're ready to perform data operations
index.query(vector=[...], top_k=10)