Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load index #59

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion semantic_search/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Dict, List, Optional, Tuple, Union, cast

import faiss
from faiss.swigfaiss import read_index
Anwesh1 marked this conversation as resolved.
Show resolved Hide resolved
import torch
from fastapi import FastAPI
from pydantic import BaseSettings
Expand Down Expand Up @@ -32,6 +33,7 @@ class Settings(BaseSettings):
pretrained_model_name_or_path: str = "johngiorgi/declutr-sci-base"
batch_size: int = 64
max_length: Optional[int] = None
file_path: Optional[str] = None
Anwesh1 marked this conversation as resolved.
Show resolved Hide resolved
mean_pool: bool = True
cuda_device: int = -1

Expand Down Expand Up @@ -80,7 +82,10 @@ def app_startup():
settings.pretrained_model_name_or_path, cuda_device=settings.cuda_device
)
embedding_dim = model.model.config.hidden_size
model.index = setup_faiss_index(embedding_dim)
if settings.file_path is not None:
Anwesh1 marked this conversation as resolved.
Show resolved Hide resolved
model.index = read_index(settings.file_path)
Anwesh1 marked this conversation as resolved.
Show resolved Hide resolved
else:
model.index = setup_faiss_index(embedding_dim)


@app.post("/")
Expand Down