feat: add rag by codex
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
import Joi, { type CustomHelpers } from 'joi';
|
||||
|
||||
export const documentMimeTypes = [
|
||||
'application/pdf',
|
||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
||||
'text/plain',
|
||||
];
|
||||
|
||||
export const maxUploadBytes = 20 * 1024 * 1024;
|
||||
|
||||
interface RagLimits {
|
||||
RAG_CHUNK_SIZE: number;
|
||||
RAG_CHUNK_OVERLAP: number;
|
||||
RAG_CONTEXT_BYTES: number;
|
||||
RAG_PROMPT_BYTES: number;
|
||||
}
|
||||
|
||||
export function validateRagLimits<T extends RagLimits>(
|
||||
value: T,
|
||||
helpers: CustomHelpers,
|
||||
) {
|
||||
if (value.RAG_CHUNK_OVERLAP >= value.RAG_CHUNK_SIZE) {
|
||||
return helpers.message({
|
||||
custom: 'RAG_CHUNK_OVERLAP must be smaller than RAG_CHUNK_SIZE',
|
||||
});
|
||||
}
|
||||
if (value.RAG_CONTEXT_BYTES >= value.RAG_PROMPT_BYTES) {
|
||||
return helpers.message({
|
||||
custom: 'RAG_CONTEXT_BYTES must be smaller than RAG_PROMPT_BYTES',
|
||||
});
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
export const ragValidation = {
|
||||
RAG_ENABLED: Joi.boolean().default(false),
|
||||
RAG_EMBEDDING_URL: Joi.string()
|
||||
.uri({ scheme: ['http', 'https'] })
|
||||
.default('http://localhost:8080'),
|
||||
RAG_EMBEDDING_MODEL: Joi.string()
|
||||
.max(240)
|
||||
.default('intfloat/multilingual-e5-small'),
|
||||
RAG_EMBEDDING_REVISION: Joi.string()
|
||||
.hex()
|
||||
.length(40)
|
||||
.default('62ff60abe92eb88c1b297fabaad28f7ac77b5875'),
|
||||
RAG_EMBEDDING_TIMEOUT_MS: Joi.number()
|
||||
.integer()
|
||||
.min(1000)
|
||||
.max(120000)
|
||||
.default(30000),
|
||||
RAG_BATCH_SIZE: Joi.number().integer().min(1).max(32).default(8),
|
||||
RAG_CHUNK_SIZE: Joi.number().integer().min(64).max(480).default(440),
|
||||
RAG_CHUNK_OVERLAP: Joi.number().integer().min(0).max(160).default(88),
|
||||
RAG_TOP_K: Joi.number().integer().min(1).max(12).default(5),
|
||||
RAG_SIMILARITY_THRESHOLD: Joi.number().min(0).max(1).default(0.78),
|
||||
RAG_CONTEXT_BYTES: Joi.number().integer().min(1024).max(64000).default(10000),
|
||||
RAG_PROMPT_BYTES: Joi.number().integer().min(6000).max(128000).default(14000),
|
||||
RAG_INGESTION_CONCURRENCY: Joi.number().integer().min(1).max(4).default(1),
|
||||
RAG_UPLOAD_MAX_BYTES: Joi.number()
|
||||
.integer()
|
||||
.min(1)
|
||||
.max(maxUploadBytes)
|
||||
.default(10 * 1024 * 1024),
|
||||
RAG_UPLOAD_MIME_TYPES: Joi.string()
|
||||
.custom((value: string, helpers) =>
|
||||
value.split(',').every((mime) => documentMimeTypes.includes(mime.trim()))
|
||||
? value
|
||||
: helpers.error('any.invalid'),
|
||||
)
|
||||
.default(documentMimeTypes.join(',')),
|
||||
RAG_STORAGE_DIR: Joi.string().trim().min(1).default('./private-articles'),
|
||||
};
|
||||
Reference in New Issue
Block a user