Spaces:
Runtime error
Runtime error
jiarongqiu commited on
Commit ·
45ed5ce
1
Parent(s): 7487ea3
first commit
Browse files- main.py +4 -0
- service/__init__.py +0 -0
- service/pinecone.py +23 -0
main.py
CHANGED
|
@@ -2,6 +2,10 @@ from fastapi import FastAPI
|
|
| 2 |
|
| 3 |
app = FastAPI()
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
@app.get("/")
|
| 6 |
def read_root():
|
| 7 |
return {"Hello": "World!"}
|
|
|
|
| 2 |
|
| 3 |
app = FastAPI()
|
| 4 |
|
| 5 |
+
@app.get("/")
|
| 6 |
+
def read_root():
|
| 7 |
+
return {"Hello": "World!"}
|
| 8 |
+
|
| 9 |
@app.get("/")
|
| 10 |
def read_root():
|
| 11 |
return {"Hello": "World!"}
|
service/__init__.py
ADDED
|
File without changes
|
service/pinecone.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import pinecone
|
| 3 |
+
from langchain.embeddings.openai import OpenAIEmbeddings
|
| 4 |
+
from langchain.vectorstores import Pinecone
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class VectorStore(Pinecone):
|
| 8 |
+
|
| 9 |
+
def __init__(self,index_name) -> None:
|
| 10 |
+
pinecone.init(
|
| 11 |
+
api_key=os.getenv("PINECONE_API_KEY"), # find at app.pinecone.io
|
| 12 |
+
environment=os.getenv("PINECONE_ENV"), # next to api key in console
|
| 13 |
+
)
|
| 14 |
+
self.index_name = index_name
|
| 15 |
+
self.embeddings = OpenAIEmbeddings()
|
| 16 |
+
self.dims = 1536
|
| 17 |
+
index = pinecone.Index(self.index_name)
|
| 18 |
+
super().__init__(index, self.embeddings, "text")
|
| 19 |
+
|
| 20 |
+
def add_docs(self,docs):
|
| 21 |
+
if self.index_name not in pinecone.list_indexes():
|
| 22 |
+
pinecone.create_index(name=self.index_name, metric="cosine", dimension=self.dims)
|
| 23 |
+
Pinecone.from_documents(docs, self.embeddings, index_name=self.index_name)
|