Infers metadata schema from a collection of documents by analyzing their metadata fields.
This function examines the metadata of all provided documents and attempts to infer the appropriate field type for each metadata key based on the values found.
Type inference rules:
inferMetadataSchema(documents: Document<Record<string, any>>[]): MetadataFieldSchema[]const documents = [
{ pageContent: "...", metadata: { category: "electronics", price: 99 } },
{ pageContent: "...", metadata: { category: "books", price: 15 } },
];
const schema = inferMetadataSchema(documents);
// Returns: [
// { name: "text", type: "tag" },
// { name: "price", type: "numeric" }
// ]