Skip to content

Commit

Permalink
remove upsert
Browse files Browse the repository at this point in the history
  • Loading branch information
pablonyx committed Sep 4, 2024
1 parent 9b18140 commit ad0c02f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 36 deletions.
35 changes: 1 addition & 34 deletions backend/danswer/db/search_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,44 +31,11 @@
logger = setup_logger()


def create_or_fetch_search_settings(
def create_search_settings(
search_settings: SavedSearchSettings,
db_session: Session,
status: IndexModelStatus = IndexModelStatus.FUTURE,
) -> SearchSettings:
# Check if a SearchSettings instance with the same model_name and provider_type already exists
existing_settings = (
db_session.query(SearchSettings)
.filter(
SearchSettings.model_name == search_settings.model_name,
SearchSettings.provider_type == search_settings.provider_type,
)
.first()
)

if existing_settings:
# Update all values of the existing settings manually
existing_settings.model_dim = search_settings.model_dim
existing_settings.normalize = search_settings.normalize
existing_settings.query_prefix = search_settings.query_prefix
existing_settings.passage_prefix = search_settings.passage_prefix
existing_settings.status = status
existing_settings.index_name = search_settings.index_name
existing_settings.multipass_indexing = search_settings.multipass_indexing
existing_settings.multilingual_expansion = (
search_settings.multilingual_expansion
)
existing_settings.disable_rerank_for_streaming = (
search_settings.disable_rerank_for_streaming
)
existing_settings.rerank_model_name = search_settings.rerank_model_name
existing_settings.rerank_provider_type = search_settings.rerank_provider_type
existing_settings.rerank_api_key = search_settings.rerank_api_key
existing_settings.num_rerank = search_settings.num_rerank

db_session.commit()
return existing_settings

embedding_model = SearchSettings(
model_name=search_settings.model_name,
model_dim=search_settings.model_dim,
Expand Down
4 changes: 2 additions & 2 deletions backend/danswer/server/manage/search_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from danswer.db.index_attempt import expire_index_attempts
from danswer.db.models import IndexModelStatus
from danswer.db.models import User
from danswer.db.search_settings import create_or_fetch_search_settings
from danswer.db.search_settings import create_search_settings
from danswer.db.search_settings import delete_search_settings
from danswer.db.search_settings import get_current_search_settings
from danswer.db.search_settings import get_embedding_provider_from_provider_type
Expand Down Expand Up @@ -90,7 +90,7 @@ def set_new_search_settings(
db_session=db_session,
)

new_search_settings = create_or_fetch_search_settings(
new_search_settings = create_search_settings(
search_settings=new_search_settings_request, db_session=db_session
)

Expand Down

0 comments on commit ad0c02f

Please sign in to comment.