-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.py
More file actions
34 lines (25 loc) · 1.09 KB
/
database.py
File metadata and controls
34 lines (25 loc) · 1.09 KB
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
import pinecone
from pinecone import Pinecone
import pinecone.core
import pinecone.core.openapi.shared
import pinecone.core.openapi.shared.exceptions
from exceptions import PineconeIndexNameError, PineconeUnexceptedException
import pinecone.core.openapi
class PineconeCursor:
def __init__(self, api_key:str, index_name:str):
self.pinecone_api_key = api_key
self.index_name = index_name
def query(self, **kwargs):
try:
pc = Pinecone(api_key=self.pinecone_api_key)
existing_indexes = [index.name for index in pc.list_indexes()]
if self.index_name not in existing_indexes:
raise PineconeIndexNameError
self.index = pc.Index(self.index_name)
except pinecone.exceptions.PineconeApiException as e:
raise pinecone.exceptions.PineconeApiException(e)
except PineconeIndexNameError as e:
raise PineconeIndexNameError
except Exception as e:
raise PineconeUnexceptedException(e)
return self.index.query(**kwargs)