mongodb-rag-core
Version:
Common elements used by MongoDB Chatbot Framework components.
100 lines • 3.16 kB
TypeScript
import { z } from "zod";
/**
Zod schema for MongoDB explain output
*/
export declare const ExplainOutputSchema: z.ZodObject<{
executionStats: z.ZodObject<{
nReturned: z.ZodNumber;
totalDocsExamined: z.ZodNumber;
totalKeysExamined: z.ZodNumber;
executionTimeMillis: z.ZodNumber;
}, "strip", z.ZodTypeAny, {
nReturned: number;
totalDocsExamined: number;
totalKeysExamined: number;
executionTimeMillis: number;
}, {
nReturned: number;
totalDocsExamined: number;
totalKeysExamined: number;
executionTimeMillis: number;
}>;
queryPlanner: z.ZodObject<{
namespace: z.ZodString;
winningPlan: z.ZodAny;
}, "strip", z.ZodTypeAny, {
namespace: string;
winningPlan?: any;
}, {
namespace: string;
winningPlan?: any;
}>;
}, "strip", z.ZodTypeAny, {
executionStats: {
nReturned: number;
totalDocsExamined: number;
totalKeysExamined: number;
executionTimeMillis: number;
};
queryPlanner: {
namespace: string;
winningPlan?: any;
};
}, {
executionStats: {
nReturned: number;
totalDocsExamined: number;
totalKeysExamined: number;
executionTimeMillis: number;
};
queryPlanner: {
namespace: string;
winningPlan?: any;
};
}>;
type ExplainOutput = z.infer<typeof ExplainOutputSchema>;
/**
Transforms a MongoDB query to include .explain() for execution analysis
@param query - The original MongoDB query
@returns The query with .explain() added
*/
export declare function addExplainToQuery(query: string): string;
/**
Gets the total document count for a collection
@param collectionName - The name of the collection
@param databaseName - The name of the database
@returns The total number of documents in the collection
*/
export declare function getMongoshCollectionDocumentCount(connectionUri: string, collectionName: string, databaseName: string): Promise<number>;
/**
Calculates query efficiency based on explain output and total documents
@param explainOutput - The parsed explain output
@param totalDocs - Total documents in the collection
@returns Query efficiency score between 0 and 1
*/
export declare function calculateQueryEfficiency(explainOutput: ExplainOutput, totalDocs: number): number;
export interface QueryProfile {
explainOutput: ExplainOutput;
collection: {
name: string;
documentCount: number;
};
}
export type ProfileMongoshQueryReturnValue = {
profile: QueryProfile;
error: null;
} | {
profile: null;
error: {
message: string;
};
};
/**
Calls MongoDB .explain() on the query and analyzes performance
@param query - The MongoDB query to explain
@param databaseName - The database name for execution context
@returns Explain output with performance metrics
*/
export declare function profileMongoshQuery(dbQuery: string, databaseName: string, connectionUri: string): Promise<ProfileMongoshQueryReturnValue>;
export {};
//# sourceMappingURL=profileMongoshQuery.d.ts.map