forked from pinecone-io/pinecone-python-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate.py
More file actions
37 lines (31 loc) · 1000 Bytes
/
create.py
File metadata and controls
37 lines (31 loc) · 1000 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import os
import random
import string
from pinecone import Pinecone
def read_env_var(name):
value = os.environ.get(name)
if value is None:
raise 'Environment variable {} is not set'.format(name)
return value
def random_string(length):
return ''.join(random.choice(string.ascii_lowercase) for i in range(length))
def write_gh_output(name, value):
with open(os.environ['GITHUB_OUTPUT'], 'a') as fh:
print(f'{name}={value}', file=fh)
def main():
pc = Pinecone(api_key=read_env_var('PINECONE_API_KEY'))
index_name = read_env_var('NAME_PREFIX') + random_string(20)
pc.create_index(
name=index_name,
metric=read_env_var('METRIC'),
dimension=int(read_env_var('DIMENSION')),
spec={
'serverless': {
'cloud': read_env_var('CLOUD'),
'region': read_env_var('REGION'),
}
}
)
write_gh_output('index_name', index_name)
if __name__ == '__main__':
main()