fastAPI / app.py
Almaatla's picture
Update app.py
3ab82e8 verified
raw
history blame
522 Bytes
from fastapi import FastAPI
from sentence_transformers import SentenceTransformer
import faiss
import numpy as np
app = FastAPI()
model = SentenceTransformer('paraphrase-MiniLM-L6-v2')
index = faiss.IndexFlatL2(384) # 384 is the dimensionality of the MiniLM model
@app.get("/")
def greet_json():
return {"Hello": "World!"}
@app.post("/embed")
def embed_string(text: str):
embedding = model.encode([text])
index.add(np.array(embedding))
return {"message": "String embedded and added to FAISS database"}