mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 08:50:15 +01:00
chore: meilisearch setup config
This commit is contained in:
parent
73449d9ec6
commit
67161c983f
6 changed files with 17 additions and 12 deletions
|
|
@ -27,7 +27,9 @@ BING_TOKEN=
|
||||||
# SEARCH=TRUE
|
# SEARCH=TRUE
|
||||||
SEARCH=
|
SEARCH=
|
||||||
MEILI_HOST='http://localhost:7700'
|
MEILI_HOST='http://localhost:7700'
|
||||||
MEILI_KEY='MASTER_KEY'
|
MEILI_HTTP_ADDR='http://localhost:7700'
|
||||||
|
# needs a secure key, feel free to generate your own.
|
||||||
|
MEILI_MASTER_KEY=WjRvKvpelIYHa4dlcDGsdT9c0CKRbY-4VcuCQ1iZPcc
|
||||||
|
|
||||||
# User System
|
# User System
|
||||||
# global enable/disable the sample user system.
|
# global enable/disable the sample user system.
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,13 @@ const { MeiliSearch } = require('meilisearch');
|
||||||
// eslint-disable-next-line no-unused-vars
|
// eslint-disable-next-line no-unused-vars
|
||||||
async function indexSync(req, res, next) {
|
async function indexSync(req, res, next) {
|
||||||
try {
|
try {
|
||||||
if (!process.env.MEILI_HOST || !process.env.MEILI_KEY || !process.env.SEARCH) {
|
if (!process.env.MEILI_HOST || !process.env.MEILI_MASTER_KEY || !process.env.SEARCH) {
|
||||||
throw new Error('Meilisearch not configured, search will be disabled.');
|
throw new Error('Meilisearch not configured, search will be disabled.');
|
||||||
}
|
}
|
||||||
|
|
||||||
const client = new MeiliSearch({
|
const client = new MeiliSearch({
|
||||||
host: process.env.MEILI_HOST,
|
host: process.env.MEILI_HOST,
|
||||||
apiKey: process.env.MEILI_KEY
|
apiKey: process.env.MEILI_MASTER_KEY
|
||||||
});
|
});
|
||||||
|
|
||||||
const { status } = await client.health();
|
const { status } = await client.health();
|
||||||
|
|
|
||||||
|
|
@ -53,10 +53,10 @@ const convoSchema = mongoose.Schema(
|
||||||
{ timestamps: true }
|
{ timestamps: true }
|
||||||
);
|
);
|
||||||
|
|
||||||
if (process.env.MEILI_HOST && process.env.MEILI_KEY) {
|
if (process.env.MEILI_HOST && process.env.MEILI_MASTER_KEY) {
|
||||||
convoSchema.plugin(mongoMeili, {
|
convoSchema.plugin(mongoMeili, {
|
||||||
host: process.env.MEILI_HOST,
|
host: process.env.MEILI_HOST,
|
||||||
apiKey: process.env.MEILI_KEY,
|
apiKey: process.env.MEILI_MASTER_KEY,
|
||||||
indexName: 'convos', // Will get created automatically if it doesn't exist already
|
indexName: 'convos', // Will get created automatically if it doesn't exist already
|
||||||
primaryKey: 'conversationId'
|
primaryKey: 'conversationId'
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -57,10 +57,10 @@ const messageSchema = mongoose.Schema(
|
||||||
{ timestamps: true }
|
{ timestamps: true }
|
||||||
);
|
);
|
||||||
|
|
||||||
if (process.env.MEILI_HOST && process.env.MEILI_KEY) {
|
if (process.env.MEILI_HOST && process.env.MEILI_MASTER_KEY) {
|
||||||
messageSchema.plugin(mongoMeili, {
|
messageSchema.plugin(mongoMeili, {
|
||||||
host: process.env.MEILI_HOST,
|
host: process.env.MEILI_HOST,
|
||||||
apiKey: process.env.MEILI_KEY,
|
apiKey: process.env.MEILI_MASTER_KEY,
|
||||||
indexName: 'messages',
|
indexName: 'messages',
|
||||||
primaryKey: 'messageId'
|
primaryKey: 'messageId'
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ const { MeiliSearch } = require('meilisearch');
|
||||||
const { Message } = require('../../models/Message');
|
const { Message } = require('../../models/Message');
|
||||||
const { Conversation, getConvosQueried } = require('../../models/Conversation');
|
const { Conversation, getConvosQueried } = require('../../models/Conversation');
|
||||||
const { reduceHits } = require('../../lib/utils/reduceHits');
|
const { reduceHits } = require('../../lib/utils/reduceHits');
|
||||||
// const { MeiliSearch } = require('meilisearch');
|
|
||||||
const cache = new Map();
|
const cache = new Map();
|
||||||
|
|
||||||
router.get('/sync', async function (req, res) {
|
router.get('/sync', async function (req, res) {
|
||||||
|
|
@ -56,7 +55,8 @@ router.get('/', async function (req, res) {
|
||||||
cache.set(q, result.cache);
|
cache.set(q, result.cache);
|
||||||
delete result.cache;
|
delete result.cache;
|
||||||
result.messages = messages.filter(message => !result.filter.has(message.conversationId));
|
result.messages = messages.filter(message => !result.filter.has(message.conversationId));
|
||||||
console.log(result, messages.length);
|
// for debugging
|
||||||
|
// console.log(result, messages.length);
|
||||||
res.status(200).send(result);
|
res.status(200).send(result);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
|
|
@ -85,7 +85,7 @@ router.get('/enable', async function (req, res) {
|
||||||
try {
|
try {
|
||||||
const client = new MeiliSearch({
|
const client = new MeiliSearch({
|
||||||
host: process.env.MEILI_HOST,
|
host: process.env.MEILI_HOST,
|
||||||
apiKey: process.env.MEILI_KEY
|
apiKey: process.env.MEILI_MASTER_KEY
|
||||||
});
|
});
|
||||||
|
|
||||||
const { status } = await client.health();
|
const { status } = await client.health();
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,10 @@ services:
|
||||||
image: getmeili/meilisearch:v1.0
|
image: getmeili/meilisearch:v1.0
|
||||||
ports:
|
ports:
|
||||||
- 7700:7700
|
- 7700:7700
|
||||||
environment:
|
env_file:
|
||||||
- MEILI_MASTER_KEY=MASTER_KEY
|
- ./api/.env
|
||||||
|
# environment:
|
||||||
|
# # needs a secure key, feel free to generate your own
|
||||||
|
# - MEILI_MASTER_KEY=WjRvKvpelIYHa4dlcDGsdT9c0CKRbY-4VcuCQ1iZPcc
|
||||||
volumes:
|
volumes:
|
||||||
- ./meili_data:/meili_data
|
- ./meili_data:/meili_data
|
||||||
Loading…
Add table
Add a link
Reference in a new issue