fastAPI / app.py
Almaatla's picture
Update app.py
2e6f539 verified
raw
history blame
527 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("/hello")
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"}