Skip to content

Commit

Permalink
- Added ajson_multi_file_clusters_data_adapter
Browse files Browse the repository at this point in the history
- Updated `SmartClusters` class with an `init` method
- Refined `SourceClustersAdapter` to dynamically determine the number of clusters based on available sources, improving adaptability.
  • Loading branch information
Brian Joseph Petro committed Dec 22, 2024
1 parent ce3a388 commit bc49fe1
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 2 deletions.
31 changes: 31 additions & 0 deletions smart-clusters/adapters/data/ajson_multi_file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { AjsonMultiFileCollectionDataAdapter, AjsonMultiFileItemDataAdapter } from 'smart-collections/adapters/ajson_multi_file.js';

/**
* @class AjsonMultiFileGroupsDataAdapter
* @extends AjsonMultiFileCollectionDataAdapter
* @description
* Similar to the sources adapter, but for groups (directories).
* Handles load/save/delete operations for directory groups.
*/
export class AjsonMultiFileClustersDataAdapter extends AjsonMultiFileCollectionDataAdapter {
ItemDataAdapter = AjsonMultiFileClusterDataAdapter;
get_data_file_name(key) {
return 'clusters';
}
}

/**
* @class AjsonMultiFileGroupDataAdapter
* @extends AjsonMultiFileItemDataAdapter
* @description
* Handles individual directory group items stored in append-only AJSON files.
*/
export class AjsonMultiFileClusterDataAdapter extends AjsonMultiFileItemDataAdapter {

}

export default {
collection: AjsonMultiFileClustersDataAdapter,
item: AjsonMultiFileClusterDataAdapter
};

8 changes: 7 additions & 1 deletion smart-clusters/adapters/source.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export class SourceClustersAdapter extends ClusterCollectionAdapter {
const {
max_iterations = 10,
max_cluster_size_percent = 0.3,
clusters_ct = 5,
// new settings:
min_similarity_threshold_mode = 'lowest',
orphan_cluster_key = 'orphaned',
Expand All @@ -42,6 +41,13 @@ export class SourceClustersAdapter extends ClusterCollectionAdapter {
console.warn("No vectorized sources found; skipping cluster build for SourceClustersAdapter.");
return;
}
let clusters_ct;
if(this.collection.settings?.clusters_ct) {
clusters_ct = this.collection.settings.clusters_ct;
} else {
clusters_ct = Math.max(5, Math.floor(sources.length / 100));
}

const max_cluster_size = Math.max(1, Math.floor(max_cluster_size_percent * sources.length));

// 1) Remove existing clusters
Expand Down
8 changes: 7 additions & 1 deletion smart-clusters/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { SmartClusters } from "./smart_clusters.js";
import { SmartCluster } from "./smart_cluster.js";
import source_cluster_group_adapter from "./adapters/source.js";
import ajson_multi_file_clusters_data_adapter from "./adapters/data/ajson_multi_file.js";

export { SmartClusters, SmartCluster, source_cluster_group_adapter };
export {
SmartClusters,
SmartCluster,
source_cluster_group_adapter,
ajson_multi_file_clusters_data_adapter
};
6 changes: 6 additions & 0 deletions smart-clusters/smart_clusters.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ export class SmartClusters extends SmartGroups {
// E.g., store them under "clusters" folder or "multi" if desired
get data_dir() { return 'clusters'; }

async init(){
await super.init();
await this.create_or_update({key: 'orphaned'});
await this.process_load_queue();
}

/**
* Primary method that triggers the clustering adapter to create or update clusters.
*/
Expand Down

0 comments on commit bc49fe1

Please sign in to comment.