Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore[visualize-tab]: fix inconsistency in Visualize tab and add documentation #248

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
10 changes: 7 additions & 3 deletions src/components/VisualizeChart/renderBy.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,23 @@ export function generateColorBy(points, colorBy = null) {
colorBy = { payload: colorBy };
}

function getNestedValue(obj, path) {
return path.split('.').reduce((acc, part) => acc && acc[part], obj);
}

if (colorBy.payload) {
const valuesToColor = {};

return points.map((point) => {
const payloadValue = point.payload[colorBy.payload];
if (!payloadValue) {
const payloadValue = getNestedValue(point.payload, colorBy.payload);
if (payloadValue === undefined || payloadValue === null) {
return BACKGROUND_COLOR;
}
return colorByPayload(payloadValue, valuesToColor);
});
}

if (colorBy.discover_score || colorBy.query) {
if (colorBy.query) {
const scores = points.map((point) => point.score);
const minScore = Math.min(...scores);
const maxScore = Math.max(...scores);
Expand Down
11 changes: 4 additions & 7 deletions src/components/VisualizeChart/requestData.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
/* eslint-disable camelcase */
export function requestData(
qdrantClient,
collectionName,
{ limit, filter = null, vector_name = null, color_by = null }
) {
export function requestData(qdrantClient, collectionName, { limit, filter = null, using = null, color_by = null }) {
// Based on the input parameters, we need to decide what kind of request we need to send
// By default we should do scroll request
// But if we have color_by field which uses query, it should be used instead
Expand All @@ -13,8 +9,9 @@ export function requestData(
query: color_by.query,
limit: limit,
filter: filter,
with_vector: vector_name ? [vector_name] : true,
with_vector: using ? [using] : true,
with_payload: true,
using: using ?? null,
};

return qdrantClient.query(collectionName, query);
Expand All @@ -25,7 +22,7 @@ export function requestData(
const scrollQuery = {
limit: limit,
filter: filter,
with_vector: vector_name ? [vector_name] : true,
with_vector: using ? [using] : true,
with_payload: true,
};

Expand Down
4 changes: 2 additions & 2 deletions src/components/VisualizeChart/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ self.onmessage = function (e) {
const data = [];

const points = e.data?.result?.points;
const vectorName = params.vector_name;
const vectorName = params.using;

if (!points || points.length === 0) {
self.postMessage({
Expand Down Expand Up @@ -71,7 +71,7 @@ self.onmessage = function (e) {
if (vectorType === 'named') {
self.postMessage({
data: [],
error: 'Please select a valid vector name, default vector is not defined',
error: 'Please select a valid vector name (by `using`), default vector is not defined',
});
return;
}
Expand Down
6 changes: 3 additions & 3 deletions src/pages/Visualize.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const query = `
// "payload": "field_name"
// }
//
// - 'vector_name': specify which vector to use for visualization
// - 'using': specify which vector to use for visualization
// if there are multiple.
//
// - 'algorithm': specify algorithm to use for visualization. Available options: 'TSNE', 'UMAP'.
Expand Down Expand Up @@ -100,8 +100,8 @@ function Visualize() {
},
],
},
vector_name: {
description: 'Vector field name',
using: {
description: 'Specify which vector to use for visualization',
type: 'string',
enum: vectorNames,
},
Expand Down
Loading