mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-10 05:29:08 +08:00
feat(server): improve context metadata & matching (#12064)
fix AI-20 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Enhanced file metadata with MIME type, blob ID, and file name across context and workspace, now visible in UI and API. - Added workspace-level matching for files and documents with configurable thresholds and workspace scoping in search queries. - Introduced a new error type and user-friendly messaging for global workspace context matching failures. - **Bug Fixes** - Improved consistent handling of file MIME types and nullable context IDs for accurate metadata. - **Documentation** - Updated GraphQL schema, queries, and mutations to include new metadata fields, optional parameters, and error types. - **Style** - Added new localization strings for global context matching error messages. - **Tests** - Extended test coverage with new and updated snapshot tests for metadata and matching logic. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -1316,7 +1316,11 @@ test('should be able to manage context', async t => {
|
||||
// file record
|
||||
{
|
||||
await storage.put(userId, session.workspaceId, 'blob', buffer);
|
||||
const file = await session.addFile('blob', 'sample.pdf');
|
||||
const file = await session.addFile(
|
||||
'blob',
|
||||
'sample.pdf',
|
||||
'application/pdf'
|
||||
);
|
||||
|
||||
const handler = Sinon.spy(event, 'emit');
|
||||
|
||||
@@ -1345,7 +1349,7 @@ test('should be able to manage context', async t => {
|
||||
'should list file id'
|
||||
);
|
||||
|
||||
const result = await session.matchFileChunks('test', 1, undefined, 1);
|
||||
const result = await session.matchFiles('test', 1, undefined, 1);
|
||||
t.is(result.length, 1, 'should match context');
|
||||
t.is(result[0].fileId, file.id, 'should match file id');
|
||||
}
|
||||
@@ -1499,13 +1503,13 @@ test('should be able to manage workspace embedding', async t => {
|
||||
});
|
||||
const contextSession = await context.create(sessionId);
|
||||
|
||||
const ret = await contextSession.matchFileChunks('test', 1, undefined, 1);
|
||||
const ret = await contextSession.matchFiles('test', 1, undefined, 1);
|
||||
t.is(ret.length, 1, 'should match workspace context');
|
||||
t.is(ret[0].content, 'content', 'should match content');
|
||||
|
||||
await workspace.update(ws.id, { enableDocEmbedding: false });
|
||||
|
||||
const ret2 = await contextSession.matchFileChunks('test', 1, undefined, 1);
|
||||
const ret2 = await contextSession.matchFiles('test', 1, undefined, 1);
|
||||
t.is(ret2.length, 0, 'should not match workspace context');
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user