@nshiab/simple-data-analysis-core 2.0.8 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/class/SDAError.d.ts +6 -6
- package/esm/class/SDAError.js +6 -6
- package/esm/class/Simple.d.ts +9 -9
- package/esm/class/Simple.js +9 -9
- package/esm/class/SimpleDB.d.ts +80 -76
- package/esm/class/SimpleDB.d.ts.map +1 -1
- package/esm/class/SimpleDB.js +80 -76
- package/esm/class/SimpleTable.d.ts +2805 -1077
- package/esm/class/SimpleTable.d.ts.map +1 -1
- package/esm/class/SimpleTable.js +2777 -1077
- package/esm/helpers/appendColumnBatches.d.ts +3 -0
- package/esm/helpers/appendColumnBatches.d.ts.map +1 -0
- package/esm/helpers/appendColumnBatches.js +21 -0
- package/esm/helpers/buildApproximateMutualReachabilityMst.d.ts +45 -0
- package/esm/helpers/buildApproximateMutualReachabilityMst.d.ts.map +1 -0
- package/esm/helpers/buildApproximateMutualReachabilityMst.js +212 -0
- package/esm/helpers/buildChronologicalGraphComponentsSql.d.ts +14 -0
- package/esm/helpers/buildChronologicalGraphComponentsSql.d.ts.map +1 -0
- package/esm/helpers/buildChronologicalGraphComponentsSql.js +167 -0
- package/esm/helpers/buildExactMutualReachabilityMst.d.ts +28 -0
- package/esm/helpers/buildExactMutualReachabilityMst.d.ts.map +1 -0
- package/esm/helpers/buildExactMutualReachabilityMst.js +97 -0
- package/esm/helpers/buildGraphTemporalCostStateSql.d.ts +12 -0
- package/esm/helpers/buildGraphTemporalCostStateSql.d.ts.map +1 -0
- package/esm/helpers/buildGraphTemporalCostStateSql.js +86 -0
- package/esm/helpers/buildGraphTemporalReachabilitySql.d.ts +13 -0
- package/esm/helpers/buildGraphTemporalReachabilitySql.d.ts.map +1 -0
- package/esm/helpers/buildGraphTemporalReachabilitySql.js +70 -0
- package/esm/helpers/buildSparseMutualReachabilityMst.d.ts +10 -0
- package/esm/helpers/buildSparseMutualReachabilityMst.d.ts.map +1 -0
- package/esm/helpers/buildSparseMutualReachabilityMst.js +47 -0
- package/esm/helpers/buildUmapGraph.d.ts +21 -0
- package/esm/helpers/buildUmapGraph.d.ts.map +1 -0
- package/esm/helpers/buildUmapGraph.js +61 -0
- package/esm/helpers/buildVectorNeighbors.d.ts +45 -0
- package/esm/helpers/buildVectorNeighbors.d.ts.map +1 -0
- package/esm/helpers/buildVectorNeighbors.js +170 -0
- package/esm/helpers/buildWeakGraphComponentsSql.d.ts +3 -0
- package/esm/helpers/buildWeakGraphComponentsSql.d.ts.map +1 -0
- package/esm/helpers/buildWeakGraphComponentsSql.js +32 -0
- package/esm/helpers/cacheDatabase.d.ts.map +1 -1
- package/esm/helpers/cacheDatabase.js +2 -1
- package/esm/helpers/camelCase.d.ts +7 -5
- package/esm/helpers/camelCase.d.ts.map +1 -1
- package/esm/helpers/camelCase.js +7 -5
- package/esm/helpers/capitalize.d.ts +6 -4
- package/esm/helpers/capitalize.d.ts.map +1 -1
- package/esm/helpers/capitalize.js +6 -4
- package/esm/helpers/clusterHdbscan.d.ts +18 -0
- package/esm/helpers/clusterHdbscan.d.ts.map +1 -0
- package/esm/helpers/clusterHdbscan.js +342 -0
- package/esm/helpers/computeCovariance.d.ts +16 -0
- package/esm/helpers/computeCovariance.d.ts.map +1 -0
- package/esm/helpers/computeCovariance.js +99 -0
- package/esm/helpers/computeMahalanobisDistances.d.ts +14 -0
- package/esm/helpers/computeMahalanobisDistances.d.ts.map +1 -0
- package/esm/helpers/computeMahalanobisDistances.js +87 -0
- package/esm/helpers/createDirectory.d.ts +4 -3
- package/esm/helpers/createDirectory.d.ts.map +1 -1
- package/esm/helpers/createDirectory.js +4 -3
- package/esm/helpers/dataToArrays.d.ts +6 -4
- package/esm/helpers/dataToArrays.d.ts.map +1 -1
- package/esm/helpers/dataToArrays.js +6 -4
- package/esm/helpers/extractTypes.d.ts +1 -1
- package/esm/helpers/extractTypes.js +4 -9
- package/esm/helpers/factorCovariance.d.ts +17 -0
- package/esm/helpers/factorCovariance.d.ts.map +1 -0
- package/esm/helpers/factorCovariance.js +189 -0
- package/esm/helpers/findGeoColumn.d.ts +6 -4
- package/esm/helpers/findGeoColumn.d.ts.map +1 -1
- package/esm/helpers/findGeoColumn.js +6 -4
- package/esm/helpers/findGeoColumnFromSchema.d.ts +8 -5
- package/esm/helpers/findGeoColumnFromSchema.d.ts.map +1 -1
- package/esm/helpers/findGeoColumnFromSchema.js +8 -5
- package/esm/helpers/fitUmapCurve.d.ts +2 -0
- package/esm/helpers/fitUmapCurve.d.ts.map +1 -0
- package/esm/helpers/fitUmapCurve.js +66 -0
- package/esm/helpers/formatDate.d.ts +12 -6
- package/esm/helpers/formatDate.d.ts.map +1 -1
- package/esm/helpers/formatDate.js +12 -6
- package/esm/helpers/formatMissingTables.d.ts +8 -5
- package/esm/helpers/formatMissingTables.d.ts.map +1 -1
- package/esm/helpers/formatMissingTables.js +8 -5
- package/esm/helpers/formatNumber.d.ts +19 -10
- package/esm/helpers/formatNumber.d.ts.map +1 -1
- package/esm/helpers/formatNumber.js +32 -17
- package/esm/helpers/getGraphEdgeIdColumn.d.ts +9 -0
- package/esm/helpers/getGraphEdgeIdColumn.d.ts.map +1 -0
- package/esm/helpers/getGraphEdgeIdColumn.js +25 -0
- package/esm/helpers/getGraphEndpointColumns.d.ts +11 -0
- package/esm/helpers/getGraphEndpointColumns.d.ts.map +1 -0
- package/esm/helpers/getGraphEndpointColumns.js +160 -0
- package/esm/helpers/getGraphWeightColumn.d.ts +10 -0
- package/esm/helpers/getGraphWeightColumn.d.ts.map +1 -0
- package/esm/helpers/getGraphWeightColumn.js +40 -0
- package/esm/helpers/graphRouteResultSchema.d.ts +4 -0
- package/esm/helpers/graphRouteResultSchema.d.ts.map +1 -0
- package/esm/helpers/graphRouteResultSchema.js +12 -0
- package/esm/helpers/graphRouteResultSelect.d.ts +4 -0
- package/esm/helpers/graphRouteResultSelect.d.ts.map +1 -0
- package/esm/helpers/graphRouteResultSelect.js +22 -0
- package/esm/helpers/hasGeometryColumn.d.ts +4 -3
- package/esm/helpers/hasGeometryColumn.d.ts.map +1 -1
- package/esm/helpers/hasGeometryColumn.js +4 -3
- package/esm/helpers/initialUmapCoordinates.d.ts +2 -0
- package/esm/helpers/initialUmapCoordinates.d.ts.map +1 -0
- package/esm/helpers/initialUmapCoordinates.js +5 -0
- package/esm/helpers/inspectGraphConnectivity.d.ts +10 -0
- package/esm/helpers/inspectGraphConnectivity.d.ts.map +1 -0
- package/esm/helpers/inspectGraphConnectivity.js +55 -0
- package/esm/helpers/mergeOptions.d.ts +24 -13
- package/esm/helpers/mergeOptions.d.ts.map +1 -1
- package/esm/helpers/mergeOptions.js +24 -13
- package/esm/helpers/optimizeUmapLayout.d.ts +7 -0
- package/esm/helpers/optimizeUmapLayout.d.ts.map +1 -0
- package/esm/helpers/optimizeUmapLayout.js +93 -0
- package/esm/helpers/parseValue.d.ts +6 -4
- package/esm/helpers/parseValue.d.ts.map +1 -1
- package/esm/helpers/parseValue.js +6 -4
- package/esm/helpers/prepareGraphRouteSql.d.ts +31 -0
- package/esm/helpers/prepareGraphRouteSql.d.ts.map +1 -0
- package/esm/helpers/prepareGraphRouteSql.js +86 -0
- package/esm/helpers/prepareGraphStarts.d.ts +9 -0
- package/esm/helpers/prepareGraphStarts.d.ts.map +1 -0
- package/esm/helpers/prepareGraphStarts.js +68 -0
- package/esm/helpers/prepareGraphTemporalSql.d.ts +28 -0
- package/esm/helpers/prepareGraphTemporalSql.d.ts.map +1 -0
- package/esm/helpers/prepareGraphTemporalSql.js +154 -0
- package/esm/helpers/prepareGraphTraversal.d.ts +19 -0
- package/esm/helpers/prepareGraphTraversal.d.ts.map +1 -0
- package/esm/helpers/prepareGraphTraversal.js +79 -0
- package/esm/helpers/prepareNumericFeatures.d.ts +41 -0
- package/esm/helpers/prepareNumericFeatures.d.ts.map +1 -0
- package/esm/helpers/prepareNumericFeatures.js +210 -0
- package/esm/helpers/prepareUmapLayoutOptions.d.ts +14 -0
- package/esm/helpers/prepareUmapLayoutOptions.d.ts.map +1 -0
- package/esm/helpers/prepareUmapLayoutOptions.js +23 -0
- package/esm/helpers/prettyDuration.d.ts +14 -8
- package/esm/helpers/prettyDuration.d.ts.map +1 -1
- package/esm/helpers/prettyDuration.js +14 -8
- package/esm/helpers/printTable.d.ts +18 -13
- package/esm/helpers/printTable.d.ts.map +1 -1
- package/esm/helpers/printTable.js +18 -13
- package/esm/helpers/publishPreparedColumns.d.ts +37 -0
- package/esm/helpers/publishPreparedColumns.d.ts.map +1 -0
- package/esm/helpers/publishPreparedColumns.js +113 -0
- package/esm/helpers/queryDB.d.ts +24 -13
- package/esm/helpers/queryDB.d.ts.map +1 -1
- package/esm/helpers/queryDB.js +24 -13
- package/esm/helpers/queueAsyncBarrier.d.ts +12 -7
- package/esm/helpers/queueAsyncBarrier.d.ts.map +1 -1
- package/esm/helpers/queueAsyncBarrier.js +12 -7
- package/esm/helpers/queueGraphResult.d.ts +18 -0
- package/esm/helpers/queueGraphResult.d.ts.map +1 -0
- package/esm/helpers/queueGraphResult.js +39 -0
- package/esm/helpers/quoteIdentifier.d.ts +4 -3
- package/esm/helpers/quoteIdentifier.d.ts.map +1 -1
- package/esm/helpers/quoteIdentifier.js +4 -3
- package/esm/helpers/quoteQualifiedIdentifier.d.ts +6 -4
- package/esm/helpers/quoteQualifiedIdentifier.d.ts.map +1 -1
- package/esm/helpers/quoteQualifiedIdentifier.js +6 -4
- package/esm/helpers/readScalarNumber.d.ts +3 -0
- package/esm/helpers/readScalarNumber.d.ts.map +1 -0
- package/esm/helpers/readScalarNumber.js +4 -0
- package/esm/helpers/runQuery.d.ts.map +1 -1
- package/esm/helpers/runQuery.js +17 -3
- package/esm/helpers/selectFuzzyReplacements.d.ts +11 -0
- package/esm/helpers/selectFuzzyReplacements.d.ts.map +1 -0
- package/esm/helpers/selectFuzzyReplacements.js +124 -0
- package/esm/helpers/stabilizeCosineVectors.d.ts +14 -0
- package/esm/helpers/stabilizeCosineVectors.d.ts.map +1 -0
- package/esm/helpers/stabilizeCosineVectors.js +34 -0
- package/esm/helpers/stringToArray.d.ts +4 -3
- package/esm/helpers/stringToArray.d.ts.map +1 -1
- package/esm/helpers/stringToArray.js +4 -3
- package/esm/helpers/umapRandom.d.ts +2 -0
- package/esm/helpers/umapRandom.d.ts.map +1 -0
- package/esm/helpers/umapRandom.js +10 -0
- package/esm/helpers/updateColumnsWithJS.d.ts +12 -6
- package/esm/helpers/updateColumnsWithJS.d.ts.map +1 -1
- package/esm/helpers/updateColumnsWithJS.js +12 -6
- package/esm/helpers/validateGraphRouteResultSchema.d.ts +4 -0
- package/esm/helpers/validateGraphRouteResultSchema.d.ts.map +1 -0
- package/esm/helpers/validateGraphRouteResultSchema.js +13 -0
- package/esm/helpers/validateGraphTemporalEvents.d.ts +7 -0
- package/esm/helpers/validateGraphTemporalEvents.d.ts.map +1 -0
- package/esm/helpers/validateGraphTemporalEvents.js +47 -0
- package/esm/helpers/validateNumericalAnalysis.d.ts +10 -6
- package/esm/helpers/validateNumericalAnalysis.d.ts.map +1 -1
- package/esm/helpers/validateNumericalAnalysis.js +10 -6
- package/esm/helpers/validateVectorRowIds.d.ts +4 -0
- package/esm/helpers/validateVectorRowIds.d.ts.map +1 -0
- package/esm/helpers/validateVectorRowIds.js +16 -0
- package/esm/helpers/vectorDistanceExpression.d.ts +6 -0
- package/esm/helpers/vectorDistanceExpression.d.ts.map +1 -0
- package/esm/helpers/vectorDistanceExpression.js +11 -0
- package/esm/helpers/wrapString.d.ts +10 -7
- package/esm/helpers/wrapString.d.ts.map +1 -1
- package/esm/helpers/wrapString.js +10 -7
- package/esm/methods/addId.d.ts +5 -0
- package/esm/methods/addId.d.ts.map +1 -0
- package/esm/methods/addId.js +38 -0
- package/esm/methods/cache.js +1 -1
- package/esm/methods/commonNeighbors.d.ts +10 -0
- package/esm/methods/commonNeighbors.d.ts.map +1 -0
- package/esm/methods/commonNeighbors.js +101 -0
- package/esm/methods/connectedComponents.d.ts +9 -0
- package/esm/methods/connectedComponents.d.ts.map +1 -0
- package/esm/methods/connectedComponents.js +147 -0
- package/esm/methods/degree.d.ts +9 -0
- package/esm/methods/degree.d.ts.map +1 -0
- package/esm/methods/degree.js +135 -0
- package/esm/methods/distances.d.ts +12 -0
- package/esm/methods/distances.d.ts.map +1 -0
- package/esm/methods/distances.js +164 -0
- package/esm/methods/findCycles.d.ts +12 -0
- package/esm/methods/findCycles.d.ts.map +1 -0
- package/esm/methods/findCycles.js +330 -0
- package/esm/methods/fuzzyClean.d.ts.map +1 -1
- package/esm/methods/fuzzyClean.js +17 -136
- package/esm/methods/fuzzyJoin.js +70 -16
- package/esm/methods/getTypes.d.ts +1 -1
- package/esm/methods/hdbscan.d.ts +5 -0
- package/esm/methods/hdbscan.d.ts.map +1 -0
- package/esm/methods/hdbscan.js +208 -0
- package/esm/methods/loadArray.d.ts.map +1 -1
- package/esm/methods/loadArray.js +3 -20
- package/esm/methods/mahalanobis.d.ts +5 -0
- package/esm/methods/mahalanobis.d.ts.map +1 -0
- package/esm/methods/mahalanobis.js +92 -0
- package/esm/methods/neighbors.d.ts +9 -0
- package/esm/methods/neighbors.d.ts.map +1 -0
- package/esm/methods/neighbors.js +81 -0
- package/esm/methods/normalizeVector.d.ts +5 -0
- package/esm/methods/normalizeVector.d.ts.map +1 -0
- package/esm/methods/normalizeVector.js +132 -0
- package/esm/methods/paths.d.ts +12 -0
- package/esm/methods/paths.d.ts.map +1 -0
- package/esm/methods/paths.js +287 -0
- package/esm/methods/reachable.d.ts +11 -0
- package/esm/methods/reachable.d.ts.map +1 -0
- package/esm/methods/reachable.js +131 -0
- package/esm/methods/rowToVector.d.ts +5 -0
- package/esm/methods/rowToVector.d.ts.map +1 -0
- package/esm/methods/rowToVector.js +77 -0
- package/esm/methods/shortestPath.d.ts +12 -0
- package/esm/methods/shortestPath.d.ts.map +1 -0
- package/esm/methods/shortestPath.js +337 -0
- package/esm/methods/topologicalSort.d.ts +7 -0
- package/esm/methods/topologicalSort.d.ts.map +1 -0
- package/esm/methods/topologicalSort.js +164 -0
- package/esm/methods/umap.d.ts +5 -0
- package/esm/methods/umap.d.ts.map +1 -0
- package/esm/methods/umap.js +156 -0
- package/esm/methods/updateWithJS.js +9 -21
- package/llm.md +2170 -128
- package/llms.txt +1 -1
- package/package.json +1 -1
- package/script/class/SDAError.d.ts +6 -6
- package/script/class/SDAError.js +6 -6
- package/script/class/Simple.d.ts +9 -9
- package/script/class/Simple.js +9 -9
- package/script/class/SimpleDB.d.ts +80 -76
- package/script/class/SimpleDB.d.ts.map +1 -1
- package/script/class/SimpleDB.js +80 -76
- package/script/class/SimpleTable.d.ts +2805 -1077
- package/script/class/SimpleTable.d.ts.map +1 -1
- package/script/class/SimpleTable.js +2777 -1077
- package/script/helpers/appendColumnBatches.d.ts +3 -0
- package/script/helpers/appendColumnBatches.d.ts.map +1 -0
- package/script/helpers/appendColumnBatches.js +24 -0
- package/script/helpers/buildApproximateMutualReachabilityMst.d.ts +45 -0
- package/script/helpers/buildApproximateMutualReachabilityMst.d.ts.map +1 -0
- package/script/helpers/buildApproximateMutualReachabilityMst.js +219 -0
- package/script/helpers/buildChronologicalGraphComponentsSql.d.ts +14 -0
- package/script/helpers/buildChronologicalGraphComponentsSql.d.ts.map +1 -0
- package/script/helpers/buildChronologicalGraphComponentsSql.js +174 -0
- package/script/helpers/buildExactMutualReachabilityMst.d.ts +28 -0
- package/script/helpers/buildExactMutualReachabilityMst.d.ts.map +1 -0
- package/script/helpers/buildExactMutualReachabilityMst.js +103 -0
- package/script/helpers/buildGraphTemporalCostStateSql.d.ts +12 -0
- package/script/helpers/buildGraphTemporalCostStateSql.d.ts.map +1 -0
- package/script/helpers/buildGraphTemporalCostStateSql.js +92 -0
- package/script/helpers/buildGraphTemporalReachabilitySql.d.ts +13 -0
- package/script/helpers/buildGraphTemporalReachabilitySql.d.ts.map +1 -0
- package/script/helpers/buildGraphTemporalReachabilitySql.js +76 -0
- package/script/helpers/buildSparseMutualReachabilityMst.d.ts +10 -0
- package/script/helpers/buildSparseMutualReachabilityMst.d.ts.map +1 -0
- package/script/helpers/buildSparseMutualReachabilityMst.js +50 -0
- package/script/helpers/buildUmapGraph.d.ts +21 -0
- package/script/helpers/buildUmapGraph.d.ts.map +1 -0
- package/script/helpers/buildUmapGraph.js +67 -0
- package/script/helpers/buildVectorNeighbors.d.ts +45 -0
- package/script/helpers/buildVectorNeighbors.d.ts.map +1 -0
- package/script/helpers/buildVectorNeighbors.js +176 -0
- package/script/helpers/buildWeakGraphComponentsSql.d.ts +3 -0
- package/script/helpers/buildWeakGraphComponentsSql.d.ts.map +1 -0
- package/script/helpers/buildWeakGraphComponentsSql.js +38 -0
- package/script/helpers/cacheDatabase.d.ts.map +1 -1
- package/script/helpers/cacheDatabase.js +2 -1
- package/script/helpers/camelCase.d.ts +7 -5
- package/script/helpers/camelCase.d.ts.map +1 -1
- package/script/helpers/camelCase.js +7 -5
- package/script/helpers/capitalize.d.ts +6 -4
- package/script/helpers/capitalize.d.ts.map +1 -1
- package/script/helpers/capitalize.js +6 -4
- package/script/helpers/clusterHdbscan.d.ts +18 -0
- package/script/helpers/clusterHdbscan.d.ts.map +1 -0
- package/script/helpers/clusterHdbscan.js +346 -0
- package/script/helpers/computeCovariance.d.ts +16 -0
- package/script/helpers/computeCovariance.d.ts.map +1 -0
- package/script/helpers/computeCovariance.js +105 -0
- package/script/helpers/computeMahalanobisDistances.d.ts +14 -0
- package/script/helpers/computeMahalanobisDistances.d.ts.map +1 -0
- package/script/helpers/computeMahalanobisDistances.js +93 -0
- package/script/helpers/createDirectory.d.ts +4 -3
- package/script/helpers/createDirectory.d.ts.map +1 -1
- package/script/helpers/createDirectory.js +4 -3
- package/script/helpers/dataToArrays.d.ts +6 -4
- package/script/helpers/dataToArrays.d.ts.map +1 -1
- package/script/helpers/dataToArrays.js +6 -4
- package/script/helpers/extractTypes.d.ts +1 -1
- package/script/helpers/extractTypes.js +4 -9
- package/script/helpers/factorCovariance.d.ts +17 -0
- package/script/helpers/factorCovariance.d.ts.map +1 -0
- package/script/helpers/factorCovariance.js +194 -0
- package/script/helpers/findGeoColumn.d.ts +6 -4
- package/script/helpers/findGeoColumn.d.ts.map +1 -1
- package/script/helpers/findGeoColumn.js +6 -4
- package/script/helpers/findGeoColumnFromSchema.d.ts +8 -5
- package/script/helpers/findGeoColumnFromSchema.d.ts.map +1 -1
- package/script/helpers/findGeoColumnFromSchema.js +8 -5
- package/script/helpers/fitUmapCurve.d.ts +2 -0
- package/script/helpers/fitUmapCurve.d.ts.map +1 -0
- package/script/helpers/fitUmapCurve.js +69 -0
- package/script/helpers/formatDate.d.ts +12 -6
- package/script/helpers/formatDate.d.ts.map +1 -1
- package/script/helpers/formatDate.js +12 -6
- package/script/helpers/formatMissingTables.d.ts +8 -5
- package/script/helpers/formatMissingTables.d.ts.map +1 -1
- package/script/helpers/formatMissingTables.js +8 -5
- package/script/helpers/formatNumber.d.ts +19 -10
- package/script/helpers/formatNumber.d.ts.map +1 -1
- package/script/helpers/formatNumber.js +32 -17
- package/script/helpers/getGraphEdgeIdColumn.d.ts +9 -0
- package/script/helpers/getGraphEdgeIdColumn.d.ts.map +1 -0
- package/script/helpers/getGraphEdgeIdColumn.js +31 -0
- package/script/helpers/getGraphEndpointColumns.d.ts +11 -0
- package/script/helpers/getGraphEndpointColumns.d.ts.map +1 -0
- package/script/helpers/getGraphEndpointColumns.js +166 -0
- package/script/helpers/getGraphWeightColumn.d.ts +10 -0
- package/script/helpers/getGraphWeightColumn.d.ts.map +1 -0
- package/script/helpers/getGraphWeightColumn.js +46 -0
- package/script/helpers/graphRouteResultSchema.d.ts +4 -0
- package/script/helpers/graphRouteResultSchema.d.ts.map +1 -0
- package/script/helpers/graphRouteResultSchema.js +18 -0
- package/script/helpers/graphRouteResultSelect.d.ts +4 -0
- package/script/helpers/graphRouteResultSelect.d.ts.map +1 -0
- package/script/helpers/graphRouteResultSelect.js +28 -0
- package/script/helpers/hasGeometryColumn.d.ts +4 -3
- package/script/helpers/hasGeometryColumn.d.ts.map +1 -1
- package/script/helpers/hasGeometryColumn.js +4 -3
- package/script/helpers/initialUmapCoordinates.d.ts +2 -0
- package/script/helpers/initialUmapCoordinates.d.ts.map +1 -0
- package/script/helpers/initialUmapCoordinates.js +11 -0
- package/script/helpers/inspectGraphConnectivity.d.ts +10 -0
- package/script/helpers/inspectGraphConnectivity.d.ts.map +1 -0
- package/script/helpers/inspectGraphConnectivity.js +58 -0
- package/script/helpers/mergeOptions.d.ts +24 -13
- package/script/helpers/mergeOptions.d.ts.map +1 -1
- package/script/helpers/mergeOptions.js +24 -13
- package/script/helpers/optimizeUmapLayout.d.ts +7 -0
- package/script/helpers/optimizeUmapLayout.d.ts.map +1 -0
- package/script/helpers/optimizeUmapLayout.js +99 -0
- package/script/helpers/parseValue.d.ts +6 -4
- package/script/helpers/parseValue.d.ts.map +1 -1
- package/script/helpers/parseValue.js +6 -4
- package/script/helpers/prepareGraphRouteSql.d.ts +31 -0
- package/script/helpers/prepareGraphRouteSql.d.ts.map +1 -0
- package/script/helpers/prepareGraphRouteSql.js +127 -0
- package/script/helpers/prepareGraphStarts.d.ts +9 -0
- package/script/helpers/prepareGraphStarts.d.ts.map +1 -0
- package/script/helpers/prepareGraphStarts.js +71 -0
- package/script/helpers/prepareGraphTemporalSql.d.ts +28 -0
- package/script/helpers/prepareGraphTemporalSql.d.ts.map +1 -0
- package/script/helpers/prepareGraphTemporalSql.js +161 -0
- package/script/helpers/prepareGraphTraversal.d.ts +19 -0
- package/script/helpers/prepareGraphTraversal.d.ts.map +1 -0
- package/script/helpers/prepareGraphTraversal.js +87 -0
- package/script/helpers/prepareNumericFeatures.d.ts +41 -0
- package/script/helpers/prepareNumericFeatures.d.ts.map +1 -0
- package/script/helpers/prepareNumericFeatures.js +217 -0
- package/script/helpers/prepareUmapLayoutOptions.d.ts +14 -0
- package/script/helpers/prepareUmapLayoutOptions.d.ts.map +1 -0
- package/script/helpers/prepareUmapLayoutOptions.js +29 -0
- package/script/helpers/prettyDuration.d.ts +14 -8
- package/script/helpers/prettyDuration.d.ts.map +1 -1
- package/script/helpers/prettyDuration.js +14 -8
- package/script/helpers/printTable.d.ts +18 -13
- package/script/helpers/printTable.d.ts.map +1 -1
- package/script/helpers/printTable.js +18 -13
- package/script/helpers/publishPreparedColumns.d.ts +37 -0
- package/script/helpers/publishPreparedColumns.d.ts.map +1 -0
- package/script/helpers/publishPreparedColumns.js +119 -0
- package/script/helpers/queryDB.d.ts +24 -13
- package/script/helpers/queryDB.d.ts.map +1 -1
- package/script/helpers/queryDB.js +24 -13
- package/script/helpers/queueAsyncBarrier.d.ts +12 -7
- package/script/helpers/queueAsyncBarrier.d.ts.map +1 -1
- package/script/helpers/queueAsyncBarrier.js +12 -7
- package/script/helpers/queueGraphResult.d.ts +18 -0
- package/script/helpers/queueGraphResult.d.ts.map +1 -0
- package/script/helpers/queueGraphResult.js +45 -0
- package/script/helpers/quoteIdentifier.d.ts +4 -3
- package/script/helpers/quoteIdentifier.d.ts.map +1 -1
- package/script/helpers/quoteIdentifier.js +4 -3
- package/script/helpers/quoteQualifiedIdentifier.d.ts +6 -4
- package/script/helpers/quoteQualifiedIdentifier.d.ts.map +1 -1
- package/script/helpers/quoteQualifiedIdentifier.js +6 -4
- package/script/helpers/readScalarNumber.d.ts +3 -0
- package/script/helpers/readScalarNumber.d.ts.map +1 -0
- package/script/helpers/readScalarNumber.js +7 -0
- package/script/helpers/runQuery.d.ts.map +1 -1
- package/script/helpers/runQuery.js +17 -3
- package/script/helpers/selectFuzzyReplacements.d.ts +11 -0
- package/script/helpers/selectFuzzyReplacements.d.ts.map +1 -0
- package/script/helpers/selectFuzzyReplacements.js +127 -0
- package/script/helpers/stabilizeCosineVectors.d.ts +14 -0
- package/script/helpers/stabilizeCosineVectors.d.ts.map +1 -0
- package/script/helpers/stabilizeCosineVectors.js +40 -0
- package/script/helpers/stringToArray.d.ts +4 -3
- package/script/helpers/stringToArray.d.ts.map +1 -1
- package/script/helpers/stringToArray.js +4 -3
- package/script/helpers/umapRandom.d.ts +2 -0
- package/script/helpers/umapRandom.d.ts.map +1 -0
- package/script/helpers/umapRandom.js +13 -0
- package/script/helpers/updateColumnsWithJS.d.ts +12 -6
- package/script/helpers/updateColumnsWithJS.d.ts.map +1 -1
- package/script/helpers/updateColumnsWithJS.js +12 -6
- package/script/helpers/validateGraphRouteResultSchema.d.ts +4 -0
- package/script/helpers/validateGraphRouteResultSchema.d.ts.map +1 -0
- package/script/helpers/validateGraphRouteResultSchema.js +19 -0
- package/script/helpers/validateGraphTemporalEvents.d.ts +7 -0
- package/script/helpers/validateGraphTemporalEvents.d.ts.map +1 -0
- package/script/helpers/validateGraphTemporalEvents.js +53 -0
- package/script/helpers/validateNumericalAnalysis.d.ts +10 -6
- package/script/helpers/validateNumericalAnalysis.d.ts.map +1 -1
- package/script/helpers/validateNumericalAnalysis.js +10 -6
- package/script/helpers/validateVectorRowIds.d.ts +4 -0
- package/script/helpers/validateVectorRowIds.d.ts.map +1 -0
- package/script/helpers/validateVectorRowIds.js +19 -0
- package/script/helpers/vectorDistanceExpression.d.ts +6 -0
- package/script/helpers/vectorDistanceExpression.d.ts.map +1 -0
- package/script/helpers/vectorDistanceExpression.js +14 -0
- package/script/helpers/wrapString.d.ts +10 -7
- package/script/helpers/wrapString.d.ts.map +1 -1
- package/script/helpers/wrapString.js +10 -7
- package/script/methods/addId.d.ts +5 -0
- package/script/methods/addId.d.ts.map +1 -0
- package/script/methods/addId.js +44 -0
- package/script/methods/cache.js +1 -1
- package/script/methods/commonNeighbors.d.ts +10 -0
- package/script/methods/commonNeighbors.d.ts.map +1 -0
- package/script/methods/commonNeighbors.js +140 -0
- package/script/methods/connectedComponents.d.ts +9 -0
- package/script/methods/connectedComponents.d.ts.map +1 -0
- package/script/methods/connectedComponents.js +186 -0
- package/script/methods/degree.d.ts +9 -0
- package/script/methods/degree.d.ts.map +1 -0
- package/script/methods/degree.js +141 -0
- package/script/methods/distances.d.ts +12 -0
- package/script/methods/distances.d.ts.map +1 -0
- package/script/methods/distances.js +203 -0
- package/script/methods/findCycles.d.ts +12 -0
- package/script/methods/findCycles.d.ts.map +1 -0
- package/script/methods/findCycles.js +369 -0
- package/script/methods/fuzzyClean.d.ts.map +1 -1
- package/script/methods/fuzzyClean.js +17 -136
- package/script/methods/fuzzyJoin.js +70 -16
- package/script/methods/getTypes.d.ts +1 -1
- package/script/methods/hdbscan.d.ts +5 -0
- package/script/methods/hdbscan.d.ts.map +1 -0
- package/script/methods/hdbscan.js +214 -0
- package/script/methods/loadArray.d.ts.map +1 -1
- package/script/methods/loadArray.js +2 -19
- package/script/methods/mahalanobis.d.ts +5 -0
- package/script/methods/mahalanobis.d.ts.map +1 -0
- package/script/methods/mahalanobis.js +98 -0
- package/script/methods/neighbors.d.ts +9 -0
- package/script/methods/neighbors.d.ts.map +1 -0
- package/script/methods/neighbors.js +120 -0
- package/script/methods/normalizeVector.d.ts +5 -0
- package/script/methods/normalizeVector.d.ts.map +1 -0
- package/script/methods/normalizeVector.js +138 -0
- package/script/methods/paths.d.ts +12 -0
- package/script/methods/paths.d.ts.map +1 -0
- package/script/methods/paths.js +326 -0
- package/script/methods/reachable.d.ts +11 -0
- package/script/methods/reachable.d.ts.map +1 -0
- package/script/methods/reachable.js +170 -0
- package/script/methods/rowToVector.d.ts +5 -0
- package/script/methods/rowToVector.d.ts.map +1 -0
- package/script/methods/rowToVector.js +83 -0
- package/script/methods/shortestPath.d.ts +12 -0
- package/script/methods/shortestPath.d.ts.map +1 -0
- package/script/methods/shortestPath.js +376 -0
- package/script/methods/topologicalSort.d.ts +7 -0
- package/script/methods/topologicalSort.d.ts.map +1 -0
- package/script/methods/topologicalSort.js +170 -0
- package/script/methods/umap.d.ts +5 -0
- package/script/methods/umap.d.ts.map +1 -0
- package/script/methods/umap.js +162 -0
- package/script/methods/updateWithJS.js +9 -21
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import quoteIdentifier from "./quoteIdentifier.js";
|
|
2
|
+
/** Builds keyed best-cost chronological states from an arbitrary start relation. */
|
|
3
|
+
export default function buildGraphTemporalCostStateSql(prepared, startsSelect, direction, temporal, distanceType, edgeWeight, eventSelections = []) {
|
|
4
|
+
const q = quoteIdentifier;
|
|
5
|
+
const relations = prepared.relationNames([
|
|
6
|
+
"graph_starts",
|
|
7
|
+
"graph_temporal_settings",
|
|
8
|
+
"graph_event_rows",
|
|
9
|
+
"graph_edges",
|
|
10
|
+
"graph_cost_states",
|
|
11
|
+
]);
|
|
12
|
+
const startsRelation = relations.graph_starts;
|
|
13
|
+
const settingsRelation = relations.graph_temporal_settings;
|
|
14
|
+
const eventRowsRelation = relations.graph_event_rows;
|
|
15
|
+
const edgesRelation = relations.graph_edges;
|
|
16
|
+
const costRelation = relations.graph_cost_states;
|
|
17
|
+
const start = `${q("starts")}.${q("start")}`;
|
|
18
|
+
const startKey = `${q("starts")}.${q("__key")}`;
|
|
19
|
+
const reachedStart = `${q("reached")}.${q("start")}`;
|
|
20
|
+
const reachedStartKey = `${q("reached")}.${q("__start_key")}`;
|
|
21
|
+
const reachedNodeKey = `${q("reached")}.${q("__node_key")}`;
|
|
22
|
+
const reachedDistance = `${q("reached")}.${q("distance")}`;
|
|
23
|
+
const edgeTo = `${q("edges")}.${q("__to")}`;
|
|
24
|
+
const edgeToKey = `${q("edges")}.${q("__to_key")}`;
|
|
25
|
+
const edgeFromKey = `${q("edges")}.${q("__from_key")}`;
|
|
26
|
+
const eventId = `${q("edges")}.${q("__event_id")}`;
|
|
27
|
+
const eventStart = `${q("edges")}.${q("__event_start")}`;
|
|
28
|
+
const eventEnd = `${q("edges")}.${q("__event_end")}`;
|
|
29
|
+
const edgeCost = `${q("edges")}.${q("__weight")}`;
|
|
30
|
+
const bestDistance = `${q("best")}.${q("distance")}`;
|
|
31
|
+
const gap = `${q("settings")}.${q("__gap")}`;
|
|
32
|
+
const candidateDistance = `CAST(${reachedDistance} + ${edgeCost} AS ${distanceType})`;
|
|
33
|
+
const resolvedStartsSelect = typeof startsSelect === "string"
|
|
34
|
+
? startsSelect
|
|
35
|
+
: startsSelect(edgesRelation);
|
|
36
|
+
// Only costs for the same start and physical event can dominate each other.
|
|
37
|
+
// Strict improvements and non-negative weights terminate even zero-cost cycles.
|
|
38
|
+
return {
|
|
39
|
+
costRelation,
|
|
40
|
+
edgesRelation,
|
|
41
|
+
settingsRelation,
|
|
42
|
+
startsRelation,
|
|
43
|
+
withClause: `WITH RECURSIVE ${settingsRelation} AS MATERIALIZED (
|
|
44
|
+
SELECT CAST(? AS HUGEINT) AS ${q("__gap")}
|
|
45
|
+
), ${eventRowsRelation} AS MATERIALIZED (
|
|
46
|
+
${prepared.edges(direction, [
|
|
47
|
+
`${edgeWeight} AS ${q("__weight")}`,
|
|
48
|
+
...eventSelections,
|
|
49
|
+
...temporal.eventSelections("edges"),
|
|
50
|
+
])}
|
|
51
|
+
), ${edgesRelation} AS MATERIALIZED (
|
|
52
|
+
SELECT *
|
|
53
|
+
FROM ${eventRowsRelation} AS ${q("events")}
|
|
54
|
+
WHERE ${temporal.eventValidity("events")}
|
|
55
|
+
), ${startsRelation} AS MATERIALIZED (
|
|
56
|
+
${resolvedStartsSelect}
|
|
57
|
+
), ${costRelation}(
|
|
58
|
+
${q("start")}, ${q("node")},
|
|
59
|
+
${q("__start_key")}, ${q("__node_key")},
|
|
60
|
+
${q("__event_id")}, ${q("__event_start")}, ${q("__event_end")},
|
|
61
|
+
${q("distance")}
|
|
62
|
+
) USING KEY(${q("__start_key")}, ${q("__event_id")}) AS (
|
|
63
|
+
SELECT ${start}, ${edgeTo}, ${startKey}, ${edgeToKey},
|
|
64
|
+
${eventId}, ${eventStart}, ${eventEnd}, ${edgeCost}
|
|
65
|
+
FROM ${startsRelation} AS ${q("starts")}
|
|
66
|
+
INNER JOIN ${edgesRelation} AS ${q("edges")}
|
|
67
|
+
ON ${startKey} = ${edgeFromKey}
|
|
68
|
+
UNION
|
|
69
|
+
SELECT ${reachedStart}, ${edgeTo}, ${reachedStartKey}, ${edgeToKey},
|
|
70
|
+
${eventId}, ${eventStart}, ${eventEnd},
|
|
71
|
+
MIN(${candidateDistance}) AS ${q("distance")}
|
|
72
|
+
FROM ${costRelation} AS ${q("reached")}
|
|
73
|
+
INNER JOIN ${edgesRelation} AS ${q("edges")}
|
|
74
|
+
ON ${reachedNodeKey} = ${edgeFromKey}
|
|
75
|
+
CROSS JOIN ${settingsRelation} AS ${q("settings")}
|
|
76
|
+
LEFT JOIN recurring.${costRelation} AS ${q("best")}
|
|
77
|
+
ON ${reachedStartKey} = ${q("best")}.${q("__start_key")}
|
|
78
|
+
AND ${eventId} = ${q("best")}.${q("__event_id")}
|
|
79
|
+
WHERE ${temporal.transition("reached", "edges", direction, gap)}
|
|
80
|
+
GROUP BY ${reachedStart}, ${edgeTo}, ${reachedStartKey}, ${edgeToKey},
|
|
81
|
+
${eventId}, ${eventStart}, ${eventEnd}, ${bestDistance}
|
|
82
|
+
HAVING ${bestDistance} IS NULL OR
|
|
83
|
+
MIN(${candidateDistance}) < ${bestDistance}
|
|
84
|
+
)`,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { PreparedGraphTemporalSql } from "./prepareGraphTemporalSql.js";
|
|
2
|
+
import type { GraphDirection, PreparedGraphSql } from "./prepareGraphTraversal.js";
|
|
3
|
+
export type GraphTemporalReachabilitySql = {
|
|
4
|
+
edgesRelation: string;
|
|
5
|
+
reachableRelation: string;
|
|
6
|
+
withClause: string;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Builds reusable chronological reachability CTEs from a start relation.
|
|
10
|
+
* A callback may derive all-node starts from the materialized valid edges.
|
|
11
|
+
*/
|
|
12
|
+
export default function buildGraphTemporalReachabilitySql(prepared: PreparedGraphSql, startsSelect: string | ((validEdgesRelation: string) => string), direction: Exclude<GraphDirection, "both">, temporal: PreparedGraphTemporalSql): GraphTemporalReachabilitySql;
|
|
13
|
+
//# sourceMappingURL=buildGraphTemporalReachabilitySql.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildGraphTemporalReachabilitySql.d.ts","sourceRoot":"","sources":["../../src/helpers/buildGraphTemporalReachabilitySql.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAC7E,OAAO,KAAK,EACV,cAAc,EACd,gBAAgB,EACjB,MAAM,4BAA4B,CAAC;AAGpC,MAAM,MAAM,4BAA4B,GAAG;IACzC,aAAa,EAAE,MAAM,CAAC;IACtB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,OAAO,UAAU,iCAAiC,CACvD,QAAQ,EAAE,gBAAgB,EAC1B,YAAY,EAAE,MAAM,GAAG,CAAC,CAAC,kBAAkB,EAAE,MAAM,KAAK,MAAM,CAAC,EAC/D,SAAS,EAAE,OAAO,CAAC,cAAc,EAAE,MAAM,CAAC,EAC1C,QAAQ,EAAE,wBAAwB,GACjC,4BAA4B,CAiE9B"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import quoteIdentifier from "./quoteIdentifier.js";
|
|
2
|
+
/**
|
|
3
|
+
* Builds reusable chronological reachability CTEs from a start relation.
|
|
4
|
+
* A callback may derive all-node starts from the materialized valid edges.
|
|
5
|
+
*/
|
|
6
|
+
export default function buildGraphTemporalReachabilitySql(prepared, startsSelect, direction, temporal) {
|
|
7
|
+
const q = quoteIdentifier;
|
|
8
|
+
const relations = prepared.relationNames([
|
|
9
|
+
"graph_starts",
|
|
10
|
+
"graph_temporal_settings",
|
|
11
|
+
"graph_event_rows",
|
|
12
|
+
"graph_edges",
|
|
13
|
+
"graph_reachable_states",
|
|
14
|
+
]);
|
|
15
|
+
const startsRelation = relations.graph_starts;
|
|
16
|
+
const settingsRelation = relations.graph_temporal_settings;
|
|
17
|
+
const eventRowsRelation = relations.graph_event_rows;
|
|
18
|
+
const edgesRelation = relations.graph_edges;
|
|
19
|
+
const reachableRelation = relations.graph_reachable_states;
|
|
20
|
+
const start = `${q("starts")}.${q("start")}`;
|
|
21
|
+
const startKey = `${q("starts")}.${q("__key")}`;
|
|
22
|
+
const reachedStart = `${q("reached")}.${q("start")}`;
|
|
23
|
+
const reachedStartKey = `${q("reached")}.${q("__start_key")}`;
|
|
24
|
+
const reachedNodeKey = `${q("reached")}.${q("__node_key")}`;
|
|
25
|
+
const edgeTo = `${q("edges")}.${q("__to")}`;
|
|
26
|
+
const edgeToKey = `${q("edges")}.${q("__to_key")}`;
|
|
27
|
+
const edgeFromKey = `${q("edges")}.${q("__from_key")}`;
|
|
28
|
+
const eventId = `${q("edges")}.${q("__event_id")}`;
|
|
29
|
+
const eventStart = `${q("edges")}.${q("__event_start")}`;
|
|
30
|
+
const eventEnd = `${q("edges")}.${q("__event_end")}`;
|
|
31
|
+
const gap = `${q("settings")}.${q("__gap")}`;
|
|
32
|
+
const resolvedStartsSelect = typeof startsSelect === "string"
|
|
33
|
+
? startsSelect
|
|
34
|
+
: startsSelect(edgesRelation);
|
|
35
|
+
// Materialized event IDs stay fixed; UNION bounds states to starts × events,
|
|
36
|
+
// including equal-time cycles, because the last event determines all next steps.
|
|
37
|
+
return {
|
|
38
|
+
edgesRelation,
|
|
39
|
+
reachableRelation,
|
|
40
|
+
withClause: `WITH RECURSIVE ${settingsRelation} AS MATERIALIZED (
|
|
41
|
+
SELECT CAST(? AS HUGEINT) AS ${q("__gap")}
|
|
42
|
+
), ${eventRowsRelation} AS MATERIALIZED (
|
|
43
|
+
${prepared.edges(direction, temporal.eventSelections("edges"))}
|
|
44
|
+
), ${edgesRelation} AS MATERIALIZED (
|
|
45
|
+
SELECT *
|
|
46
|
+
FROM ${eventRowsRelation} AS ${q("events")}
|
|
47
|
+
WHERE ${temporal.eventValidity("events")}
|
|
48
|
+
), ${startsRelation} AS MATERIALIZED (
|
|
49
|
+
${resolvedStartsSelect}
|
|
50
|
+
), ${reachableRelation}(
|
|
51
|
+
${q("start")}, ${q("node")},
|
|
52
|
+
${q("__start_key")}, ${q("__node_key")},
|
|
53
|
+
${q("__event_id")}, ${q("__event_start")}, ${q("__event_end")}
|
|
54
|
+
) AS (
|
|
55
|
+
SELECT ${start}, ${edgeTo}, ${startKey}, ${edgeToKey},
|
|
56
|
+
${eventId}, ${eventStart}, ${eventEnd}
|
|
57
|
+
FROM ${startsRelation} AS ${q("starts")}
|
|
58
|
+
INNER JOIN ${edgesRelation} AS ${q("edges")}
|
|
59
|
+
ON ${startKey} = ${edgeFromKey}
|
|
60
|
+
UNION
|
|
61
|
+
SELECT ${reachedStart}, ${edgeTo}, ${reachedStartKey}, ${edgeToKey},
|
|
62
|
+
${eventId}, ${eventStart}, ${eventEnd}
|
|
63
|
+
FROM ${reachableRelation} AS ${q("reached")}
|
|
64
|
+
INNER JOIN ${edgesRelation} AS ${q("edges")}
|
|
65
|
+
ON ${reachedNodeKey} = ${edgeFromKey}
|
|
66
|
+
CROSS JOIN ${settingsRelation} AS ${q("settings")}
|
|
67
|
+
WHERE ${temporal.transition("reached", "edges", direction, gap)}
|
|
68
|
+
)`,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { DuckDBConnection } from "@duckdb/node-api";
|
|
2
|
+
type WeightedEdge = {
|
|
3
|
+
source: number;
|
|
4
|
+
target: number;
|
|
5
|
+
distance: number;
|
|
6
|
+
};
|
|
7
|
+
/** Select a deterministically ordered MST from a connected sparse candidate graph. */
|
|
8
|
+
export default function buildSparseMutualReachabilityMst(connection: DuckDBConnection, edges: string, count: number): Promise<WeightedEdge[]>;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=buildSparseMutualReachabilityMst.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildSparseMutualReachabilityMst.d.ts","sourceRoot":"","sources":["../../src/helpers/buildSparseMutualReachabilityMst.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEzD,KAAK,YAAY,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AAEzE,sFAAsF;AACtF,wBAA8B,gCAAgC,CAC5D,UAAU,EAAE,gBAAgB,EAC5B,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,YAAY,EAAE,CAAC,CA4CzB"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** Select a deterministically ordered MST from a connected sparse candidate graph. */
|
|
2
|
+
export default async function buildSparseMutualReachabilityMst(connection, edges, count) {
|
|
3
|
+
const parent = new Int32Array(count);
|
|
4
|
+
const size = new Int32Array(count).fill(1);
|
|
5
|
+
for (let vertex = 0; vertex < count; vertex++)
|
|
6
|
+
parent[vertex] = vertex;
|
|
7
|
+
const find = (start) => {
|
|
8
|
+
let root = start;
|
|
9
|
+
while (parent[root] !== root)
|
|
10
|
+
root = parent[root];
|
|
11
|
+
let current = start;
|
|
12
|
+
while (parent[current] !== current) {
|
|
13
|
+
const next = parent[current];
|
|
14
|
+
parent[current] = root;
|
|
15
|
+
current = next;
|
|
16
|
+
}
|
|
17
|
+
return root;
|
|
18
|
+
};
|
|
19
|
+
const mst = [];
|
|
20
|
+
const result = await connection.stream(`SELECT source,target,distance FROM ${edges}
|
|
21
|
+
ORDER BY distance,source,target`);
|
|
22
|
+
while (mst.length < count - 1) {
|
|
23
|
+
const chunk = await result.fetchChunk();
|
|
24
|
+
if (!chunk || chunk.rowCount === 0)
|
|
25
|
+
break;
|
|
26
|
+
const sources = chunk.getColumnVector(0);
|
|
27
|
+
const targets = chunk.getColumnVector(1);
|
|
28
|
+
const distances = chunk.getColumnVector(2);
|
|
29
|
+
for (let row = 0; row < chunk.rowCount && mst.length < count - 1; row++) {
|
|
30
|
+
const source = Number(sources.getItem(row));
|
|
31
|
+
const target = Number(targets.getItem(row));
|
|
32
|
+
const distance = Number(distances.getItem(row));
|
|
33
|
+
let left = find(source), right = find(target);
|
|
34
|
+
if (left === right)
|
|
35
|
+
continue;
|
|
36
|
+
if (size[left] < size[right])
|
|
37
|
+
[left, right] = [right, left];
|
|
38
|
+
parent[right] = left;
|
|
39
|
+
size[left] += size[right];
|
|
40
|
+
mst.push({ source, target, distance });
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (mst.length !== count - 1) {
|
|
44
|
+
throw new Error("Approximate HDBSCAN candidate graph has no spanning tree.");
|
|
45
|
+
}
|
|
46
|
+
return mst;
|
|
47
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { DuckDBConnection } from "@duckdb/node-api";
|
|
2
|
+
import { type VectorNeighborTables } from "./buildVectorNeighbors.js";
|
|
3
|
+
export type UmapTables = Omit<VectorNeighborTables, "neighbors"> & {
|
|
4
|
+
knn: string;
|
|
5
|
+
scales: string;
|
|
6
|
+
directed: string;
|
|
7
|
+
graph: string;
|
|
8
|
+
};
|
|
9
|
+
export default function buildUmapGraph(connection: DuckDBConnection, input: {
|
|
10
|
+
count: number;
|
|
11
|
+
dimensions: number;
|
|
12
|
+
neighbors: number;
|
|
13
|
+
}, options: {
|
|
14
|
+
metric: "euclidean" | "cosine";
|
|
15
|
+
search: "exact" | "hnsw";
|
|
16
|
+
}, names: UmapTables): Promise<{
|
|
17
|
+
source: Uint32Array<ArrayBuffer>;
|
|
18
|
+
target: Uint32Array<ArrayBuffer>;
|
|
19
|
+
weight: Float64Array<ArrayBuffer>;
|
|
20
|
+
}>;
|
|
21
|
+
//# sourceMappingURL=buildUmapGraph.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildUmapGraph.d.ts","sourceRoot":"","sources":["../../src/helpers/buildUmapGraph.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEzD,OAA6B,EAC3B,KAAK,oBAAoB,EAC1B,MAAM,2BAA2B,CAAC;AAInC,MAAM,MAAM,UAAU,GAAG,IAAI,CAAC,oBAAoB,EAAE,WAAW,CAAC,GAAG;IACjE,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,wBAA8B,cAAc,CAC1C,UAAU,EAAE,gBAAgB,EAC5B,KAAK,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,EAC/D,OAAO,EAAE;IAAE,MAAM,EAAE,WAAW,GAAG,QAAQ,CAAC;IAAC,MAAM,EAAE,OAAO,GAAG,MAAM,CAAA;CAAE,EACrE,KAAK,EAAE,UAAU;;;;GA2ClB"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import readScalarNumber from "./readScalarNumber.js";
|
|
2
|
+
import buildVectorNeighbors from "./buildVectorNeighbors.js";
|
|
3
|
+
export default async function buildUmapGraph(connection, input, options, names) {
|
|
4
|
+
await buildVectorNeighbors(connection, {
|
|
5
|
+
count: input.count,
|
|
6
|
+
dimensions: input.dimensions,
|
|
7
|
+
neighborCount: input.neighbors,
|
|
8
|
+
}, { ...options, includeSelf: true }, { ...names, neighbors: names.knn });
|
|
9
|
+
await buildFuzzyGraph(connection, input.neighbors, names);
|
|
10
|
+
const edges = await readScalarNumber(connection, `SELECT count(*) FROM ${names.graph}`);
|
|
11
|
+
const source = new Uint32Array(edges), target = new Uint32Array(edges), weight = new Float64Array(edges);
|
|
12
|
+
const rows = await connection.stream(`SELECT source,target,weight FROM ${names.graph} ORDER BY source,target`);
|
|
13
|
+
let edge = 0;
|
|
14
|
+
while (true) {
|
|
15
|
+
const chunk = await rows.fetchChunk();
|
|
16
|
+
if (!chunk || chunk.rowCount === 0)
|
|
17
|
+
break;
|
|
18
|
+
chunk.visitColumnValues(0, (value, row) => source[edge + row] = Number(value));
|
|
19
|
+
chunk.visitColumnValues(1, (value, row) => target[edge + row] = Number(value));
|
|
20
|
+
chunk.visitColumnValues(2, (value, row) => weight[edge + row] = Number(value));
|
|
21
|
+
edge += chunk.rowCount;
|
|
22
|
+
}
|
|
23
|
+
if (edge !== edges)
|
|
24
|
+
throw new Error("Graph changed during transfer.");
|
|
25
|
+
return { source, target, weight };
|
|
26
|
+
}
|
|
27
|
+
async function buildFuzzyGraph(connection, neighbors, names) {
|
|
28
|
+
// Smooth-kNN with local_connectivity=1, bandwidth=1, 64 bisection steps,
|
|
29
|
+
// tolerance 1e-5 and the reference's 1e-3 minimum-distance scale.
|
|
30
|
+
await connection.run(`CREATE OR REPLACE TEMP TABLE ${names.scales} AS
|
|
31
|
+
SELECT source, coalesce(min(distance) FILTER(WHERE distance>0),0) AS rho,
|
|
32
|
+
avg(distance) AS mean_distance, 0::DOUBLE AS lo, 'Infinity'::DOUBLE AS hi,
|
|
33
|
+
1::DOUBLE AS sigma, false AS done FROM ${names.knn} GROUP BY source`);
|
|
34
|
+
for (let iteration = 0; iteration < 64; iteration++) {
|
|
35
|
+
await connection.run(`CREATE OR REPLACE TEMP TABLE ${names.scales} AS
|
|
36
|
+
WITH sums AS (
|
|
37
|
+
SELECT s.*, (SELECT sum(CASE WHEN n.distance <= s.rho THEN 1
|
|
38
|
+
ELSE exp(-(n.distance-s.rho)/s.sigma) END)
|
|
39
|
+
FROM ${names.knn} n WHERE n.source=s.source AND n.target != n.source) AS mass
|
|
40
|
+
FROM ${names.scales} s
|
|
41
|
+
), bounds AS (
|
|
42
|
+
SELECT * EXCLUDE(lo,hi,done),
|
|
43
|
+
CASE WHEN NOT done AND mass < log2(${neighbors}) THEN sigma ELSE lo END AS lo,
|
|
44
|
+
CASE WHEN NOT done AND mass > log2(${neighbors}) THEN sigma ELSE hi END AS hi,
|
|
45
|
+
done OR abs(mass-log2(${neighbors})) < 1e-5 AS done FROM sums
|
|
46
|
+
) SELECT source,rho,mean_distance,lo,hi,
|
|
47
|
+
CASE WHEN done THEN sigma WHEN isinf(hi) THEN sigma*2 ELSE (lo+hi)/2 END AS sigma,
|
|
48
|
+
done FROM bounds`);
|
|
49
|
+
}
|
|
50
|
+
await connection.run(`UPDATE ${names.scales} SET sigma=greatest(sigma,0.001 *
|
|
51
|
+
CASE WHEN rho>0 THEN mean_distance ELSE (SELECT avg(distance) FROM ${names.knn}) END);
|
|
52
|
+
CREATE OR REPLACE TEMP TABLE ${names.directed} AS
|
|
53
|
+
SELECT n.source,n.target,CASE WHEN n.distance<=s.rho OR s.sigma=0 THEN 1
|
|
54
|
+
ELSE exp(-(n.distance-s.rho)/s.sigma) END AS weight
|
|
55
|
+
FROM ${names.knn} n JOIN ${names.scales} s USING(source) WHERE n.source != n.target;
|
|
56
|
+
CREATE OR REPLACE TEMP TABLE ${names.graph} AS
|
|
57
|
+
SELECT coalesce(a.source,b.target) AS source, coalesce(a.target,b.source) AS target,
|
|
58
|
+
coalesce(a.weight,0)+coalesce(b.weight,0)-coalesce(a.weight*b.weight,0) AS weight
|
|
59
|
+
FROM ${names.directed} a FULL OUTER JOIN ${names.directed} b
|
|
60
|
+
ON a.source=b.target AND a.target=b.source`);
|
|
61
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { DuckDBConnection } from "@duckdb/node-api";
|
|
2
|
+
/** Private, already-quoted relation names owned and cleaned up by the caller. */
|
|
3
|
+
export type VectorNeighborTables = {
|
|
4
|
+
rows: string;
|
|
5
|
+
neighbors: string;
|
|
6
|
+
search: string;
|
|
7
|
+
hnsw: string;
|
|
8
|
+
candidates: string;
|
|
9
|
+
};
|
|
10
|
+
type NeighborInput = {
|
|
11
|
+
count: number;
|
|
12
|
+
dimensions: number;
|
|
13
|
+
neighborCount: number;
|
|
14
|
+
};
|
|
15
|
+
type NeighborOptions = {
|
|
16
|
+
metric: "euclidean" | "cosine";
|
|
17
|
+
search: "exact" | "hnsw";
|
|
18
|
+
includeSelf: boolean;
|
|
19
|
+
hnsw?: {
|
|
20
|
+
efConstruction: number;
|
|
21
|
+
efSearch: number;
|
|
22
|
+
connectivity: number;
|
|
23
|
+
candidateCount: number;
|
|
24
|
+
singleThreaded: boolean;
|
|
25
|
+
cosineAsL2: boolean;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Materialize ranked vector neighbors without moving source vectors into JS.
|
|
30
|
+
*
|
|
31
|
+
* `neighborCount` is the number of rows produced per source. When `includeSelf`
|
|
32
|
+
* is true, the source is rank 0 and consumes one of those rows. Otherwise all
|
|
33
|
+
* rows are other points. Ranks are zero-based and ties use target id order.
|
|
34
|
+
* Input rows have unique contiguous `vertex` ids from 0 through count-1 and
|
|
35
|
+
* validated, non-null, fixed-size DOUBLE `vec` values. Cosine preparation may
|
|
36
|
+
* rescale this private vec column, preserving direction.
|
|
37
|
+
*
|
|
38
|
+
* The caller owns every supplied scratch relation and must drop them after
|
|
39
|
+
* success or failure. Approximate search only approximates candidate retrieval;
|
|
40
|
+
* candidate distances are recomputed from the DOUBLE source vectors before
|
|
41
|
+
* stable final ranking.
|
|
42
|
+
*/
|
|
43
|
+
export default function buildVectorNeighbors(connection: DuckDBConnection, input: NeighborInput, options: NeighborOptions, names: VectorNeighborTables): Promise<void>;
|
|
44
|
+
export {};
|
|
45
|
+
//# sourceMappingURL=buildVectorNeighbors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildVectorNeighbors.d.ts","sourceRoot":"","sources":["../../src/helpers/buildVectorNeighbors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAMzD,iFAAiF;AACjF,MAAM,MAAM,oBAAoB,GAAG;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,KAAK,aAAa,GAAG;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,KAAK,eAAe,GAAG;IACrB,MAAM,EAAE,WAAW,GAAG,QAAQ,CAAC;IAC/B,MAAM,EAAE,OAAO,GAAG,MAAM,CAAC;IACzB,WAAW,EAAE,OAAO,CAAC;IACrB,IAAI,CAAC,EAAE;QACL,cAAc,EAAE,MAAM,CAAC;QACvB,QAAQ,EAAE,MAAM,CAAC;QACjB,YAAY,EAAE,MAAM,CAAC;QACrB,cAAc,EAAE,MAAM,CAAC;QACvB,cAAc,EAAE,OAAO,CAAC;QACxB,UAAU,EAAE,OAAO,CAAC;KACrB,CAAC;CACH,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,wBAA8B,oBAAoB,CAChD,UAAU,EAAE,gBAAgB,EAC5B,KAAK,EAAE,aAAa,EACpB,OAAO,EAAE,eAAe,EACxB,KAAK,EAAE,oBAAoB,GAC1B,OAAO,CAAC,IAAI,CAAC,CAqHf"}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import readScalarNumber from "./readScalarNumber.js";
|
|
2
|
+
import vectorDistanceExpression from "./vectorDistanceExpression.js";
|
|
3
|
+
import stabilizeCosineVectors from "./stabilizeCosineVectors.js";
|
|
4
|
+
import validateVectorRowIds from "./validateVectorRowIds.js";
|
|
5
|
+
/**
|
|
6
|
+
* Materialize ranked vector neighbors without moving source vectors into JS.
|
|
7
|
+
*
|
|
8
|
+
* `neighborCount` is the number of rows produced per source. When `includeSelf`
|
|
9
|
+
* is true, the source is rank 0 and consumes one of those rows. Otherwise all
|
|
10
|
+
* rows are other points. Ranks are zero-based and ties use target id order.
|
|
11
|
+
* Input rows have unique contiguous `vertex` ids from 0 through count-1 and
|
|
12
|
+
* validated, non-null, fixed-size DOUBLE `vec` values. Cosine preparation may
|
|
13
|
+
* rescale this private vec column, preserving direction.
|
|
14
|
+
*
|
|
15
|
+
* The caller owns every supplied scratch relation and must drop them after
|
|
16
|
+
* success or failure. Approximate search only approximates candidate retrieval;
|
|
17
|
+
* candidate distances are recomputed from the DOUBLE source vectors before
|
|
18
|
+
* stable final ranking.
|
|
19
|
+
*/
|
|
20
|
+
export default async function buildVectorNeighbors(connection, input, options, names) {
|
|
21
|
+
const { count, dimensions, neighborCount } = input;
|
|
22
|
+
await validateVectorRowIds(connection, names.rows, count);
|
|
23
|
+
if (!Number.isSafeInteger(dimensions) || dimensions < 1) {
|
|
24
|
+
throw new Error("Vector dimensions must be a positive safe integer.");
|
|
25
|
+
}
|
|
26
|
+
const maximum = count - (options.includeSelf ? 0 : 1);
|
|
27
|
+
if (!Number.isSafeInteger(neighborCount) || neighborCount < 1 ||
|
|
28
|
+
neighborCount > maximum) {
|
|
29
|
+
throw new Error(`Neighbor count must be a safe integer between 1 and ${maximum}.`);
|
|
30
|
+
}
|
|
31
|
+
if (options.metric === "cosine") {
|
|
32
|
+
await stabilizeCosineVectors(connection, names.rows);
|
|
33
|
+
}
|
|
34
|
+
// FLOAT representation limits apply only to the HNSW search vectors.
|
|
35
|
+
// Exact Euclidean distance does not require representable squared norms.
|
|
36
|
+
if (options.search === "hnsw") {
|
|
37
|
+
const normExpression = `array_inner_product(vec::FLOAT[${dimensions}],vec::FLOAT[${dimensions}])`;
|
|
38
|
+
if (await readScalarNumber(connection, `SELECT count(*) FROM ${names.rows} WHERE NOT isfinite(${normExpression})
|
|
39
|
+
${options.metric === "cosine" ? `OR ${normExpression}=0` : ""}`)) {
|
|
40
|
+
throw new Error("HNSW requires vectors with finite FLOAT norms (and nonzero cosine norms).");
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const distanceFunction = options.metric === "cosine"
|
|
44
|
+
? "array_cosine_distance"
|
|
45
|
+
: "array_distance";
|
|
46
|
+
// Equal vectors must have exactly zero cosine distance. Positive roundoff can
|
|
47
|
+
// otherwise alter downstream density estimates. Clamp negative roundoff too.
|
|
48
|
+
const exactDistance = vectorDistanceExpression("a.vec", "b.vec", options.metric);
|
|
49
|
+
const otherCount = neighborCount - (options.includeSelf ? 1 : 0);
|
|
50
|
+
await connection.run(`CREATE OR REPLACE TEMP TABLE ${names.candidates}
|
|
51
|
+
(source INTEGER, target INTEGER, distance DOUBLE)`);
|
|
52
|
+
if (otherCount > 0) {
|
|
53
|
+
if (options.search === "exact") {
|
|
54
|
+
// O(n²d) work with a bounded source batch and top-k heaps. The full
|
|
55
|
+
// distance matrix is never materialized.
|
|
56
|
+
await buildExactCandidates(connection, input, names, exactDistance, otherCount);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
await buildHnswCandidates(connection, input, options, names, distanceFunction, exactDistance, otherCount);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (await readScalarNumber(connection, `SELECT count(*) FROM ${names.candidates} WHERE distance IS NULL OR NOT isfinite(distance)`)) {
|
|
63
|
+
throw new Error("Distance computation returned a non-finite value.");
|
|
64
|
+
}
|
|
65
|
+
const selfRows = options.includeSelf
|
|
66
|
+
? `SELECT vertex AS source,vertex AS target,0::DOUBLE AS distance FROM ${names.rows}`
|
|
67
|
+
: "SELECT NULL::INTEGER AS source,NULL::INTEGER AS target,NULL::DOUBLE AS distance WHERE false";
|
|
68
|
+
const rankOrder = options.includeSelf
|
|
69
|
+
? "CASE WHEN source=target THEN 0 ELSE 1 END,distance,target"
|
|
70
|
+
: "distance,target";
|
|
71
|
+
await connection.run(`CREATE OR REPLACE TEMP TABLE ${names.neighbors} AS
|
|
72
|
+
SELECT source,target,
|
|
73
|
+
(row_number() OVER (PARTITION BY source ORDER BY ${rankOrder})-1)::INTEGER AS rank,
|
|
74
|
+
greatest(0,distance)::DOUBLE AS distance
|
|
75
|
+
FROM (${selfRows} UNION ALL
|
|
76
|
+
SELECT source,target,distance FROM ${names.candidates})
|
|
77
|
+
QUALIFY row_number() OVER (PARTITION BY source ORDER BY ${rankOrder})
|
|
78
|
+
<= ${neighborCount}`);
|
|
79
|
+
const produced = await readScalarNumber(connection, `SELECT count(*) FROM ${names.neighbors}`);
|
|
80
|
+
if (produced !== count * neighborCount) {
|
|
81
|
+
throw new Error(`Neighbor search returned ${produced} rows; ${count * neighborCount} were required.`);
|
|
82
|
+
}
|
|
83
|
+
if (await readScalarNumber(connection, `SELECT count(*) FROM ${names.neighbors} WHERE NOT isfinite(distance)`)) {
|
|
84
|
+
throw new Error("Distance computation returned a non-finite value.");
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
async function buildHnswCandidates(connection, input, options, names, distanceFunction, exactDistance, otherCount) {
|
|
88
|
+
const { count, dimensions, neighborCount } = input;
|
|
89
|
+
const settings = options.hnsw;
|
|
90
|
+
const cosineAsL2 = options.metric === "cosine" && settings?.cosineAsL2;
|
|
91
|
+
// Euclidean distance on unit vectors has the same mathematical ordering as
|
|
92
|
+
// cosine. Computing differences avoids FLOAT dot-product cancellation for
|
|
93
|
+
// near-collinear vectors; final metric distances still use source DOUBLEs.
|
|
94
|
+
const searchVector = cosineAsL2
|
|
95
|
+
? "list_transform(vec,x -> x/sqrt(array_inner_product(vec,vec)))"
|
|
96
|
+
: "vec";
|
|
97
|
+
const previousThreads = Number((await connection.runAndReadAll("SELECT current_setting('threads')")).getRowsJS()[0][0]);
|
|
98
|
+
try {
|
|
99
|
+
if (settings?.singleThreaded)
|
|
100
|
+
await connection.run("SET threads=1");
|
|
101
|
+
await connection.run(`INSTALL vss; LOAD vss;
|
|
102
|
+
CREATE OR REPLACE TEMP TABLE ${names.search} AS
|
|
103
|
+
SELECT vertex,${searchVector}::FLOAT[${dimensions}] AS vec
|
|
104
|
+
FROM ${names.rows} ORDER BY vertex;
|
|
105
|
+
CREATE INDEX ${names.hnsw} ON ${names.search} USING HNSW(vec)
|
|
106
|
+
WITH (metric='${options.metric === "cosine" && !cosineAsL2 ? "cosine" : "l2sq"}',
|
|
107
|
+
ef_construction=${settings?.efConstruction ?? 128},
|
|
108
|
+
ef_search=${settings?.efSearch ?? 128},M=${settings?.connectivity ?? 16})`);
|
|
109
|
+
}
|
|
110
|
+
finally {
|
|
111
|
+
if (settings?.singleThreaded) {
|
|
112
|
+
await connection.run(`SET threads=${previousThreads}`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
const previous = String((await connection.runAndReadAll("SELECT current_setting('disabled_optimizers')")).getRowsJS()[0][0]);
|
|
116
|
+
const disabled = [
|
|
117
|
+
...new Set([
|
|
118
|
+
...previous.split(",").filter(Boolean),
|
|
119
|
+
"top_n_window_elimination",
|
|
120
|
+
]),
|
|
121
|
+
].join(",");
|
|
122
|
+
try {
|
|
123
|
+
await connection.run(`SET disabled_optimizers='${disabled.replaceAll("'", "''")}'`);
|
|
124
|
+
// Preserve UMAP's established candidate budget when self is included.
|
|
125
|
+
// Excluding self needs one extra result because HNSW normally returns it.
|
|
126
|
+
const candidateCount = settings?.candidateCount ??
|
|
127
|
+
(options.includeSelf
|
|
128
|
+
? Math.max(otherCount + 1, Math.min(neighborCount + 1, count - 1))
|
|
129
|
+
: Math.min(otherCount + 1, count));
|
|
130
|
+
const candidateDistanceFunction = cosineAsL2
|
|
131
|
+
? "array_distance"
|
|
132
|
+
: distanceFunction;
|
|
133
|
+
const query = `SELECT a.vertex AS source,b.vertex AS target,b.distance
|
|
134
|
+
FROM ${names.search} a,LATERAL (
|
|
135
|
+
SELECT vertex,${candidateDistanceFunction}(vec,a.vec) AS distance
|
|
136
|
+
FROM ${names.search} ORDER BY distance LIMIT ${candidateCount}
|
|
137
|
+
) b`;
|
|
138
|
+
// Carry ids and scalar distances through the candidate relation. Recompute
|
|
139
|
+
// in DOUBLE against source rows to isolate ANN retrieval from precision.
|
|
140
|
+
const candidates = `SELECT q.source,q.target,${exactDistance} AS distance
|
|
141
|
+
FROM (${query}) q JOIN ${names.rows} a ON q.source=a.vertex
|
|
142
|
+
JOIN ${names.rows} b ON q.target=b.vertex WHERE q.source != q.target`;
|
|
143
|
+
const plan = JSON.stringify((await connection.runAndReadAll(`EXPLAIN ${candidates}`)).getRowsJS());
|
|
144
|
+
if (!plan.includes("HNSW_INDEX_JOIN")) {
|
|
145
|
+
if (count <= 1000) {
|
|
146
|
+
return await buildExactCandidates(connection, input, names, exactDistance, otherCount);
|
|
147
|
+
}
|
|
148
|
+
throw new Error("DuckDB could not use its vector index for neighbor search.");
|
|
149
|
+
}
|
|
150
|
+
await connection.run(`INSERT INTO ${names.candidates} ${candidates}`);
|
|
151
|
+
}
|
|
152
|
+
finally {
|
|
153
|
+
await connection.run(`SET disabled_optimizers='${previous.replaceAll("'", "''")}'`);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
async function buildExactCandidates(connection, input, names, exactDistance, otherCount) {
|
|
157
|
+
for (let offset = 0; offset < input.count; offset += 32) {
|
|
158
|
+
const query = `SELECT source,item.target,item.distance FROM (
|
|
159
|
+
SELECT a.vertex AS source,
|
|
160
|
+
CASE WHEN bool_and(isfinite(${exactDistance})) THEN
|
|
161
|
+
min_by(struct_pack(target := b.vertex,distance := ${exactDistance}),
|
|
162
|
+
struct_pack(distance := ${exactDistance},target := b.vertex),
|
|
163
|
+
${otherCount}) ELSE error('Distance computation returned a non-finite value.') END AS closest
|
|
164
|
+
FROM ${names.rows} a CROSS JOIN ${names.rows} b
|
|
165
|
+
WHERE a.vertex >= ${offset} AND a.vertex < ${offset + 32}
|
|
166
|
+
AND a.vertex != b.vertex GROUP BY a.vertex
|
|
167
|
+
),UNNEST(closest) AS t(item)`;
|
|
168
|
+
await connection.run(`INSERT INTO ${names.candidates} ${query}`);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildWeakGraphComponentsSql.d.ts","sourceRoot":"","sources":["../../src/helpers/buildWeakGraphComponentsSql.ts"],"names":[],"mappings":"AAEA,gFAAgF;AAChF,MAAM,CAAC,OAAO,UAAU,2BAA2B,CACjD,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,GACZ,MAAM,CA6BR"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import quoteIdentifier from "./quoteIdentifier.js";
|
|
2
|
+
/** Builds weak component labels and zero-based IDs from bidirectional edges. */
|
|
3
|
+
export default function buildWeakGraphComponentsSql(edges, nodes, labels, roots) {
|
|
4
|
+
const q = quoteIdentifier;
|
|
5
|
+
return `${labels}(
|
|
6
|
+
${q("node")}, ${q("__node_key")}, ${q("__root_key")}
|
|
7
|
+
) USING KEY(${q("__node_key")}) AS (
|
|
8
|
+
SELECT ${q("node")}, ${q("__key")}, ${q("__key")}
|
|
9
|
+
FROM ${nodes}
|
|
10
|
+
UNION
|
|
11
|
+
SELECT ${q("edges")}.${q("__to")},
|
|
12
|
+
${q("edges")}.${q("__to_key")},
|
|
13
|
+
MIN(${q("reached")}.${q("__root_key")})
|
|
14
|
+
FROM ${labels} AS ${q("reached")}
|
|
15
|
+
INNER JOIN ${edges} AS ${q("edges")}
|
|
16
|
+
ON ${q("reached")}.${q("__node_key")} =
|
|
17
|
+
${q("edges")}.${q("__from_key")}
|
|
18
|
+
INNER JOIN recurring.${labels} AS ${q("best")}
|
|
19
|
+
ON ${q("edges")}.${q("__to_key")} =
|
|
20
|
+
${q("best")}.${q("__node_key")}
|
|
21
|
+
GROUP BY ${q("edges")}.${q("__to")},
|
|
22
|
+
${q("edges")}.${q("__to_key")}, ${q("best")}.${q("__root_key")}
|
|
23
|
+
HAVING MIN(${q("reached")}.${q("__root_key")}) <
|
|
24
|
+
${q("best")}.${q("__root_key")}
|
|
25
|
+
), ${roots} AS (
|
|
26
|
+
SELECT ${q("__root_key")},
|
|
27
|
+
CAST(row_number() OVER (ORDER BY ${q("__root_key")}) - 1 AS BIGINT)
|
|
28
|
+
AS ${q("componentId")}
|
|
29
|
+
FROM (SELECT DISTINCT ${q("__root_key")} FROM ${labels})
|
|
30
|
+
AS ${q("distinct_roots")}
|
|
31
|
+
)`;
|
|
32
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cacheDatabase.d.ts","sourceRoot":"","sources":["../../src/helpers/cacheDatabase.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AACvD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAU7D,wBAAsB,kBAAkB,CACtC,KAAK,EAAE,WAAW,EAClB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,eAAe,EAAE,GACzB,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"cacheDatabase.d.ts","sourceRoot":"","sources":["../../src/helpers/cacheDatabase.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AACvD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAU7D,wBAAsB,kBAAkB,CACtC,KAAK,EAAE,WAAW,EAClB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,eAAe,EAAE,GACzB,OAAO,CAAC,IAAI,CAAC,CA0Cf;AASD,wBAAsB,iBAAiB,CACrC,KAAK,EAAE,WAAW,EAClB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,eAAe,EAAE,EAC1B,GAAG,EAAE,OAAO,GACX,OAAO,CAAC,IAAI,CAAC,CAiCf"}
|
|
@@ -11,7 +11,8 @@ export async function writeCacheDatabase(table, file, indexes) {
|
|
|
11
11
|
const persistedIndexes = indexes.filter((index) => getIndexCacheStrategy(index) === "persist");
|
|
12
12
|
await loadIndexExtensions(table, persistedIndexes);
|
|
13
13
|
try {
|
|
14
|
-
await table.sdb.customQuery(`ATTACH '${cleanPath(temporaryFile)}' AS ${cacheDatabase}
|
|
14
|
+
await table.sdb.customQuery(`ATTACH '${cleanPath(temporaryFile)}' AS ${cacheDatabase}
|
|
15
|
+
(STORAGE_VERSION 'latest');
|
|
15
16
|
CREATE TABLE ${cacheDatabase}.${quoteIdentifier(table.name)} AS
|
|
16
17
|
SELECT * FROM ${quoteIdentifier(table.name)};`);
|
|
17
18
|
if (persistedIndexes.length > 0) {
|
|
@@ -2,29 +2,31 @@
|
|
|
2
2
|
* Converts a string into camelCase. This is useful for creating variable
|
|
3
3
|
* names or object keys from human-readable text.
|
|
4
4
|
*
|
|
5
|
-
* @param input - The string to convert to camelCase. It can contain spaces,
|
|
6
|
-
* punctuation, and mixed casing.
|
|
7
|
-
*
|
|
8
|
-
* @returns The camelCased version of the input string.
|
|
9
|
-
*
|
|
10
5
|
* @example
|
|
11
6
|
* ```ts
|
|
12
7
|
* // Basic conversion
|
|
13
8
|
* const result1 = camelCase("hello world");
|
|
14
9
|
* console.log(result1); // "helloWorld"
|
|
15
10
|
* ```
|
|
11
|
+
*
|
|
16
12
|
* @example
|
|
17
13
|
* ```ts
|
|
18
14
|
* // With punctuation and mixed case
|
|
19
15
|
* const result2 = camelCase(" --Some@Thing is- happening-- ");
|
|
20
16
|
* console.log(result2); // "someThingIsHappening"
|
|
21
17
|
* ```
|
|
18
|
+
*
|
|
22
19
|
* @example
|
|
23
20
|
* ```ts
|
|
24
21
|
* // With a single word
|
|
25
22
|
* const result3 = camelCase("Journalism");
|
|
26
23
|
* console.log(result3); // "journalism"
|
|
27
24
|
* ```
|
|
25
|
+
*
|
|
26
|
+
* @param input - The string to convert to camelCase. It can contain spaces,
|
|
27
|
+
* punctuation, and mixed casing.
|
|
28
|
+
*
|
|
29
|
+
* @returns The camelCased version of the input string.
|
|
28
30
|
*/
|
|
29
31
|
export default function camelCase(input: string): string;
|
|
30
32
|
//# sourceMappingURL=camelCase.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"camelCase.d.ts","sourceRoot":"","sources":["../../src/helpers/camelCase.ts"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"camelCase.d.ts","sourceRoot":"","sources":["../../src/helpers/camelCase.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAiBvD"}
|