Skip to content

feat(compass-collection): Process schema into format for LLM submission for Mock Data Generator – CLOUDP-337090 #7205

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

Open
wants to merge 30 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
8f9d83f
WIP
jcobis Aug 8, 2025
a0b79e0
WIP
jcobis Aug 8, 2025
15ff5d3
Re order buttons
jcobis Aug 8, 2025
6f3f320
WIP
jcobis Aug 8, 2025
8935d22
Rename datatest-id
jcobis Aug 8, 2025
777ab8b
Merge branch 'main' into CLOUDP-333847
jcobis Aug 8, 2025
5163ed7
Move state to redux
jcobis Aug 11, 2025
f13950b
Update tests per comments
jcobis Aug 11, 2025
ceefa80
Merge branch 'main' of github.com:mongodb-js/compass into CLOUDP-333847
jcobis Aug 11, 2025
e0d431f
Fix import
jcobis Aug 11, 2025
6abe239
Test file
jcobis Aug 12, 2025
7d3b7fb
Tests cleanup
jcobis Aug 12, 2025
7b3c4ba
Add tests
jcobis Aug 12, 2025
607ff03
Rename actions; Remove action wrapper
jcobis Aug 12, 2025
ff4ce2d
Merge branch 'main' of github.com:mongodb-js/compass into CLOUDP-333847
jcobis Aug 14, 2025
bcff32e
Address comments
jcobis Aug 14, 2025
f2151f4
WIP
jcobis Aug 14, 2025
8d0d47f
WIP
jcobis Aug 14, 2025
ff558cd
Merge branch 'main' of github.com:mongodb-js/compass into CLOUDP-333847
jcobis Aug 15, 2025
920df5f
Merge branch 'main' into CLOUDP-333847
jcobis Aug 15, 2025
6d9061c
Merge branch 'main' of github.com:mongodb-js/compass into CLOUDP-333847
jcobis Aug 15, 2025
9fedf3f
Process schema
jcobis Aug 15, 2025
f81571e
WIP
jcobis Aug 18, 2025
456225c
WIP
jcobis Aug 19, 2025
1a70ed3
WIP
jcobis Aug 19, 2025
0dbab78
Merge branch 'main' of github.com:mongodb-js/compass into CLOUDP-3370…
jcobis Aug 19, 2025
891b707
WIP
jcobis Aug 19, 2025
25999c0
Merge branch 'main' into CLOUDP-337090_v2
jcobis Aug 19, 2025
b50e797
WIP
jcobis Aug 19, 2025
6e5318f
Merge branch 'CLOUDP-337090_v2' of github.com:mongodb-js/compass into…
jcobis Aug 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions packages/compass-collection/src/modules/collection-tab.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Reducer, AnyAction, Action } from 'redux';
import { analyzeDocuments, type Schema } from 'mongodb-schema';
import { analyzeDocuments } from 'mongodb-schema';

import type { CollectionMetadata } from 'mongodb-collection-model';
import type { ThunkAction } from 'redux-thunk';
Expand All @@ -19,8 +19,10 @@ import {
SCHEMA_ANALYSIS_STATE_INITIAL,
type SchemaAnalysisError,
type SchemaAnalysisState,
type FieldInfo,
} from '../schema-analysis-types';
import { calculateSchemaDepth } from '../calculate-schema-depth';
import { processSchema } from '../transform-schema-to-field-info';
import type { Document, MongoError } from 'mongodb';

const DEFAULT_SAMPLE_SIZE = 100;
Expand Down Expand Up @@ -106,7 +108,7 @@ interface SchemaAnalysisStartedAction {

interface SchemaAnalysisFinishedAction {
type: CollectionActions.SchemaAnalysisFinished;
schema: Schema;
processedSchema: Record<string, FieldInfo>;
sampleDocument: Document;
schemaMetadata: {
maxNestingDepth: number;
Expand Down Expand Up @@ -201,7 +203,7 @@ const reducer: Reducer<CollectionState, Action> = (
...state,
schemaAnalysis: {
status: SCHEMA_ANALYSIS_STATE_COMPLETE,
schema: action.schema,
processedSchema: action.processedSchema,
sampleDocument: action.sampleDocument,
schemaMetadata: action.schemaMetadata,
},
Expand Down Expand Up @@ -420,7 +422,9 @@ export const analyzeCollectionSchema = (): CollectionThunkAction<
schema.fields = schema.fields.filter(
({ path }) => !isInternalFieldPath(path[0])
);
// TODO: Transform schema to structure that will be used by the LLM.

// Transform schema to structure that will be used by the LLM
const processedSchema = processSchema(schema);

const maxNestingDepth = await calculateSchemaDepth(schema);
const { database, collection } = toNS(namespace);
Expand All @@ -432,7 +436,7 @@ export const analyzeCollectionSchema = (): CollectionThunkAction<
};
dispatch({
type: CollectionActions.SchemaAnalysisFinished,
schema,
processedSchema,
sampleDocument: sampleDocuments[0],
schemaMetadata,
});
Expand Down
10 changes: 8 additions & 2 deletions packages/compass-collection/src/schema-analysis-types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Document } from 'mongodb';
import { type Schema } from 'mongodb-schema';

export const SCHEMA_ANALYSIS_STATE_INITIAL = 'initial';
export const SCHEMA_ANALYSIS_STATE_ANALYZING = 'analyzing';
Expand Down Expand Up @@ -30,9 +29,16 @@ export type SchemaAnalysisErrorState = {
error: SchemaAnalysisError;
};

export interface FieldInfo {
type: string; // MongoDB type (eg. String, Double, Array, Document)
sample_values?: unknown[]; // Primitive sample values (flattened for arrays)
array_sample_values?: unknown[]; // Sample values of the top-level array object
probability?: number; // 0.0 - 1.0 field frequency
}

export type SchemaAnalysisCompletedState = {
status: typeof SCHEMA_ANALYSIS_STATE_COMPLETE;
schema: Schema;
processedSchema: Record<string, FieldInfo>;
sampleDocument: Document;
schemaMetadata: {
maxNestingDepth: number;
Expand Down
Loading
Loading