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

Merged
merged 40 commits into from
Aug 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 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
a0415c2
WIP
jcobis Aug 19, 2025
0a6f9c1
Add more test
jcobis Aug 20, 2025
054176e
Merge branch 'main' of github.com:mongodb-js/compass into CLOUDP-3370…
jcobis Aug 20, 2025
55088ba
Use type predicate validators
jcobis Aug 20, 2025
1524be4
Constants validator
jcobis Aug 20, 2025
c502a78
Create constant value
jcobis Aug 20, 2025
f221923
Package lock update
jcobis Aug 20, 2025
03f3cd8
Types
jcobis Aug 20, 2025
476d003
Package Lock
jcobis Aug 20, 2025
e4db17c
Address comment
jcobis Aug 20, 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
2 changes: 2 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/compass-collection/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@
"react": "^17.0.2",
"react-redux": "^8.1.3",
"redux": "^4.2.1",
"redux-thunk": "^2.4.2"
"redux-thunk": "^2.4.2",
"bson": "^6.10.1"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since bson is only used for its types, it should be a dev dependency so it doesn't get bundled to prod

Copy link
Collaborator Author

@jcobis jcobis Aug 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dependency checker was still complaining even with using import type.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried adding 'bson' to the ignores in packages/compass-collection/.depcheckrc. But not sure

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

},
"devDependencies": {
"@mongodb-js/eslint-config-compass": "^1.4.6",
Expand Down
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
30 changes: 28 additions & 2 deletions packages/compass-collection/src/schema-analysis-types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Document } from 'mongodb';
import { type Schema } from 'mongodb-schema';
import type { PrimitiveSchemaType } from 'mongodb-schema';

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

/**
* MongoDB schema type
*/
export type MongoDBFieldType = PrimitiveSchemaType['name'];

/**
* Primitive values that can appear in sample_values after BSON-to-primitive conversion.
* These are the JavaScript primitive equivalents of BSON values.
*/
export type SampleValue =
| string // String, Symbol, ObjectId, Binary, RegExp, Code, etc. (converted to string)
| number // Number, Int32, Long, Double, Decimal128, Timestamp (converted via valueOf())
| boolean
| Date
| null
| undefined;

/**
* Schema field information (for LLM processing)
*/
export interface FieldInfo {
type: MongoDBFieldType; // MongoDB primitive type
sample_values?: SampleValue[]; // Primitive sample values (limited to 10)
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