From 44ca1dcf9850b8e75f3b353aeb52c72b93afba96 Mon Sep 17 00:00:00 2001 From: estromenko Date: Fri, 31 Oct 2025 00:52:39 +0300 Subject: [PATCH] Fix recommendation link and lower similarity threshold --- .../commands/generate_recommended_vacancies.py | 4 ++-- vacancies/main/vector_store.py | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/vacancies/main/management/commands/generate_recommended_vacancies.py b/vacancies/main/management/commands/generate_recommended_vacancies.py index f889d5e..496a859 100644 --- a/vacancies/main/management/commands/generate_recommended_vacancies.py +++ b/vacancies/main/management/commands/generate_recommended_vacancies.py @@ -20,7 +20,7 @@ class Command(BaseCommand): ).values_list('vacancy_id', flat=True) query_filter = Filter(must_not=[HasIdCondition(has_id=recommended_vacancy_ids)]) - search_result_id, vacancy_content = search_similarities(query_filter, customer_cv.id) + search_result_id, vacancy_content, link = search_similarities(query_filter, customer_cv.id) recommendation = RecommendedVacancy.objects.create( customer=customer_cv.customer, @@ -31,6 +31,6 @@ class Command(BaseCommand): chat_id=recommendation.customer.chat_id, text=vacancy_content, reply_markup=InlineKeyboardMarkup([[ - InlineKeyboardButton("Откликнуться", url=recommendation.vacancy.link), + InlineKeyboardButton("Откликнуться", url=link), ]]), )) diff --git a/vacancies/main/vector_store.py b/vacancies/main/vector_store.py index c48e052..92d8563 100644 --- a/vacancies/main/vector_store.py +++ b/vacancies/main/vector_store.py @@ -91,7 +91,7 @@ def add_vectors(collection_name: str, _id: int, features: dict, payload: dict): scored.append({"id": vid, "score": total}) scored.sort(key=lambda x: x["score"], reverse=True) - if scored and scored[0]["score"] > 35: #treshold + if scored and scored[0]["score"] > 33: # threshold return client.upsert( @@ -132,17 +132,19 @@ def search_similarities(query_filter: Filter, cv_id: int) -> list[dict]: max_similarities[vid] = {} max_similarities[vid][name] = sim if vid not in vacancies_content: - vacancies_content[vid] = res.payload["content"] + vacancies_content[vid] = {} + vacancies_content[vid]["content"] = res.payload["content"] + vacancies_content[vid]["link"] = res.payload["link"] scored = [] for vid, feature_sims in max_similarities.items(): total = sum(feature_sims[feature] * weights.get(feature, 1) for feature in feature_sims) - scored.append({"id": vid, "score": total, "content": vacancies_content[vid]}) + scored.append({"id": vid, "score": total, "content": vacancies_content[vid]["content"], "link": vacancies_content[vid]["link"]}) scored.sort(key=lambda x: x["score"], reverse=True) for i in range(20): print(f"{scored[i]['content']} {scored[i]['score']}") - return scored[0]["id"], scored[0]["content"] + return scored[0]["id"], scored[0]["content"], scored[0]["link"] def extract_features(content: str) -> VacancyFeatures: