From 0d27239ca69320b2f9c9bb91770b814c19886658 Mon Sep 17 00:00:00 2001 From: James Ketrenos Date: Thu, 15 May 2025 05:24:27 -0700 Subject: [PATCH] Everything is working --- frontend/src/VectorVisualizer.css | 3 - frontend/src/VectorVisualizer.tsx | 294 ++++++++++++------------------ 2 files changed, 112 insertions(+), 185 deletions(-) diff --git a/frontend/src/VectorVisualizer.css b/frontend/src/VectorVisualizer.css index e9a86d3..3598aa4 100644 --- a/frontend/src/VectorVisualizer.css +++ b/frontend/src/VectorVisualizer.css @@ -1,6 +1,3 @@ -.Hover { - border: 3px solid purple !important; -} /* .js-plotly-plot { width: 100%; height: 100%; diff --git a/frontend/src/VectorVisualizer.tsx b/frontend/src/VectorVisualizer.tsx index 538185d..a02689d 100644 --- a/frontend/src/VectorVisualizer.tsx +++ b/frontend/src/VectorVisualizer.tsx @@ -1,6 +1,6 @@ import React, { useEffect, useState, useRef } from 'react'; import Box from '@mui/material/Box'; -import Card from '@mui/material/Card'; +import Paper from '@mui/material/Paper'; import Plot from 'react-plotly.js'; import TextField from '@mui/material/TextField'; import Tooltip from '@mui/material/Tooltip'; @@ -212,8 +212,6 @@ const VectorVisualizer: React.FC = (props: VectorVisualiz * filtered is for any item not in the querySet * query is for any item that is in the querySet */ - console.log(querySet); - full.ids.forEach((id, index) => { const foundIndex = querySet.ids.indexOf(id); /* Update metadata to hold the doc content and id */ @@ -222,7 +220,6 @@ const VectorVisualizer: React.FC = (props: VectorVisualiz if (foundIndex !== -1) { /* The query set will contain the distance to the query */ full.metadatas[index].distance = querySet.distances ? querySet.distances[foundIndex] : undefined; - console.log(querySet.distances ? querySet.distances[foundIndex] : undefined); query.ids.push(id); query.documents.push(full.documents[index]); query.embeddings.push(full.embeddings[index]); @@ -265,11 +262,6 @@ const VectorVisualizer: React.FC = (props: VectorVisualiz const query_y = normalizeDimension(query.embeddings.map((v: number[]) => v[1])); const query_z = is3D ? normalizeDimension(query.embeddings.map((v: number[]) => v[2])) : undefined; - query_sizes.forEach((s, i) => { console.log(`distance: ${query.metadatas[i].distance} size: ${s}`) }); - - // console.log(query_sizes.length, query_colors.length, query_x.length, query_y.length, query.ids.length, query.metadatas.length, query.embeddings.length); - // console.log(filtered_sizes.length, filtered_colors.length, filtered_x.length, filtered_y.length, filtered.ids.length, filtered.metadatas.length, filtered.embeddings.length); - const data: any = [{ name: 'All data', x: filtered_x, @@ -407,7 +399,7 @@ The scatter graph shows the query in N-dimensional space, mapped to ${view2D ? ' }; return ( - - { - !inline && - - RAG Vector Visualization - - } - - - - } onChange={() => setView2D(!view2D)} label="3D" /> - { onNodeSelected(event.points[0].customdata); }} - data={plotData} - useResizeHandler={true} - config={{ - responsive: true, - // displayModeBar: false, - displaylogo: false, - showSendToCloud: false, - staticPlot: false, - }} - style={{ - display: "flex", - flexGrow: 1, - minHeight: '240px', - padding: 0, - margin: 0, - width: "100%", - height: "100%", - overflow: "hidden", - }} - layout={layout} - /> - - { - !inline && querySet.ids.length > 0 && + { + !inline && + + RAG Vector Visualization + + } + + } onChange={() => setView2D(!view2D)} label="3D" /> + { onNodeSelected(event.points[0].customdata); }} + data={plotData} + useResizeHandler={true} + config={{ + responsive: true, + // displayModeBar: false, + displaylogo: false, + showSendToCloud: false, + staticPlot: false, + }} + style={{ + display: "flex", flexGrow: 1, - height: "max-content", - backgroundColor: "white", - }}> - - { - return ( -
{ - if (typeof value === "string") { - const id: string = value; - /* Not sure why 'distance' isn't being tracked in customdata... */ - const item = plotData.customdata.find(m => m.id === id) - if (item) { - onNodeSelected(item); - } - } + minHeight: '240px', + padding: 0, + margin: 0, + width: "100%", + height: "100%", + overflow: "hidden", + }} + layout={layout} + /> + - // console.log("keyName", keyName) - // console.log("value", value) - // console.log("parentValue", parentValue) - }} - /> - ) - }} - /> - - - } - { - !inline && querySet.ids.length === 0 && Enter query below to view distances. - } - - - { - {node !== null && - - + + {node !== null && + + - + Type {node.emoji} {node.doc_type} @@ -559,64 +491,62 @@ The scatter graph shows the query in N-dimensional space, mapped to ${view2D ? '
{node.content !== "" && node.content !== undefined && - + Vector Embedded Content {node.content} - +
} -
+
} - {node === null && - No node selected. Click a point in the scatter-graph. - } - {!inline && - - {node !== null && node.full_content && - node.full_content.split('\n').map((line, index) => { - index += 1 + node.chunk_begin; - const bgColor = (index > node.line_begin && index <= node.line_end) ? '#f0f0f0' : 'auto'; - // console.log(index, node.line_begin, node.line_end, bgColor); - return - {index} -
{line || " "}
-
; - }) - } - {node !== null && !node.line_begin &&
{node.content}
} - {node === null && "Select a node in the visualization."} -
- } - - } - - {!inline && querySet.query !== undefined && querySet.query !== '' && - - Query: {querySet.query} - - } - { - !inline && - - + {node === null && + + Click a point in the scatter-graph to see information about that node. + + } + {!inline && node !== null && node.full_content && + + { + node.full_content.split('\n').map((line, index) => { + index += 1 + node.chunk_begin; + const bgColor = (index > node.line_begin && index <= node.line_end) ? '#f0f0f0' : 'auto'; + return + {index} +
{line || " "}
+
; + }) + } + {!node.line_begin &&
{node.content}
} +
+ } +
+ + + {!inline && querySet.query !== undefined && querySet.query !== '' && + + {querySet.query !== undefined && querySet.query !== '' && `Query: ${querySet.query}`} + {querySet.ids.length === 0 && "Enter query below to perform a similarity search."} + + } + + { + !inline && + + setNewQuery(e.target.value)} onKeyDown={handleKeyPress} @@ -627,12 +557,12 @@ The scatter graph shows the query in N-dimensional space, mapped to ${view2D ? ' - } - + } + + ); }; - const VectorVisualizerPage: React.FC = (props: VectorVisualizerProps) => { return