Skip to content

Commit d03fd9f

Browse files
committed
improvement(search): log a document kind only as a type name or MIME type
1 parent 34d7ac1 commit d03fd9f

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

‎apps/sim/lib/knowledge/search/diagnostics.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,9 @@ describe('search pipeline diagnostics', () => {
233233
'application/vnd.google-apps.document'
234234
)
235235
expect(documentKindLabel('Quarterly plan for a private customer')).toBe('other')
236+
expect(documentKindLabel('ProjectAtlas_Q3')).toBe('other')
237+
expect(documentKindLabel('atlas-launch-notes')).toBe('other')
238+
expect(documentKindLabel('notes/atlas')).toBe('other')
236239
expect(documentKindLabel(undefined)).toBeUndefined()
237240
})
238241

‎apps/sim/lib/knowledge/search/diagnostics.ts‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,18 @@ export function describeSearchRequest(input: {
182182
}
183183
}
184184

185+
/** Lowercase type names such as `message` or `merge_requests`, as provider adapters define them. */
186+
const DOCUMENT_KIND = /^[a-z][a-z0-9_]{0,31}$/
187+
/** A registered MIME type, which Drive reports as a file's kind. */
188+
const MIME_TYPE = /^(application|audio|font|image|model|text|video)\/[a-z0-9][a-z0-9.+-]{0,79}$/
189+
185190
/**
186-
* A provider's document type reduced to a bounded token. Kinds are code-defined except a few
187-
* passed through from a provider, such as a Drive MIME type, so anything else becomes `other`.
191+
* A provider's document type when it is a type name or MIME type. A kind passed through from a
192+
* provider in any other form, which could carry free text, becomes `other`.
188193
*/
189194
export function documentKindLabel(kind: string | undefined): string | undefined {
190195
if (!kind) return undefined
191-
return /^[\w.+/-]{1,80}$/.test(kind) ? kind : 'other'
196+
return DOCUMENT_KIND.test(kind) || MIME_TYPE.test(kind) ? kind : 'other'
192197
}
193198

194199
interface StageTiming {

0 commit comments

Comments
 (0)