From 9534b041db993e31fb33abc40b7919b522a5779f Mon Sep 17 00:00:00 2001 From: Mikhail Date: Tue, 25 Aug 2026 05:45:40 +0300 Subject: [PATCH] Ask for location before proximity search --- cmd/core-runtime/main.go | 4 ++++ modules/interaction/domain/semantics_test.go | 9 +++++++++ modules/interaction/domain/travel.go | 18 ++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/cmd/core-runtime/main.go b/cmd/core-runtime/main.go index a28790e..da9e980 100644 --- a/cmd/core-runtime/main.go +++ b/cmd/core-runtime/main.go @@ -705,6 +705,10 @@ func main() { parts := interactiondomain.IndependentRequestParts(effectiveTaskMessage) replies := make([]string, 0, len(parts)) for index, part := range parts { + if clarification := interactiondomain.LocalSearchClarification(part); clarification != "" { + replies = append(replies, "По запросу «"+part+"»: "+clarification) + continue + } researchCtx, cancelResearch := context.WithTimeout(r.Context(), 8*time.Second) result, researchErr := researchClient.SearchWeb(researchCtx, epistemics.WebSearchRequest{ Plan: epistemics.ResearchPlan{ID: epistemics.ResearchPlanID(fmt.Sprintf("plan:%s:%d", planID, index)), Question: part, SourceClasses: []string{"web-search"}, FreshnessPolicy: "current"}, diff --git a/modules/interaction/domain/semantics_test.go b/modules/interaction/domain/semantics_test.go index ab31c00..23611c6 100644 --- a/modules/interaction/domain/semantics_test.go +++ b/modules/interaction/domain/semantics_test.go @@ -76,6 +76,15 @@ func TestIndependentRequestParts(t *testing.T) { } } +func TestLocalSearchClarification(t *testing.T) { + if got := LocalSearchClarification("найди ближайший ресторан"); got == "" { + t.Fatal("proximity search without place must ask for location") + } + if got := LocalSearchClarification("найди ближайший ресторан в Сочи"); got != "" { + t.Fatalf("explicit place must proceed, got %q", got) + } +} + func TestTravelSearchClarification(t *testing.T) { if got := TravelSearchClarification("Найди билеты", nil); got == "" { t.Fatal("underspecified travel request must ask for missing route and date") diff --git a/modules/interaction/domain/travel.go b/modules/interaction/domain/travel.go index 04be7c4..2d64867 100644 --- a/modules/interaction/domain/travel.go +++ b/modules/interaction/domain/travel.go @@ -47,6 +47,24 @@ func IndependentRequestParts(message string) []string { return result } +// LocalSearchClarification prevents a proximity search from silently using a +// default city when the user did not provide a place. +func LocalSearchClarification(message string) string { + tokens := semanticTokens(StripAssistantVocative(message)) + if !containsStemInTokens(tokens, "ресторан", "кафе") || !containsStemInTokens(tokens, "ближ", "рядом") { + return "" + } + for index, token := range tokens { + if token != "в" && token != "на" && token != "около" && !containsStem(token, "район", "город") { + continue + } + if index+1 < len(tokens) || containsStem(token, "район", "город") { + return "" + } + } + return "В каком городе или районе искать ресторан?" +} + // TravelSearchClarification keeps an incomplete travel request in dialogue // instead of reducing it to an unrelated generic web search. func TravelSearchClarification(message string, history []interaction.HumanUtterance) string { -- 2.54.0