Skip to content

Commit 66b570f

Browse files
committed
store rag file metadata in db
1 parent a017ba1 commit 66b570f

File tree

12 files changed

+330
-310
lines changed

12 files changed

+330
-310
lines changed

src/client/components/Rag/ProgressReporter.tsx

Lines changed: 0 additions & 187 deletions
This file was deleted.

src/server/db/migrations/20250521_00_add_files_to_rag_indexes.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import { DataTypes } from 'sequelize'
2+
3+
import { Migration } from '../connection'
4+
5+
export const up: Migration = ({ context: queryInterface }) =>
6+
queryInterface.createTable('rag_files', {
7+
id: {
8+
type: DataTypes.INTEGER,
9+
allowNull: false,
10+
primaryKey: true,
11+
autoIncrement: true,
12+
},
13+
rag_index_id: {
14+
type: DataTypes.INTEGER,
15+
allowNull: false,
16+
references: {
17+
model: 'rag_indices',
18+
key: 'id',
19+
},
20+
onUpdate: 'CASCADE',
21+
onDelete: 'CASCADE',
22+
},
23+
pipeline_stage: {
24+
type: DataTypes.STRING,
25+
allowNull: false,
26+
defaultValue: 'pending',
27+
comment: 'Stage of the ingestion pipeline',
28+
},
29+
error: {
30+
type: DataTypes.STRING,
31+
allowNull: true,
32+
comment: 'Error message if any error occurred during the ingestion pipeline',
33+
},
34+
filename: {
35+
type: DataTypes.STRING,
36+
allowNull: false,
37+
comment: 'Name of the uploaded file',
38+
},
39+
file_type: {
40+
type: DataTypes.STRING,
41+
allowNull: false,
42+
comment: 'Type of the uploaded file (e.g., pdf, md, text)',
43+
},
44+
file_size: {
45+
type: DataTypes.INTEGER,
46+
allowNull: false,
47+
comment: 'Number of characters in the file after text extraction',
48+
},
49+
num_chunks: {
50+
type: DataTypes.INTEGER,
51+
allowNull: true,
52+
comment: 'Number of chunks created from the file',
53+
},
54+
user_id: {
55+
type: DataTypes.STRING,
56+
allowNull: false,
57+
comment: 'ID of the user who uploaded the file',
58+
},
59+
metadata: {
60+
type: DataTypes.JSONB,
61+
allowNull: true,
62+
},
63+
created_at: {
64+
type: DataTypes.DATE,
65+
allowNull: false,
66+
},
67+
updated_at: {
68+
type: DataTypes.DATE,
69+
allowNull: false,
70+
},
71+
})
72+
73+
export const down: Migration = ({ context: queryInterface }) => queryInterface.dropTable('rag_files')

src/server/db/models/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Enrolment from './enrolment'
66
import Responsibility from './responsibilities'
77
import Discussion from './discussion'
88
import RagIndex from './ragIndex'
9+
import RagFile from './ragFile'
910

1011
User.belongsToMany(ChatInstance, {
1112
through: UserChatInstanceUsage,
@@ -47,4 +48,10 @@ User.hasMany(RagIndex, { as: 'ragIndices' })
4748

4849
RagIndex.belongsTo(User, { as: 'user' })
4950

50-
export { User, ChatInstance, UserChatInstanceUsage, Prompt, Enrolment, Responsibility, Discussion, RagIndex }
51+
RagFile.belongsTo(RagIndex, { as: 'ragIndex' })
52+
53+
RagIndex.hasMany(RagFile, { as: 'ragFiles' })
54+
55+
RagFile.belongsTo(User, { as: 'user' })
56+
57+
export { User, ChatInstance, UserChatInstanceUsage, Prompt, Enrolment, Responsibility, Discussion, RagIndex, RagFile }

src/server/db/models/ragFile.ts

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import { Model, InferAttributes, InferCreationAttributes, CreationOptional, DataTypes } from 'sequelize'
2+
3+
import { sequelize } from '../connection'
4+
import { IngestionPipelineStageKey } from '../../../shared/constants'
5+
6+
class RagFile extends Model<InferAttributes<RagFile>, InferCreationAttributes<RagFile>> {
7+
declare id: CreationOptional<number>
8+
9+
declare ragIndexId: number
10+
11+
declare pipelineStage: CreationOptional<IngestionPipelineStageKey>
12+
13+
declare error: CreationOptional<string | null>
14+
15+
declare filename: string
16+
17+
declare fileType: string
18+
19+
declare fileSize: number
20+
21+
declare numChunks: CreationOptional<number | null>
22+
23+
declare userId: string
24+
25+
declare metadata: Record<string, unknown> | null
26+
}
27+
28+
RagFile.init(
29+
{
30+
id: {
31+
type: DataTypes.INTEGER,
32+
allowNull: false,
33+
primaryKey: true,
34+
autoIncrement: true,
35+
},
36+
ragIndexId: {
37+
type: DataTypes.INTEGER,
38+
allowNull: false,
39+
references: {
40+
model: 'rag_indices',
41+
key: 'id',
42+
},
43+
onUpdate: 'CASCADE',
44+
onDelete: 'CASCADE',
45+
},
46+
pipelineStage: {
47+
type: DataTypes.STRING,
48+
allowNull: false,
49+
defaultValue: 'pending',
50+
},
51+
error: {
52+
type: DataTypes.STRING,
53+
allowNull: true,
54+
},
55+
filename: {
56+
type: DataTypes.STRING,
57+
allowNull: false,
58+
},
59+
fileType: {
60+
type: DataTypes.STRING,
61+
allowNull: false,
62+
},
63+
fileSize: {
64+
type: DataTypes.INTEGER,
65+
allowNull: false,
66+
},
67+
numChunks: {
68+
type: DataTypes.INTEGER,
69+
allowNull: true,
70+
},
71+
userId: {
72+
type: DataTypes.STRING,
73+
allowNull: false,
74+
},
75+
metadata: {
76+
type: DataTypes.JSONB,
77+
allowNull: true,
78+
},
79+
},
80+
{
81+
underscored: true,
82+
timestamps: true,
83+
sequelize,
84+
},
85+
)
86+
87+
export default RagFile
88+
89+
export type RagFileAttributes = InferAttributes<RagFile>

0 commit comments

Comments
 (0)