Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
11 changes: 7 additions & 4 deletions core/concepts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,7 @@
name_key = self.request.data.get('name_key', None) or 'display_name'
text = self.request.data.get('q', None)
score_key = self.request.data.get('score_key', None)
encoder_model = self.request.data.get('encoder_model', None)

if not isinstance(rows, list) or not rows:
return Response(
Expand All @@ -1017,7 +1018,9 @@
{'detail': 'Missing "q" in request body.'},
status=status.HTTP_400_BAD_REQUEST
)

return Response(
Reranker().rerank(hits=rows, name_key=name_key, txt=text, score_key=score_key, order_results=True)
)
try:
reranker = Reranker(model_name=encoder_model)
results = reranker.rerank(hits=rows, name_key=name_key, txt=text, score_key=score_key, order_results=True)
return Response(results)
except Exception as e:
return Response({'detail': str(e)}, status=status.HTTP_400_BAD_REQUEST)
18 changes: 18 additions & 0 deletions core/map_projects/migrations/0031_mapproject_encoder_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.1.5 on 2026-04-06 05:31

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('map_projects', '0030_auto_20260221_0250'),
]

operations = [
migrations.AddField(
model_name='mapproject',
name='encoder_model',
field=models.TextField(blank=True, default='BAAI/bge-reranker-v2-m3', null=True),
),
]
4 changes: 4 additions & 0 deletions core/map_projects/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
from collections import Counter

from django.conf import settings
from django.contrib.postgres.fields import ArrayField
from django.core.exceptions import ValidationError
from django.db import models, IntegrityError
Expand Down Expand Up @@ -38,6 +39,7 @@ class MapProject(BaseModel):
candidates = models.JSONField(default=dict, null=True, blank=True)
lookup_config = models.JSONField(default=dict, null=True, blank=True)
analysis = models.JSONField(default=dict, null=True, blank=True)
encoder_model = models.TextField(null=True, blank=True, default=settings.ENCODER_MODEL_NAME)

class Meta:
db_table = 'map_projects'
Expand Down Expand Up @@ -195,6 +197,8 @@ def clean(self):
self.clean_filters()
if not self.include_retired:
self.include_retired = False
if not self.encoder_model:
self.encoder_model = settings.ENCODER_MODEL_NAME
if self.matches:
try:
self.matches = json.loads(self.matches)
Expand Down
8 changes: 5 additions & 3 deletions core/map_projects/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Meta:
'created_by', 'updated_by', 'created_at', 'updated_at', 'url', 'is_active',
'public_access', 'file', 'user_id', 'organization_id', 'description',
'target_repo_url', 'include_retired', 'score_configuration',
'filters', 'candidates', 'algorithms', 'lookup_config', 'analysis'
'filters', 'candidates', 'algorithms', 'lookup_config', 'analysis', 'encoder_model'
]

def prepare_object(self, validated_data, instance=None, file=None):
Expand All @@ -36,7 +36,8 @@ def prepare_object(self, validated_data, instance=None, file=None):
instance.columns = columns
for attr in [
'name', 'description', 'extras', 'target_repo_url', 'include_retired',
'score_configuration', 'filters', 'candidates', 'algorithms', 'lookup_config', 'analysis'
'score_configuration', 'filters', 'candidates', 'algorithms', 'lookup_config', 'analysis',
'encoder_model'
]:
setattr(instance, attr, validated_data.get(attr, get(instance, attr)))
if not instance.id:
Expand Down Expand Up @@ -109,7 +110,8 @@ class Meta:
'created_by', 'updated_by', 'created_at', 'updated_at', 'url', 'is_active',
'owner', 'owner_type', 'owner_url', 'public_access',
'target_repo_url', 'summary', 'logs', 'include_retired',
'score_configuration', 'filters', 'candidates', 'algorithms', 'lookup_config', 'analysis'
'score_configuration', 'filters', 'candidates', 'algorithms', 'lookup_config', 'analysis',
'encoder_model'
]

def __init__(self, *args, **kwargs):
Expand Down
Loading