1. Get an API key
The API key will be sent to your email.
2. Install the lightweight python client
Once you have your API key, you’re ready to install and configure the lightweight python client.
pip install pinecone-client
3. Import Pinecone and set API key
import pinecone
pinecone.init(api_key="YOUR_API_KEY")
4. Load your data
Here we’ll use some synthetic data for illustration.
import numpy as np
items = []
items.extend((f'class-a-{i}', vec) for i, vec in enumerate(np.random.randn(500, 1024) + 0.0))
items.extend((f'class-b-{i}', vec) for i, vec in enumerate(np.random.randn(500, 1024) + 1.0))
queries = np.random.randn(100, 1024) + 0.0 # the queries belong to class a
5. Define ingress paths
Define arbitrary pre-processing steps (DAGs) to transform inputs and outputs.
import pinecone.graph
graph = pinecone.graph.IndexGraph()
# you can do things like
# graph.add_read_preprocessor('my_item_transformer_image_uri')
# graph.add_write_preprocessor('my_query_transformer_image_uri')
# graph.add_postprocessor('my_postprocessor_image_uri')
6. Start the service
Start the live service. Pinecone will run it on a managed, distributed container cluster.
import pinecone.service
pinecone.service.deploy(service_name="hello-pinecone", graph=graph)
7. Connect to your live service
import pinecone.connector
conn = pinecone.connector.connect("hello-pinecone")
8. Add data
Data is transformed into high-dimensional vectors using the pre-processors defined in Step 5, and the index is updated within 100ms.
acks = conn.upsert(items=items).collect()
9. Query the database
Find similar or top-ranking items in milliseconds.
results = conn.query(queries=queries).collect()
print(results[0])
What’s next? Read the documentation or contact support@pinecone.io with questions.