---
title: "Discussion on \"Embeddings, Vector Search & RAG from Scratch with Node.js and PostgreSQL (pgvector)\" | Hashnode"
description: "Discussion on \"Embeddings, Vector Search & RAG from Scratch with Node.js and PostgreSQL (pgvector)\". Learn the building blocks before you touch LangChain"
url: "https://hashnode.com/posts/embeddings-vector-search-rag-from-scratch-with-node-js-and-postgresql-pgvector/6ac886790b56f76134c18b6f"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Embeddings, Vector Search & RAG from Scratch with Node.js and PostgreSQL (pgvector)](https://leeonscoding.hashnode.dev/embeddings-vector-search-rag-from-scratch-with-node-js-and-postgresql-pgvector?utm_source=hashnode&utm_medium=feed)

Learn the building blocks before you touch LangChain

Oct 9 · 13 min read · leeonscoding.hashnode.dev  
Updated 4d ago  
Read the article

-   [#ai](https://hashnode.com/tag/ai)
-   [#rag](https://hashnode.com/tag/rag)
-   [#embeddings](https://hashnode.com/tag/embeddings)
-   [#vector-embeddings](https://hashnode.com/tag/vector-embeddings)
-   [#semantic-search](https://hashnode.com/tag/semantic-search)
-   [#pgvector](https://hashnode.com/tag/pgvector)

## Written by

[Asfaq Leeon](https://hashnode.com/@leeonscoding)

@leeonscoding · Dhaka, Bangladesh

  
[View profile](https://hashnode.com/@leeonscoding)

Senior Software Engineer

## Responses 3

Markdown supported · ⌘↵ to post

[Ahmet Özel](https://hashnode.com/@ahmetozel)

[Oct 11](https://hashnode.com/posts/embeddings-vector-search-rag-from-scratch-with-node-js-and-postgresql-pgvector/6ac886790b56f76134c18b6f/comment/6acb5aa99d3b390249830fcf)

The simple chunker has an edge case worth adding to its known limitations: with overlap set to zero, current.slice(-overlap) becomes slice(0), which copies the entire previous chunk. A caller trying to disable overlap can therefore get growing duplicated content instead.

I would handle zero explicitly and validate that overlap is non-negative and smaller than chunkSize. A tiny fixture with several short paragraphs can assert the exact chunk boundaries for zero and positive overlap. That makes the from-scratch implementation more useful for your suggested 300, 800 and 2000-character experiments, where an unnoticed duplication bug would distort the retrieval comparison.

[Asfaq Leeon](https://hashnode.com/@leeonscoding)

[Oct 17](https://hashnode.com/posts/embeddings-vector-search-rag-from-scratch-with-node-js-and-postgresql-pgvector/6ac886790b56f76134c18b6f/comment/6acb5aa99d3b390249830fcf#reply-6ad3b15b7ae3050570955cb8)

Wow, great catch! Also, thanks for reading the blog and trying the code. You’re right: with overlap = 0, current.slice(-overlap) becomes slice(0), so the old snippet copied the whole previous chunk into the next one.

[Ahmet Özel](https://hashnode.com/@ahmetozel)

[Oct 20](https://hashnode.com/posts/embeddings-vector-search-rag-from-scratch-with-node-js-and-postgresql-pgvector/6ac886790b56f76134c18b6f/comment/6acb5aa99d3b390249830fcf#reply-6ad72a4099cf66806f7fdcfd)

That zero case is easy to miss because positive overlap still appears to work. An explicit zero branch makes the intended behavior much easier to reason about than relying on negative slicing.

I would also keep a progress invariant in the fixture: each emitted chunk must advance to new source text, and the final chunk must terminate without repeating the same suffix forever. Testing empty paragraphs and a paragraph longer than chunkSize alongside overlap=0 would help separate the duplication fix from the chunker's remaining size-limit behavior.
