Public
Edited
Dec 9, 2022
Insert cell
Insert cell
Insert cell
viewof con_index_type = Inputs.select(['ivfflat', 'hnsw'], {label: 'index_type', value: 'ivfflat'})
Insert cell
viewof con_nprobe = Inputs.range([1, 32], {label: 'nprobe', step: 1, disabled: con_index_type !== 'ivfflat', value: 8})
Insert cell
viewof con_ef = Inputs.range([1, 64], {label: 'ef', step: 1, disabled: con_index_type !== 'hnsw', value: 16})
Insert cell
viewof exp_index_type = Inputs.select(['ivfflat', 'hnsw'], {label: 'index_type', value: 'ivfflat'})
Insert cell
viewof exp_nprobe = Inputs.range([1, 32], {label: 'nprobe', step: 1, disabled: exp_index_type !== 'ivfflat', value: 8})
Insert cell
viewof exp_ef = Inputs.range([1, 64], {label: 'ef', step: 1, disabled: exp_index_type !== 'hnsw', value: 16})
Insert cell
getExperimentView(
q,
con_index_type,
{ nprobe: con_nprobe, ef: con_ef, k: 12 },
exp_index_type,
{ nprobe: exp_nprobe, ef: exp_ef, k: 12 }
)
Insert cell
getExperimentView = async (
q,
indexTypeControl,
searchParamsControl,
indexTypeExperiment,
searchParamsExperiment
) => {
const svg = d3
.create("svg")
.attr("width", width)
.attr("height", height)
.style("border", "1px solid #ccc");
const view = svg.node();

const controlNodes = await getNodes(q, indexTypeControl, searchParamsControl);
const experimentNodes = await getNodes(
q,
indexTypeExperiment,
searchParamsExperiment
);
const controlIds = controlNodes.map((node) => node.id);
const experimentIds = experimentNodes.map((node) => node.id);
controlNodes.forEach(
(node) => (node.type = experimentIds.includes(node.id) ? 1 : 0)
);
const addedNodes = experimentNodes.filter(
(node) => !controlIds.includes(node.id)
);

const intersectG = svg.append("g").attr("id", "intersect-view");
const addedG = svg.append("g").attr("id", "added-view");

const xDomain = d3.extent(
[].concat(controlNodes, experimentNodes),
(node) => node.distance
);
const xDomainLength = xDomain[1] - xDomain[0] + 0.01;
const xBinLength = Math.floor(width / (R * 2));

const controlHistogram = [];
for (let i = 0; i < xBinLength; i++) controlHistogram.push([]);
controlNodes.forEach((node) => {
const binX = Math.floor(
((node.distance - xDomain[0]) / xDomainLength) * xBinLength
);
controlHistogram[binX].push(node);
});
smoothHistogram(controlHistogram);
smoothHistogram(controlHistogram);
controlHistogram.forEach((row) => row.sort((a, b) => -a.type + b.type));

const experimentHistogram = [];
for (let i = 0; i < xBinLength; i++) experimentHistogram.push([]);
addedNodes.forEach((node) => {
const binX = Math.floor(
((node.distance - xDomain[0]) / xDomainLength) * xBinLength
);
experimentHistogram[binX].push(node);
});
smoothHistogram(experimentHistogram);
smoothHistogram(experimentHistogram);

const id2binPos = {};
controlHistogram.forEach((row, x) => {
row.forEach(({ id }, y) => (id2binPos[id] = { x, y }));
});
experimentHistogram.forEach((row, x) => {
row.forEach(({ id }, y) => (id2binPos[id] = { x, y }));
});

const intersectNodesG = intersectG
.selectAll("g")
.data(controlNodes)
.join("g")
.attr("transform", (node) => {
return `translate(${(2 * id2binPos[node.id].x + 1) * R}, ${
height / 2 - (2 * id2binPos[node.id].y + 1) * R
})`;
});

const addedNodesG = addedG
.selectAll("g")
.data(addedNodes)
.join("g")
.attr("transform", (node) => {
// console.log(node.id, id2binPos, id2binPos[node.id])
return `translate(${(2 * id2binPos[node.id].x + 1) * R}, ${
height / 2 + (2 * id2binPos[node.id].y + 1) * R
})`;
});

intersectNodesG
.append("circle")
.attr("r", r)
.attr("fill", (node) => colors[node.type]);

addedNodesG.append("circle").attr("r", r).attr("fill", colors[2]);

return view;
}
Insert cell
Insert cell
Insert cell
a = getNodes(q, 'hnsw', {ef: 32, k: 12})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
url = "http://127.0.0.1:12357"
Insert cell
getVisitedRecords = (q, indexType, searchParams) =>
fetch(
`${url}/getSearchRecords?${new URLSearchParams({
indexType,
params: JSON.stringify({ target: q, searchParams })
})}`
).then((res) => res.json()).then(res => res.data)
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more