Merge branch 'dev' into feature/cog-2734-cognee-feedbacks-interactions-poc-to-prod

This commit is contained in:
hajdul88 2025-08-19 17:04:09 +02:00 committed by GitHub
commit 67d88c4e85
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 49 additions and 18 deletions

View file

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

View file

@ -4,7 +4,7 @@ import classNames from "classnames";
import { useCallback, useEffect, useRef, useState } from "react"; import { useCallback, useEffect, useRef, useState } from "react";
import { LoadingIndicator } from "@/ui/App"; 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 useChat from "@/modules/chat/hooks/useChat";
import styles from "./SearchView.module.css"; import styles from "./SearchView.module.css";
@ -59,17 +59,28 @@ export default function SearchView() {
}, [refreshChat, scrollToBottom]); }, [refreshChat, scrollToBottom]);
const [searchInputValue, setSearchInputValue] = useState(""); const [searchInputValue, setSearchInputValue] = useState("");
// Add state for top_k
const [topK, setTopK] = useState(10);
const handleSearchInputChange = useCallback((value: string) => { const handleSearchInputChange = useCallback((value: string) => {
setSearchInputValue(value); 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>) => { const handleChatMessageSubmit = useCallback((event: React.FormEvent<SearchFormPayload>) => {
event.preventDefault(); event.preventDefault();
const formElements = event.currentTarget; const formElements = event.currentTarget;
const searchType = formElements.searchType.value; const searchType = formElements.searchType.value;
const chatInput = searchInputValue.trim(); const chatInput = searchInputValue.trim();
if (chatInput === "") { if (chatInput === "") {
@ -79,10 +90,11 @@ export default function SearchView() {
scrollToBottom(); scrollToBottom();
setSearchInputValue(""); setSearchInputValue("");
sendMessage(chatInput, searchType) // Pass topK to sendMessage
sendMessage(chatInput, searchType, topK)
.then(scrollToBottom) .then(scrollToBottom)
}, [scrollToBottom, sendMessage, searchInputValue]); }, [scrollToBottom, sendMessage, searchInputValue, topK]);
const chatFormRef = useRef<HTMLFormElement>(null); const chatFormRef = useRef<HTMLFormElement>(null);
@ -125,13 +137,30 @@ export default function SearchView() {
className="resize-none min-h-14 max-h-96 overflow-y-auto" className="resize-none min-h-14 max-h-96 overflow-y-auto"
/> />
<div className="flex flex-row items-center justify-between gap-4"> <div className="flex flex-row items-center justify-between gap-4">
<div className="flex flex-row items-center gap-2"> <div className="flex flex-row items-center gap-4">
<label className="text-gray-600 whitespace-nowrap">Search type:</label> <div className="flex flex-row items-center gap-2">
<Select name="searchType" defaultValue={searchOptions[0].value} className="max-w-2xs"> <label className="text-gray-600 whitespace-nowrap">Search type:</label>
{searchOptions.map((option) => ( <Select name="searchType" defaultValue={searchOptions[0].value} className="max-w-2xs">
<option key={option.value} value={option.value}>{option.label}</option> {searchOptions.map((option) => (
))} <option key={option.value} value={option.value}>{option.label}</option>
</Select> ))}
</Select>
</div>
<div className="flex flex-row items-center gap-2">
<label className="text-gray-600 whitespace-nowrap" title="Controls how many results to return. Smaller = focused, larger = broader graph exploration.">
Max results:
</label>
<Input
type="number"
name="topK"
min={1}
max={100}
value={topK}
onChange={handleTopKChange}
className="w-20"
title="Controls how many results to return. Smaller = focused, larger = broader graph exploration."
/>
</div>
</div> </div>
<CTAButton disabled={isSearchRunning} type="submit"> <CTAButton disabled={isSearchRunning} type="submit">
{isSearchRunning? "Searching..." : "Search"} {isSearchRunning? "Searching..." : "Search"}
@ -142,4 +171,4 @@ export default function SearchView() {
</form> </form>
</div> </div>
); );
} }

View file

@ -138,8 +138,9 @@ class KuzuAdapter(GraphDBInterface):
s3_file_storage = S3FileStorage("") s3_file_storage = S3FileStorage("")
async with self.KUZU_ASYNC_LOCK: if self.connection:
self.connection.execute("CHECKPOINT;") async with self.KUZU_ASYNC_LOCK:
self.connection.execute("CHECKPOINT;")
s3_file_storage.s3.put(self.temp_graph_file, self.db_path, recursive=True) s3_file_storage.s3.put(self.temp_graph_file, self.db_path, recursive=True)