mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-28 14:18:51 +01:00
refactor(data-schemas): reintroduce mongoMeili plugin for conversation and message schemas
- Added mongoMeili plugin back to convoSchema and messageSchema for enhanced search capabilities. - Updated import statements to use Schema directly from mongoose for consistency. - Removed conditional checks for the plugin from model files, centralizing the logic in the schema definitions.
This commit is contained in:
parent
2d492b932f
commit
728d19e361
4 changed files with 24 additions and 24 deletions
|
|
@ -1,17 +1,6 @@
|
|||
import mongoose from 'mongoose';
|
||||
import type * as t from '~/types';
|
||||
import mongoMeili from '~/models/plugins/mongoMeili';
|
||||
import convoSchema from '~/schema/convo';
|
||||
|
||||
if (process.env.MEILI_HOST && process.env.MEILI_MASTER_KEY) {
|
||||
convoSchema.plugin(mongoMeili, {
|
||||
host: process.env.MEILI_HOST,
|
||||
apiKey: process.env.MEILI_MASTER_KEY,
|
||||
/** Note: Will get created automatically if it doesn't exist already */
|
||||
indexName: 'convos',
|
||||
primaryKey: 'conversationId',
|
||||
});
|
||||
}
|
||||
|
||||
export const Conversation =
|
||||
mongoose.models.Conversation || mongoose.model<t.IConversation>('Conversation', convoSchema);
|
||||
|
|
|
|||
|
|
@ -1,16 +1,6 @@
|
|||
import mongoose from 'mongoose';
|
||||
import mongoMeili from '~/models/plugins/mongoMeili';
|
||||
import messageSchema from '~/schema/message';
|
||||
import type * as t from '~/types';
|
||||
|
||||
if (process.env.MEILI_HOST && process.env.MEILI_MASTER_KEY) {
|
||||
messageSchema.plugin(mongoMeili, {
|
||||
host: process.env.MEILI_HOST,
|
||||
apiKey: process.env.MEILI_MASTER_KEY,
|
||||
indexName: 'messages',
|
||||
primaryKey: 'messageId',
|
||||
});
|
||||
}
|
||||
|
||||
export const Message =
|
||||
mongoose.models.Message || mongoose.model<t.IMessage>('Message', messageSchema);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import mongoose, { Schema } from 'mongoose';
|
||||
import { Schema } from 'mongoose';
|
||||
import mongoMeili from '~/models/plugins/mongoMeili';
|
||||
import { conversationPreset } from './defaults';
|
||||
import { IConversation } from '~/types';
|
||||
|
||||
|
|
@ -20,9 +21,9 @@ const convoSchema: Schema<IConversation> = new Schema(
|
|||
type: String,
|
||||
index: true,
|
||||
},
|
||||
messages: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Message' }],
|
||||
messages: [{ type: Schema.Types.ObjectId, ref: 'Message' }],
|
||||
agentOptions: {
|
||||
type: mongoose.Schema.Types.Mixed,
|
||||
type: Schema.Types.Mixed,
|
||||
},
|
||||
...conversationPreset,
|
||||
agent_id: {
|
||||
|
|
@ -47,4 +48,14 @@ convoSchema.index({ expiredAt: 1 }, { expireAfterSeconds: 0 });
|
|||
convoSchema.index({ createdAt: 1, updatedAt: 1 });
|
||||
convoSchema.index({ conversationId: 1, user: 1 }, { unique: true });
|
||||
|
||||
if (process.env.MEILI_HOST && process.env.MEILI_MASTER_KEY) {
|
||||
convoSchema.plugin(mongoMeili, {
|
||||
host: process.env.MEILI_HOST,
|
||||
apiKey: process.env.MEILI_MASTER_KEY,
|
||||
/** Note: Will get created automatically if it doesn't exist already */
|
||||
indexName: 'convos',
|
||||
primaryKey: 'conversationId',
|
||||
});
|
||||
}
|
||||
|
||||
export default convoSchema;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import mongoose, { Schema, Document } from 'mongoose';
|
||||
import mongoMeili from '~/models/plugins/mongoMeili';
|
||||
|
||||
// @ts-ignore
|
||||
export interface IMessage extends Document {
|
||||
|
|
@ -182,4 +183,13 @@ messageSchema.index({ expiredAt: 1 }, { expireAfterSeconds: 0 });
|
|||
messageSchema.index({ createdAt: 1 });
|
||||
messageSchema.index({ messageId: 1, user: 1 }, { unique: true });
|
||||
|
||||
if (process.env.MEILI_HOST && process.env.MEILI_MASTER_KEY) {
|
||||
messageSchema.plugin(mongoMeili, {
|
||||
host: process.env.MEILI_HOST,
|
||||
apiKey: process.env.MEILI_MASTER_KEY,
|
||||
indexName: 'messages',
|
||||
primaryKey: 'messageId',
|
||||
});
|
||||
}
|
||||
|
||||
export default messageSchema;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue