@@ -20,4 +20,235 @@ Or a specific development version:
20
20
pip install git+https://
[email protected] /pinecone-io/pinecone-python-client.git
21
21
pip install git+https://
[email protected] /pinecone-io/pinecone-python-client.git@example-branch-name
22
22
pip install git+https://
[email protected] /pinecone-io/pinecone-python-client.git@259deff
23
- ```
23
+ ```
24
+
25
+ ## Creating an index
26
+
27
+ The following example creates an index without a metadata
28
+ configuration. By default, Pinecone indexes all metadata.
29
+
30
+ ``` python
31
+
32
+ import pinecone
33
+
34
+
35
+ pinecone.init(api_key = " YOUR_API_KEY" ,
36
+ environment = " us-west1-gcp" )
37
+
38
+ pinecone.create_index(" example-index" , dimension = 1024 )
39
+ ```
40
+
41
+ The following example creates an index that only indexes
42
+ the "color" metadata field. Queries against this index
43
+ cannot filter based on any other metadata field.
44
+
45
+ ``` python
46
+ metadata_config = {
47
+ " indexed" : [" color" ]
48
+ }
49
+
50
+ pinecone.create_index(" example-index-2" , dimension = 1024 ,
51
+ metadata_config = metadata_config)
52
+ ```
53
+
54
+ ## List indexes
55
+
56
+ The following example returns all indexes in your project.
57
+
58
+ ``` python
59
+ import pinecone
60
+
61
+ pinecone.init(api_key = " YOUR_API_KEY" , environment = " us-west1-gcp" )
62
+
63
+ active_indexes = pinecone.list_indexes()
64
+ ```
65
+
66
+ ## Describe index
67
+
68
+ The following example returns information about the index ` example-index ` .
69
+
70
+ ``` python
71
+ import pinecone
72
+
73
+ pinecone.init(api_key = " YOUR_API_KEY" , environment = " us-west1-gcp" )
74
+
75
+ index_description = pinecone.describe_index(" example-index"
76
+ ```)
77
+
78
+ # # Delete an index
79
+
80
+ The following example deletes `example- index` .
81
+
82
+ ```python
83
+ import pinecone
84
+
85
+ pinecone.init(api_key = " YOUR_API_KEY" , environment = " us-west1-gcp" )
86
+
87
+ pinecone.delete_index(" example-index" )
88
+ ```
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