// // SPDX-FileCopyrightText: Copyright (c) 1993-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // import { useState, useEffect } from "react"; import { Triple } from "@/types/graph"; import { Search as SearchIcon, Zap, Database, Cpu } from "lucide-react"; import { LLMSelectorCompact } from "./llm-selector-compact"; interface RagQueryProps { onQuerySubmit: (query: string, params: RagParams) => Promise; clearResults: () => void; isLoading: boolean; error?: string | null; className?: string; vectorEnabled?: boolean; } type QueryMode = 'traditional' | 'vector-search' | 'pure-rag'; export interface RagParams { kNeighbors: number; fanout: number; numHops: number; topK: number; useVectorSearch?: boolean; usePureRag?: boolean; queryMode?: QueryMode; } export function RagQuery({ onQuerySubmit, clearResults, isLoading, error, className, vectorEnabled }: RagQueryProps) { const [query, setQuery] = useState(""); const [showAdvanced, setShowAdvanced] = useState(false); const [queryMode, setQueryMode] = useState('traditional'); const [params, setParams] = useState({ kNeighbors: 4096, fanout: 400, numHops: 2, topK: 40, // Increased to 40 for multi-hop paths (was 20, originally 5) useVectorSearch: false, usePureRag: false, queryMode: 'traditional' }); // Update query mode when vectorEnabled changes - but don't override user selection useEffect(() => { // Only set default mode on initial load, not when user selects Graph Search if (vectorEnabled && queryMode === 'traditional') { console.log('Not forcing mode change - respecting user selection'); // No longer forcing mode change - let user select what they want } }, [vectorEnabled, queryMode]); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); if (!query.trim()) return; // Set the appropriate params based on the selected query mode const updatedParams = { ...params }; if (queryMode === 'pure-rag') { updatedParams.usePureRag = true; updatedParams.useVectorSearch = false; } else if (queryMode === 'vector-search') { updatedParams.usePureRag = false; updatedParams.useVectorSearch = true; } else { // traditional updatedParams.usePureRag = false; updatedParams.useVectorSearch = false; } // Pass the current queryMode to the parent component await onQuerySubmit(query, { ...updatedParams, queryMode: queryMode // Add the query mode to the params }); }; const handleReset = () => { setQuery(""); clearResults(); }; const updateParam = (key: keyof RagParams, value: number | boolean) => { setParams(prev => ({ ...prev, [key]: value })); }; // Handle changing the query mode const handleQueryModeChange = (mode: QueryMode) => { console.log(`Changing query mode to: ${mode}`); setQueryMode(mode); // Force update params based on the selected mode const updatedParams = { ...params }; if (mode === 'pure-rag') { updatedParams.usePureRag = true; updatedParams.useVectorSearch = false; } else if (mode === 'vector-search') { updatedParams.usePureRag = false; updatedParams.useVectorSearch = true; } else { // traditional mode updatedParams.usePureRag = false; updatedParams.useVectorSearch = false; } setParams(updatedParams); }; return (

RAG Query Engine

Query your knowledge graph using natural language

{/* Query Type Selection */}

Select Query Type

{/* LLM Selection */}

LLM Model

Select the LLM for answer generation

setQuery(e.target.value)} className="w-full p-3 pl-11 rounded-xl border border-border/60 bg-background text-foreground focus:border-nvidia-green/50 focus:ring-2 focus:ring-nvidia-green/20 transition-colors" disabled={isLoading} />
{error && (
!
Error: {error}
)}
{showAdvanced && (
{/* Only show graph-related parameters for traditional and vector search modes */} {queryMode !== 'pure-rag' && ( <>
{params.kNeighbors}
updateParam('kNeighbors', parseInt(e.target.value))} className="w-full h-2 bg-muted/30 rounded-lg appearance-none cursor-pointer slider-thumb" />
{params.fanout}
updateParam('fanout', parseInt(e.target.value))} className="w-full h-2 bg-muted/30 rounded-lg appearance-none cursor-pointer slider-thumb" />
{params.numHops}
updateParam('numHops', parseInt(e.target.value))} className="w-full h-2 bg-muted/30 rounded-lg appearance-none cursor-pointer slider-thumb" />
)}
{params.topK}
updateParam('topK', parseInt(e.target.value))} className="w-full h-2 bg-muted/30 rounded-lg appearance-none cursor-pointer slider-thumb" />
)}
); }