How the search on this site works

The search console on the home page is the retrieval layer of a RAG system with no external API behind it. This is what runs when you press enter, why it is retrieval only, and why a few hundred dot products beat a vector database at this size.

Written by
Baraqix Engineering
Published
Read
7 min
Filed under
rag, search, build notes
Search on this siteHow the search on this site works. A visitor's query goes to POST /api/search, which checks its length, rate limits by IP and logs the query with the IP hashed. The all-MiniLM-L6-v2 model, in ONNX format and running on our own server, turns the query into a 384 dimension vector. Cosine similarity scores it against every chunk in an in-memory index of the site's pages and published posts. Results below a score of 0.35 are dropped and the top 5 are returned with their scores. No external API is called and nothing is generated: it is retrieval only. The index is rebuilt with the same model on deploy and when a post is published.FIG/SRCH-07Search on this siteLIVE PATHMODELASYNC OR FALLBACKGUARDRAILONE NODE PROCESS, OUR VPSNO EXTERNAL API, RETRIEVAL ONLY384 dimevery chunkreindexvectorsIN/VISITORQueryAPI/SRCH-01POST /api/searchMDL/ONNX-01all-MiniLM-L6-v2SIM/COS-01Cosine similarityGRD/THR-01Score ≥ 0.35OUT/TOP-5Top 5 + scoresSRC/CORPUSSite corpusMEM/IDX-01In-memory indexONNX, on the server,loaded once30 per minute per IPlogged, IP hashedpages + published postsSearch on this siteHow the search on this site works. A visitor's query goes to POST /api/search, which checks its length, rate limits by IP and logs the query with the IP hashed. The all-MiniLM-L6-v2 model, in ONNX format and running on our own server, turns the query into a 384 dimension vector. Cosine similarity scores it against every chunk in an in-memory index of the site's pages and published posts. Results below a score of 0.35 are dropped and the top 5 are returned with their scores. No external API is called and nothing is generated: it is retrieval only. The index is rebuilt with the same model on deploy and when a post is published.FIG/SRCH-07Search on this siteLIVE PATHMODELASYNC OR FALLBACKGUARDRAILNO EXTERNAL API, RETRIEVAL ONLY384 dimIN/VISITORQueryAPI/SRCH-01POST /api/searchMDL/ONNX-01all-MiniLM-L6-v2SIM/COS-01Cosine similarityGRD/THR-01Score ≥ 0.35OUT/TOP-5Top 5 + scoresSRC/CORPUSSitecorpusMEM/IDX-01In-memoryindex

Every AI agency website says it builds retrieval systems. Saying it costs nothing, so we put one on the home page instead. The search console there is the retrieval layer of a RAG system, running on the same small server as this site, indexing this site. This note is what happens when you press enter, and why. Everything below is true to the code as deployed.

01

Why the demo stops at retrieval

A RAG system has two halves. Retrieval finds the passages relevant to the question. Generation writes an answer from them. Almost every RAG failure we have debugged lived in the first half. The wrong passage ranked first. The right passage was split across two chunks so neither matched. The threshold was tuned on a sample folder and fell apart on the real corpus. Generation then wrote a confident paragraph on top of a bad retrieval, and that paragraph is what the user saw.

So the demo shows the half that matters. It ranks passages that already exist on this site and shows the similarity score for each. It never calls a language model to write anything, which is why the mechanics panel says the tool cannot invent a price, a timeline or a client. No component in the pipeline can produce text that is not already on a page.

There is a practical reason too. The site runs on a shared virtual server with three cores and six gigabytes of memory, next to PostgreSQL and the site itself, with zero external API spend. A small embedding model fits that budget. A generative model on CPU would saturate the cores and undercut the demo.

02

The model

The embedding model is all-MiniLM-L6-v2, run in Node through the transformers.js feature extraction pipeline with mean pooling and normalisation on. It produces a 384 dimension vector for any string, sits under a hundred megabytes on disk and around four hundred in memory with the runtime. It loads once at server start and stays resident. A model loaded per request would turn a thirty millisecond query into a multi second one and eventually run the box out of memory.

Because every vector is normalised to unit length, cosine similarity reduces to a dot product. The scoring function is a loop over 384 floats. That is the whole algorithm, and it is worth saying because people expect something more elaborate.

LST/01TypeScript
function cosineSimilarity(a: Float32Array, b: Float32Array): number {
  let dot = 0;
  for (let i = 0; i < a.length; i++) dot += a[i] * b[i];
  // Vectors are already normalised, so the dot product is the cosine.
  return dot;
}
03

How the corpus is chunked

The index is built from the same structured content objects the pages render from, so it cannot drift from what a visitor reads. Each service, process step and belief, and the main passages on the home page, become one chunk carrying its source page, a section anchor and the text. Published notes from this blog are added as title plus excerpt plus flattened body, capped at twelve hundred characters so a long post does not dominate the index with one enormous vector.

The first version chunked purely by section and had a problem we could measure. The AI integration service description mentioned reading PDF and DOCX files, but it also covered agents, MCP, voice and the stack in one paragraph. When someone asked whether we could read their PDFs, that chunk scored 0.28 against a threshold of 0.35 and missed, even though the words were in it. A long chunk about six topics is a weak match for a question about one. The fix was a dedicated shorter chunk carrying the same claim already on the page, phrased closer to how a visitor asks. It scored 0.42. The rule for adding one is strict: it may restate a claim already on the site and may never introduce a new one. The demo is proof. It is not allowed to be a more generous copy of the marketing.

The general lesson is that chunk size is a retrieval parameter before it is a formatting decision. A chunk should be about one thing, sized so a plausible question about that thing lands inside it, and carry enough context that the result card makes sense on its own.

04

Why brute force wins at this size

The corpus is in the low hundreds of chunks. Scoring a query means a few hundred dot products of 384 floats, on the order of a hundred thousand multiply and add operations, which a CPU finishes in well under a millisecond. Almost all of the retrieval time in the mechanics panel is the embedding pass for your query. A vector database here would add a network hop, a second process to keep alive and a place for the index to drift from the pages, in exchange for making the fast part faster.

TAB/01When each approach is the right call.
QuestionIn memory brute forcepgvector or a vector database
Corpus sizeHundreds to a few thousand chunksTens of thousands and up
Scoring costMicroseconds, a loopIndex lookup, approximate nearest neighbour
FilteringFilter the array in codeWHERE clauses next to the vector search
PersistenceRebuilt on deploy, lives in process memorySurvives restarts, shared between processes
WritersOne process rebuilds the whole indexMany writers, row level updates
Operational costNone beyond the modelAn extension or a service to run and monitor

Brute force stays correct until one of three things happens: the corpus grows until a linear scan is noticeable, you need to filter by metadata inside the search instead of after it, or more than one process needs to write to the index. For a client with an archive in the hundreds of thousands, pgvector inside the PostgreSQL they already run is usually the next step, because it keeps vectors next to the rows they describe and reuses existing backups and access control. A separate vector database earns its place after that, when the index needs its own machine.

05

The request path

  1. Your query goes to POST /api/search. It must be between one and two hundred characters, and each address gets thirty searches a minute.
  2. If the index is empty, for example on the first request after a deploy, the server builds it before answering.
  3. The query is embedded with the same model and pooling as the corpus. Mixing models here is a classic silent failure.
  4. Every chunk is scored by dot product and sorted. Anything below 0.35 is dropped. The top five are returned with source page, anchor and score.
  5. The query, the top score, the result count and a hashed address are written to PostgreSQL. Reading that table weekly is the cheapest research into what prospects ask.

The index is a singleton on the Node global object. That sounds like a hack and it is a considered one. The development server reloads modules on every edit, and without the global the model would reload on every save. In production the same object is what lets the index survive across requests. One shared function rebuilds it on deploy and whenever a note is published, so a new post is searchable the moment it goes live.

06

What the mechanics panel shows

Under the results there is a mono panel. Chunks searched is the size of the index at that moment, so it rises when a note is published. Embedding dims is 384, the width of every vector. Retrieval time is measured from the start of the request handler to the point the results are ready, so it includes the query embedding. The model name is there so you can look it up. The method line says cosine similarity over an in memory index, and the generation line says none. A search box on its own is a claim. A search box with its mechanics visible is a demonstration.

07

What we would change for a client

For a real document corpus the first change is the chunker, splitting long documents into overlapping passages with the heading path attached. The second is an evaluation set, a few dozen real questions with the passage that should rank first, run on every change to the chunker or the threshold. The third is a hybrid keyword and vector score once the corpus is large enough that exact terms such as product codes start to miss. Generation comes last, only after retrieval precision is measured and acceptable.

Baraqix Engineering. Written by the engineers who did the work.

NOTE/02. First published .

Where this work fits

The services behind this note.

  • SVC/AI-01

    AI integration

    RAG, agents, MCP servers and voice, built into the product you already have.

  • ENG/SPRINT

    Discovery Sprint

    A fixed price Discovery Sprint. The architecture document and a working spike on your real data, in a repository you own.

If something in this note looks like your problem, the reply comes from the engineers who built it.