Compare commits

...
Sign in to create a new pull request.

5 commits

Author SHA1 Message Date
vasilije
f214f5dbc5 search router change for UI test 2025-08-13 21:01:10 +02:00
Vasilije
8f66ab5587
Merge branch 'dev' into feature/top_k-input 2025-08-13 20:44:37 +02:00
Raj2604
6a6b48c2c9 feat: add top_k-input and send it to backend 2025-08-10 13:30:55 +05:30
Raj Mandhare
e26c21670a
Merge branch 'dev' into feature/top_k-input 2025-08-05 16:29:46 +05:30
Raj2604
8590194806 feat: add top_k input to SearchView and send to backend 2025-08-05 16:19:33 +05:30
3 changed files with 39 additions and 8 deletions

View file

@ -14,7 +14,7 @@ const fetchMessages = () => {
.then(response => response.json());
};
const sendMessage = (message: string, searchType: string) => {
const sendMessage = (message: string, searchType: string, topK: number = 10) => {
return fetch("/v1/search/", {
method: "POST",
headers: {
@ -24,6 +24,7 @@ const sendMessage = (message: string, searchType: string) => {
query: message,
searchType,
datasets: ["main_dataset"],
top_k: topK,
}),
})
.then(response => response.json());
@ -45,7 +46,7 @@ export default function useChat(dataset: Dataset) {
return setMessages(data);
}, []);
const handleMessageSending = useCallback((message: string, searchType: string) => {
const handleMessageSending = useCallback((message: string, searchType: string, topK: number = 10) => {
const sentMessageId = v4();
setMessages((messages) => [
@ -59,7 +60,7 @@ export default function useChat(dataset: Dataset) {
disableSearchRun();
return sendMessage(message, searchType)
return sendMessage(message, searchType, topK)
.then(newMessages => {
setMessages((messages) => [
...messages,

View file

@ -4,7 +4,7 @@ import classNames from "classnames";
import { useCallback, useEffect, useRef, useState } from "react";
import { LoadingIndicator } from "@/ui/App";
import { CTAButton, Select, TextArea } from "@/ui/elements";
import { CTAButton, Select, TextArea, Input } from "@/ui/elements";
import useChat from "@/modules/chat/hooks/useChat";
import styles from "./SearchView.module.css";
@ -59,17 +59,28 @@ export default function SearchView() {
}, [refreshChat, scrollToBottom]);
const [searchInputValue, setSearchInputValue] = useState("");
// Add state for top_k
const [topK, setTopK] = useState(10);
const handleSearchInputChange = useCallback((value: string) => {
setSearchInputValue(value);
}, []);
// Add handler for top_k input
const handleTopKChange = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
let value = parseInt(e.target.value, 10);
if (isNaN(value)) value = 10;
if (value < 1) value = 1;
if (value > 100) value = 100;
setTopK(value);
}, []);
const handleChatMessageSubmit = useCallback((event: React.FormEvent<SearchFormPayload>) => {
event.preventDefault();
const formElements = event.currentTarget;
const searchType = formElements.searchType.value;
const chatInput = searchInputValue.trim();
if (chatInput === "") {
@ -79,10 +90,11 @@ export default function SearchView() {
scrollToBottom();
setSearchInputValue("");
sendMessage(chatInput, searchType)
// Pass topK to sendMessage
sendMessage(chatInput, searchType, topK)
.then(scrollToBottom)
}, [scrollToBottom, sendMessage, searchInputValue]);
}, [scrollToBottom, sendMessage, searchInputValue, topK]);
const chatFormRef = useRef<HTMLFormElement>(null);
@ -132,6 +144,20 @@ export default function SearchView() {
<option key={option.value} value={option.value}>{option.label}</option>
))}
</Select>
{/* Add top_k input here */}
<label className="text-gray-600 whitespace-nowrap" title="Controls how many results to return. Smaller = focused, larger = broader graph exploration.">
Max results:
<Input
type="number"
name="topK"
min={1}
max={100}
value={topK}
onChange={handleTopKChange}
className="w-20 ml-2"
title="Controls how many results to return. Smaller = focused, larger = broader graph exploration."
/>
</label>
</div>
<CTAButton disabled={isSearchRunning} type="submit">
{isSearchRunning? "Searching..." : "Search"}

View file

@ -118,6 +118,10 @@ def get_search_router() -> APIRouter:
top_k=payload.top_k,
)
# Ensure response conforms to response_model=list
if not isinstance(results, list):
results = [results]
return results
except PermissionDeniedError:
return []