-
Notifications
You must be signed in to change notification settings - Fork 3.9k
fix(search): retire legacy embeddings through scoped backfill #8430
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
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4d73ebc
fix(search): retire legacy embeddings through scoped backfill
icecrasher321 8125747
fix(search): run retirement without cleanup flags and close ingestion…
icecrasher321 ef25256
chore(tests): scope migration recovery journal assertion
icecrasher321 474204e
chore(tests): align document dispatch billing and quota fixtures
icecrasher321 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
98 changes: 98 additions & 0 deletions
98
apps/sim/lib/knowledge/__integration__/dormant-search-processing.integration.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| import { db } from '@sim/db' | ||
| import { document, knowledgeBase, organization, user, workspace } from '@sim/db/schema' | ||
| import { generateId } from '@sim/utils/id' | ||
| import { eq, inArray } from 'drizzle-orm' | ||
| import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest' | ||
| import { | ||
| createKnowledgeAclFixtureIds, | ||
| seedKnowledgeAclFixture, | ||
| } from '@/lib/knowledge/__integration__/seed-source-access-fixture' | ||
| import { | ||
| createDocumentRecords, | ||
| createSingleDocument, | ||
| processDocumentAsync, | ||
| processDocumentsWithQueue, | ||
| } from '@/lib/knowledge/documents/service' | ||
|
|
||
| vi.mock('@/lib/core/config/env-flags', async (importOriginal) => ({ | ||
| ...(await importOriginal<Record<string, unknown>>()), | ||
| isLiveEnterpriseSearchEnabled: true, | ||
| })) | ||
|
|
||
| /** Queued work cannot revive dormant Search before retirement reaches its documents. */ | ||
| describe('dormant Search document processing', () => { | ||
| const ids = createKnowledgeAclFixtureIds() | ||
| const documentId = generateId() | ||
| const source = { | ||
| filename: 'fixture.txt', | ||
| fileUrl: 'data:text/plain,fixture', | ||
| fileSize: 7, | ||
| mimeType: 'text/plain', | ||
| } | ||
|
|
||
| beforeAll(async () => { | ||
| await seedKnowledgeAclFixture(ids, { connectorType: 'google_drive' }) | ||
| await db | ||
| .update(knowledgeBase) | ||
| .set({ isSearchIndex: true }) | ||
| .where(eq(knowledgeBase.id, ids.knowledgeBaseId)) | ||
| await db | ||
| .insert(document) | ||
| .values({ id: documentId, knowledgeBaseId: ids.knowledgeBaseId, ...source }) | ||
| }) | ||
|
|
||
| afterAll(async () => { | ||
| await db.delete(knowledgeBase).where(eq(knowledgeBase.id, ids.knowledgeBaseId)) | ||
| await db.delete(workspace).where(eq(workspace.id, ids.workspaceId)) | ||
| await db.delete(organization).where(eq(organization.id, ids.organizationId)) | ||
| await db.delete(user).where(inArray(user.id, [ids.aliceId, ids.bobId])) | ||
| }) | ||
|
|
||
| it('rejects uploads before creating documents in a dormant Search KB', async () => { | ||
| await expect( | ||
| createDocumentRecords([source], ids.knowledgeBaseId, generateId()) | ||
| ).rejects.toThrow('inactive') | ||
| await expect(createSingleDocument(source, ids.knowledgeBaseId, generateId())).rejects.toThrow( | ||
| 'inactive' | ||
| ) | ||
| const documents = await db | ||
| .select({ id: document.id }) | ||
| .from(document) | ||
| .where(eq(document.knowledgeBaseId, ids.knowledgeBaseId)) | ||
| expect(documents).toEqual([{ id: documentId }]) | ||
| }) | ||
|
|
||
| it('refuses dispatch before stamping or charging a pending Search document', async () => { | ||
| const result = await processDocumentsWithQueue( | ||
| [{ documentId, ...source }], | ||
| ids.knowledgeBaseId, | ||
| {}, | ||
| generateId(), | ||
| undefined, | ||
| 'backfill' | ||
| ) | ||
| expect(result).toEqual({ | ||
| requested: 1, | ||
| accepted: 0, | ||
| failed: 1, | ||
| failedDocumentIds: [documentId], | ||
| }) | ||
| const [stored] = await db | ||
| .select({ token: document.processingQueueToken, queuedAt: document.processingQueuedAt }) | ||
| .from(document) | ||
| .where(eq(document.id, documentId)) | ||
| expect(stored).toEqual({ token: null, queuedAt: null }) | ||
| }) | ||
|
|
||
| it('skips an old worker payload before claiming the document or requiring billing', async () => { | ||
| expect(await processDocumentAsync(ids.knowledgeBaseId, documentId, source)).toEqual({ | ||
| outcome: 'skipped', | ||
| reason: 'unavailable', | ||
| }) | ||
| const [stored] = await db | ||
| .select({ status: document.processingStatus }) | ||
| .from(document) | ||
| .where(eq(document.id, documentId)) | ||
| expect(stored.status).toBe('pending') | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.