mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-01-03 09:08:52 +01:00
search: correctly register/export schema/models for mongoMeili
This commit is contained in:
parent
8be19f9982
commit
a5cf2f9148
6 changed files with 231 additions and 53 deletions
|
|
@ -1,5 +1,6 @@
|
|||
const mongoose = require('mongoose');
|
||||
module.exports = mongoose.Schema(
|
||||
const mongoMeili = require('../plugins/mongoMeili');
|
||||
const convoSchema = mongoose.Schema(
|
||||
{
|
||||
conversationId: {
|
||||
type: String,
|
||||
|
|
@ -50,4 +51,15 @@ module.exports = mongoose.Schema(
|
|||
messages: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Message' }]
|
||||
},
|
||||
{ timestamps: true }
|
||||
);
|
||||
);
|
||||
|
||||
convoSchema.plugin(mongoMeili, {
|
||||
host: process.env.MEILI_HOST,
|
||||
apiKey: process.env.MEILI_KEY,
|
||||
indexName: 'convos', // Will get created automatically if it doesn't exist already
|
||||
primaryKey: 'conversationId'
|
||||
});
|
||||
|
||||
const Conversation = mongoose.models.Conversation || mongoose.model('Conversation', convoSchema);
|
||||
|
||||
module.exports = Conversation;
|
||||
|
|
|
|||
|
|
@ -1,46 +0,0 @@
|
|||
const mongoose = require('mongoose');
|
||||
const convoSchema = require('./convoSchema');
|
||||
const messageSchema = require('./messageSchema');
|
||||
const { MeiliSearch } = require('meilisearch');
|
||||
const mongoMeili = require('../../lib/db/mongoMeili');
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
const client = new MeiliSearch({
|
||||
host: process.env.MEILI_HOST,
|
||||
apiKey: process.env.MEILI_KEY
|
||||
});
|
||||
|
||||
const { status } = await client.health();
|
||||
console.log(`Meilisearch: ${status}`);
|
||||
const result = status === 'available' && !!process.env.SEARCH;
|
||||
|
||||
if (!result) {
|
||||
throw new Error('Meilisearch not available');
|
||||
}
|
||||
|
||||
convoSchema.plugin(mongoMeili, {
|
||||
host: process.env.MEILI_HOST,
|
||||
apiKey: process.env.MEILI_KEY,
|
||||
indexName: 'convos', // Will get created automatically if it doesn't exist already
|
||||
primaryKey: 'conversationId'
|
||||
});
|
||||
|
||||
messageSchema.plugin(mongoMeili, {
|
||||
host: process.env.MEILI_HOST,
|
||||
apiKey: process.env.MEILI_KEY,
|
||||
indexName: 'messages',
|
||||
primaryKey: 'messageId'
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.log('Meilisearch error, search will be disabled');
|
||||
console.error(error);
|
||||
}
|
||||
})();
|
||||
|
||||
const Conversation =
|
||||
mongoose.models.Conversation || mongoose.model('Conversation', convoSchema);
|
||||
const Message = mongoose.models.Message || mongoose.model('Message', messageSchema);
|
||||
|
||||
module.exports = { Conversation, Message };
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
const mongoose = require('mongoose');
|
||||
module.exports = mongoose.Schema({
|
||||
const mongoMeili = require('../plugins/mongoMeili');
|
||||
const messageSchema = mongoose.Schema({
|
||||
messageId: {
|
||||
type: String,
|
||||
unique: true,
|
||||
|
|
@ -51,4 +52,15 @@ module.exports = mongoose.Schema({
|
|||
select: false,
|
||||
default: false
|
||||
}
|
||||
}, { timestamps: true });
|
||||
}, { timestamps: true });
|
||||
|
||||
messageSchema.plugin(mongoMeili, {
|
||||
host: process.env.MEILI_HOST,
|
||||
apiKey: process.env.MEILI_KEY,
|
||||
indexName: 'messages',
|
||||
primaryKey: 'messageId'
|
||||
});
|
||||
|
||||
const Message = mongoose.models.Message || mongoose.model('Message', messageSchema);
|
||||
|
||||
module.exports = Message;
|
||||
Loading…
Add table
Add a link
Reference in a new issue