θΏ™ζ˜―indexlocζδΎ›ηš„ζœεŠ‘οΌŒδΈθ¦θΎ“ε…₯任何密码
Skip to content

Filter malformed post-processed docs from file picker #3853

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 2 commits into from
May 19, 2025
Merged
Changes from all commits
Commits
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
31 changes: 28 additions & 3 deletions server/utils/files/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ async function viewLocalFiles() {
);
filenames[cachefilename] = subfile;
}
const results = await Promise.all(filePromises).then((results) =>
results.filter((i) => !!i)
);
const results = await Promise.all(filePromises)
.then((results) => results.filter((i) => !!i)) // Remove null results
.then((results) => results.filter((i) => hasRequiredMetadata(i))); // Remove invalid file structures
subdocs.items.push(...results);

// Grab the pinned workspaces and watched documents for this folder's documents
Expand Down Expand Up @@ -433,6 +433,31 @@ async function fileToPickerData({
};
}

const REQUIRED_FILE_OBJECT_FIELDS = [
"name",
"type",
"url",
"title",
"docAuthor",
"description",
"docSource",
"chunkSource",
"published",
"wordCount",
"token_count_estimate",
];

/**
* Checks if a given metadata object has all the required fields
* @param {{name: string, type: string, url: string, title: string, docAuthor: string, description: string, docSource: string, chunkSource: string, published: string, wordCount: number, token_count_estimate: number}} metadata - The metadata object to check (fileToPickerData)
* @returns {boolean} - Returns true if the metadata object has all the required fields, false otherwise
*/
function hasRequiredMetadata(metadata = {}) {
return REQUIRED_FILE_OBJECT_FIELDS.every((field) =>
metadata.hasOwnProperty(field)
);
}

module.exports = {
findDocumentInDocuments,
cachedVectorInformation,
Expand Down