NeoQuarZ:~Archetype
EN ⇄ ES
← Back to projects

Local document assistant

Search sample documents and see the source of each result.

PythonOllamaRAG
WEB PROTOTYPE

This first version finds keyword matches in three sample documents. It does not use a language model or upload files.

local.documentsKEYWORD SEARCH

Excerpts and sources

View concept code
export const documents = {
  es: [
    {
      title: '01 / copias.md',
      text: 'Las copias de seguridad del ejemplo se guardan a diario. La restauración debe probarse antes de dar una copia por válida.',
    },
    {
      title: '02 / servidor.md',
      text: 'El servidor del ejemplo utiliza contenedores. Antes de actualizar, se revisan los registros y se prepara un plan de vuelta atrás.',
    },
    {
      title: '03 / contacto.md',
      text: 'El contacto del sitio es contact@chemicalriotlab.com. Para solicitar asesoría, describe el problema y el resultado que necesitas.',
    },
  ],
  en: [
    {
      title: '01 / backups.md',
      text: 'Sample backups are saved daily. Recovery must be tested before a backup is considered usable.',
    },
    {
      title: '02 / server.md',
      text: 'The sample server uses containers. Before an update, review logs and prepare a rollback plan.',
    },
    {
      title: '03 / contact.md',
      text: 'The website contact is contact@chemicalriotlab.com. To request consulting, describe the issue and your expected outcome.',
    },
  ],
};
const normalize = (s) =>
  s
    .normalize('NFD')
    .replace(/[\u0300-\u036f]/g, '')
    .toLowerCase();
export function search(query, lang = 'es') {
  const stop = new Set([
    'para',
    'como',
    'donde',
    'esta',
    'estan',
    'the',
    'what',
    'where',
    'with',
    'from',
    'about',
  ]);
  const terms =
    normalize(String(query))
      .match(/[a-z0-9]+/g)
      ?.filter((w) => w.length > 2 && !stop.has(w)) || [];
  if (!terms.length) return [];
  return documents[lang]
    .map((d) => ({
      ...d,
      score: terms.filter((w) => normalize(d.title + ' ' + d.text).includes(w)).length,
    }))
    .filter((d) => d.score > 0)
    .sort((a, b) => b.score - a.score);
}

To turn this into a production application

Integrate a local model, add semantic retrieval and evaluate cited answers before using real documents.

Talk about this project ↗
NEOQUARZ / ARCHETYPE~/projects/local-assistant0%