From d107d69d776ec7488685f994f0855306e43a7bc8 Mon Sep 17 00:00:00 2001 From: estromenko Date: Sun, 26 Oct 2025 14:04:56 +0300 Subject: [PATCH] Fix re-recommending vacancies --- .../collect_vacancies_from_telegram_messages.py | 7 ++++--- .../commands/generate_recommended_vacancies.py | 12 ++++++++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/vacancies/main/management/commands/collect_vacancies_from_telegram_messages.py b/vacancies/main/management/commands/collect_vacancies_from_telegram_messages.py index e2b373f..1b3e6ba 100644 --- a/vacancies/main/management/commands/collect_vacancies_from_telegram_messages.py +++ b/vacancies/main/management/commands/collect_vacancies_from_telegram_messages.py @@ -25,7 +25,7 @@ class Command(BaseCommand): help = "Collect vacancies from telegram messages" def handle(self, *args, **options): - documents = [] + ids, documents = [], [] for index, row in enumerate(clickhouse_client.query(query).result_rows): (id, chat_username, telegram_id, message, timestamp) = row @@ -36,9 +36,10 @@ class Command(BaseCommand): defaults={'content': message} ) - metadata = {"link": link, "vacancy_id": vacancy.id} + metadata = {"link": link} + ids.append(vacancy.id) documents.append(Document(page_content=message, metadata=metadata)) print(index, link) - vector_store.add_documents(documents) + vector_store.add_documents(documents, ids=ids) diff --git a/vacancies/main/management/commands/generate_recommended_vacancies.py b/vacancies/main/management/commands/generate_recommended_vacancies.py index 60391c8..d1a5a0f 100644 --- a/vacancies/main/management/commands/generate_recommended_vacancies.py +++ b/vacancies/main/management/commands/generate_recommended_vacancies.py @@ -4,6 +4,7 @@ from vacancies.main.vector_store import vector_store from vacancies.main.models import CustomerCV, RecommendedVacancy from vacancies.main.bot import application from telegram import InlineKeyboardButton, InlineKeyboardMarkup +from qdrant_client.models import Filter, HasIdCondition class Command(BaseCommand): @@ -16,14 +17,21 @@ class Command(BaseCommand): customer=customer_cv.customer ).values_list('vacancy_id', flat=True) + query_filter = Filter( + must_not = [ + HasIdCondition(has_id=recommended_vacancy_ids), + ] + ) + document = vector_store.similarity_search( customer_cv.content, k=1, - filter={"vacancy_id": {"$nin": list(recommended_vacancy_ids)}} + filter=query_filter, )[0] + print(document.__dict__) recommendation, _ = RecommendedVacancy.objects.get_or_create( customer=customer_cv.customer, - vacancy_id=document.metadata["vacancy_id"], + vacancy_id=document.metadata["_id"], ) asyncio.run(application.bot.send_message(