Skip to content

Commit 2c11d1e

Browse files
committed
Add example Python code to README.md.
1 parent 467f1e8 commit 2c11d1e

File tree

1 file changed

+166
-0
lines changed

1 file changed

+166
-0
lines changed

README.md

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,169 @@ pinecone.init(api_key="YOUR_API_KEY", environment="us-west1-gcp")
8686

8787
pinecone.delete_index("example-index")
8888
```
89+
90+
## Scale replicas
91+
92+
The following example changes the number of replicas for `example-index`.
93+
94+
```python
95+
import pinecone
96+
97+
pinecone.init(api_key="YOUR_API_KEY", environment="us-west1-gcp")
98+
99+
new_number_of_replicas = 4
100+
pinecone.configure_index("example-index", replicas=new_number_of_replicas)
101+
```
102+
103+
## Describe index statistics
104+
105+
The following example returns statistics about the index `example-index`.
106+
107+
```python
108+
import pinecone
109+
110+
pinecone.init(api_key="YOUR_API_KEY", environment="us-west1-gcp")
111+
index = pinecone.Index("example-index")
112+
113+
index_stats_response = index.describe_index_stats()
114+
```
115+
116+
## Query an index
117+
118+
The following example queries the index `example-index` with metadata
119+
filtering.
120+
121+
```python
122+
import pinecone
123+
124+
pinecone.init(api_key="YOUR_API_KEY", environment="us-west1-gcp")
125+
index = pinecone.Index("example-index")
126+
127+
query_response = index.query(
128+
namespace="example-namespace",
129+
top_k=10,
130+
include_values=True,
131+
include_metadata=True,
132+
vector=[0.1, 0.2, 0.3, 0.4],
133+
filter={
134+
"genre": {"$in": ["comedy", "documentary", "drama"]}
135+
}
136+
)
137+
```
138+
139+
## Delete vectors
140+
141+
The following example deletes vectors by ID.
142+
143+
```python
144+
import pinecone
145+
146+
pinecone.init(api_key="YOUR_API_KEY", environment="us-west1-gcp")
147+
index = pinecone.Index("example-index")
148+
149+
delete_response = index.delete(ids=["vec1", "vec2"], namespace="example-namespace")
150+
```
151+
152+
## Fetch vectors
153+
154+
The following example fetches vectors by ID.
155+
156+
```python
157+
import pinecone
158+
159+
pinecone.init(api_key="YOUR_API_KEY", environment="us-west1-gcp")
160+
index = pinecone.Index("example-index")
161+
162+
fetch_response = index.fetch(ids=["vec1", "vec2"], namespace="example-namespace")
163+
```
164+
165+
166+
## Update vectors
167+
168+
The following example updates vectors by ID.
169+
170+
```python
171+
import pinecone
172+
173+
pinecone.init(api_key="YOUR_API_KEY", environment="us-west1-gcp")
174+
index = pinecone.Index("example-index")
175+
176+
update_response = index.update(
177+
id="vec1",
178+
values=[0.1, 0.2, 0.3, 0.4],
179+
set_metadata={"genre": "drama"},
180+
namespace="example-namespace"
181+
)
182+
```
183+
184+
## Upsert vectors
185+
186+
The following example upserts vectors to `example-index`.
187+
188+
```python
189+
import pinecone
190+
191+
pinecone.init(api_key="YOUR_API_KEY", environment="us-west1-gcp")
192+
index = pinecone.Index("example-index")
193+
194+
upsert_response = index.upsert(
195+
vectors=[
196+
("vec1", [0.1, 0.2, 0.3, 0.4], {"genre": "drama"}),
197+
("vec2", [0.2, 0.3, 0.4, 0.5], {"genre": "action"}),
198+
],
199+
namespace="example-namespace"
200+
)
201+
```
202+
203+
## Create collection
204+
205+
The following example creates the collection `example-collection` from
206+
`example-index`.
207+
208+
```python
209+
import pinecone
210+
211+
pinecone.init(api_key="YOUR_API_KEY",
212+
environment="us-west1-gcp")
213+
214+
pinecone.create_collection("example-collection", "example-index")
215+
```
216+
217+
## List collections
218+
219+
The following example returns a list of the collections in the current project.
220+
221+
```python
222+
import pinecone
223+
224+
pinecone.init(api_key="YOUR_API_KEY", environment="us-west1-gcp")
225+
226+
active_collections = pinecone.list_collections()
227+
```
228+
229+
## Describe a collection
230+
231+
The following example returns a description of the collection
232+
`example-collection`.
233+
234+
```python
235+
import pinecone
236+
237+
pinecone.init(api_key="YOUR_API_KEY", environment="us-west1-gcp")
238+
239+
collection_description = pinecone.describe_collection("example-collection")
240+
```
241+
242+
## Delete a collection
243+
244+
The following example deletes the collection `example-collection`.
245+
246+
```python
247+
import pinecone
248+
249+
pinecone.init(api_key="YOUR_API_KEY", environment="us-west1-gcp")
250+
251+
pinecone.delete_collection("example-collection")
252+
```
253+
254+

0 commit comments

Comments
 (0)