Skip to content

Commit

Permalink
Update regeneration logic to run for all entries now that we have a s…
Browse files Browse the repository at this point in the history
…ingle search model ID
  • Loading branch information
sabaimran committed Jan 3, 2025
1 parent 33f85b4 commit 756f4a2
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions src/khoj/database/management/commands/change_default_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def regenerate_entries(entry_filter: Q, embeddings_model: EmbeddingsModel, searc
entries = Entry.objects.filter(entry_filter)[start:end]
compiled_entries = [entry.compiled for entry in entries]
updated_entries: List[Entry] = []

try:
embeddings = embeddings_model.embed_documents(compiled_entries)
except Exception as e:
Expand Down Expand Up @@ -87,27 +88,21 @@ def regenerate_entries(entry_filter: Q, embeddings_model: EmbeddingsModel, searc

current_default = get_default_search_model()

# TODO: Migrate all Entry objects to use the new default Search model

all_agents = Agent.objects.all()
logger.info(f"Number of Agent objects to update: {all_agents.count()}")
for agent in all_agents:
entry_filter = Q(agent=agent)
relevant_entries = Entry.objects.filter(entry_filter).all()
logger.info(f"Number of Entry objects to update for agent {agent}: {relevant_entries.count()}")

if apply:
try:
regenerate_entries(
entry_filter,
embeddings_model[new_default_search_model_config.name],
new_default_search_model_config,
)
logger.info(
f"Updated {relevant_entries.count()} Entry objects for agent {agent} to use the new default Search model."
)
except Exception as e:
logger.error(f"Error embedding documents: {e}")
# Create an entry filter with no conditions
entry_filter = Q()
relevant_entries = Entry.objects.filter(entry_filter).all()
logger.info(f"Number of Entry objects to update: {relevant_entries.count()}")

if apply:
try:
regenerate_entries(
entry_filter=entry_filter,
embeddings_model=embeddings_model[new_default_search_model_config.name],
search_model=new_default_search_model_config,
)
except Exception as e:
logger.error(f"Error updating Entry objects: {e}")
return

if apply and current_default.id != new_default_search_model_config.id:
# Get the existing default SearchModelConfig object and update its name
Expand Down

0 comments on commit 756f4a2

Please sign in to comment.