Skip to content

Commit ff25be7

Browse files
fix(search): preserve indexed vector retrieval and literal source text (#7899)
* fix(search): preserve indexed vector retrieval and literal source text * fix(search): keep benchmark corpus defaults within valid bounds * fix(search): retain ANN recall settings and verify distinct queries
1 parent 6be9008 commit ff25be7

9 files changed

Lines changed: 414 additions & 98 deletions

File tree

‎apps/sim/lib/file-parsers/index.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ export async function parseBuffer(
176176
}
177177

178178
const kind = sniffFileKind(buffer, normalizedExtension)
179-
const route = reconcileParserRoute(normalizedExtension, kind)
179+
const route = reconcileParserRoute(normalizedExtension, kind, options)
180180
const parser = PARSERS.get(route.extension)
181181

182182
if (!parser?.parseBuffer) {

‎apps/sim/lib/file-parsers/sniff.test.ts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,38 @@ describe('parseBuffer reconciles the extension with the sniffed bytes', () => {
308308
expect(result.metadata?.detectedType).toBe('html')
309309
})
310310

311+
it.each([
312+
'<!doctype html><html><head><script src="./app.js"></script></head><body><div id="root"></div></body></html>',
313+
'{\\rtf1\\ansi Source-format example}',
314+
])(
315+
'preserves textual markup when the caller supplies a canonical text artifact',
316+
async (content) => {
317+
const result = await parseBuffer(Buffer.from(content), 'txt', { textMode: 'literal' })
318+
319+
expect(result.content).toBe(content)
320+
expect(result.metadata?.detectedType).toBeUndefined()
321+
}
322+
)
323+
324+
it('keeps literal-text handling scoped to txt artifacts', async () => {
325+
const result = await parseBuffer(
326+
Buffer.from('<!doctype html><html><body><p>Readable page</p></body></html>'),
327+
'html',
328+
{ textMode: 'literal' }
329+
)
330+
331+
expect(result.content).toContain('Readable page')
332+
expect(result.content).not.toContain('<html>')
333+
await expect(
334+
parseBuffer(Buffer.from('<!doctype html><html><body>403 Forbidden</body></html>'), 'json', {
335+
textMode: 'literal',
336+
})
337+
).rejects.toMatchObject({ code: 'invalid_format' })
338+
await expect(parseBuffer(oleBinary(), 'txt', { textMode: 'literal' })).rejects.toMatchObject({
339+
code: 'invalid_format',
340+
})
341+
})
342+
311343
it('extracts a docx labelled .xlsx through the Word parser', async () => {
312344
const result = await parseBuffer(await buildDocx('Office Relocation'), 'xlsx')
313345

‎apps/sim/lib/file-parsers/sniff.ts‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { FileParserError } from '@/lib/file-parsers/errors'
22
import { isEncryptedOoxmlContainer } from '@/lib/file-parsers/ooxml-encryption'
3+
import type { FileParseOptions } from '@/lib/file-parsers/types'
34
import { decodeTextBuffer, detectBomlessUtf16 } from '@/lib/file-parsers/utils'
45
import { isZipShaped } from '@/lib/file-parsers/zip-guard'
56

@@ -307,7 +308,18 @@ function invalidFormat(extension: string, kind: SniffedKind): FileParserError {
307308
* text (as CSV under a spreadsheet extension), and an OLE2 file under a modern
308309
* Word extension is the legacy `.doc` parser's job. Legacy `.ppt` has no reader.
309310
*/
310-
export function reconcileParserRoute(extension: string, kind: SniffedKind): ParserRoute {
311+
export function reconcileParserRoute(
312+
extension: string,
313+
kind: SniffedKind,
314+
options: Pick<FileParseOptions, 'textMode'> = {}
315+
): ParserRoute {
316+
if (
317+
extension === 'txt' &&
318+
options.textMode === 'literal' &&
319+
(kind === 'html' || kind === 'rtf')
320+
) {
321+
return { extension }
322+
}
311323
if (kind === 'rtf') {
312324
throw new FileParserError(
313325
'unsupported_type',

‎apps/sim/lib/file-parsers/types.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ export interface FileParseResult {
3333

3434
export interface FileParseOptions {
3535
signal?: AbortSignal
36+
/** Preserve textual markup in a canonical .txt artifact instead of interpreting it as HTML or RTF. */
37+
textMode?: 'literal'
3638
/** Complete PDF extraction rejects safety limits instead of returning preview text. */
3739
pdfTextMode?: 'preview' | 'complete'
3840
}

0 commit comments

Comments
 (0)