Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion database/schema/chatHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,21 @@ const { default: mongoose } = require("mongoose");
/**
* Conversation & memory management
*/
const schema = new mongoose.Schema({});
const schema = new mongoose.Schema({
userId: { type: mongoose.Schema.Types.ObjectId, ref: 'User', index: true },
sessionId: { type: String, index: true },
messages: [
{
role: { type: String, enum: ['user', 'assistant', 'system'], default: 'user' },
content: { type: String },
metadata: { type: Object },
createdAt: { type: Date, default: Date.now },
},
],
lastQuestion: { type: String },
lastAnswer: { type: String },
relatedDocuments: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Document' }],
}, { timestamps: true });

const ChatHistoryModal = mongoose.model("ChatHistory", schema);

Expand Down
14 changes: 13 additions & 1 deletion database/schema/chunk.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
const { default: mongoose } = require("mongoose");

const schema = new mongoose.Schema({});
const schema = new mongoose.Schema({
documentId: { type: mongoose.Schema.Types.ObjectId, ref: 'Document', required: true, index: true },
pageNumber: { type: Number, default: 1 },
chunkIndex: { type: Number, default: 0 },
text: { type: String, required: true },
textLength: { type: Number },
vector: { type: [Number] },
embeddingStatus: { type: String, enum: ['PENDING', 'EMBEDDED', 'FAILED'], default: 'PENDING' },
payload: { type: Object },
}, { timestamps: true });

// Text index for search
schema.index({ text: 'text' });

const ChunkModal = mongoose.model("Chunk", schema);

Expand Down
21 changes: 16 additions & 5 deletions database/schema/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,22 @@ const { default: mongoose } = require("mongoose");
*/

const schema = new mongoose.Schema({
filename: String,
size: String,
status: String,
type: String,
});
filename: { type: String, required: true },
originalname: { type: String },
path: { type: String, required: true },
size: { type: Number },
mimetype: { type: String },
status: {
type: String,
enum: ['NOT_STARTED', 'PROCESSING', 'EMBEDDING', 'EMBEDDED', 'ERROR'],
default: 'NOT_STARTED',
},
type: { type: String },
userId: { type: mongoose.Schema.Types.ObjectId, ref: 'User', index: true },
numPages: { type: Number },
chunks: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Chunk' }],
metadata: { type: Object },
}, { timestamps: true });

const DocumentModal = mongoose.model("Document", schema);

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"openai": "^6.15.0",
"pdf-parse": "^2.4.5"
},
"name": "backend",
"name": "rag-docflow",
"version": "1.0.0",
"description": "this system receive documents from the users and store them in db in the document entity. and track the process as history entity this history entity will track the processing of the document either is embedded or not from the LLM",
"main": "main.js",
Expand Down