{"id":310,"date":"2026-11-23T13:00:03","date_gmt":"2026-11-23T13:00:03","guid":{"rendered":"https:\/\/devdojo.co.in\/?p=310"},"modified":"2026-11-23T13:00:05","modified_gmt":"2026-11-23T13:00:05","slug":"genai-series-part-10-vector-databases","status":"publish","type":"post","link":"https:\/\/devdojo.co.in\/index.php\/2026\/11\/23\/genai-series-part-10-vector-databases\/","title":{"rendered":"Generative AI Part 10: Vector Databases: pgvector, Chroma and Pinecone"},"content":{"rendered":"\n<div class=\"dd-post\">\n<style>\n.single article:has(.dd-hero) .entry-media{display:none}\n.dd-post{--navy:#0b1020;--blue:#3178c6;--violet:#7c5cff;--ink:#1f2433;--muted:#5b6275;--line:#e3e6ef;font-size:17px;line-height:1.75;color:var(--ink)}\n.dd-post h2{margin:2.2em 0 .6em;font-size:1.6em;line-height:1.3;scroll-margin-top:90px}\n.dd-post h3{margin:1.6em 0 .5em;font-size:1.22em;scroll-margin-top:90px}\n.dd-post a{color:var(--blue);text-decoration:underline;text-underline-offset:3px}\n.dd-post pre{background:#0f1430;color:#e6e9f5;padding:18px 20px;border-radius:12px;overflow-x:auto;line-height:1.6;border:1px solid #232a52;margin:1.2em 0;font-size:14.5px !important}\n.dd-post pre code{font-size:1em !important;background:none;color:inherit;padding:0;font-family:\"JetBrains Mono\",\"Fira Code\",Consolas,Menlo,monospace;white-space:pre}\n.dd-post :not(pre)>code{background:#eef1fb;color:#2b3a8f;padding:2px 6px;border-radius:5px;font-size:.9em}\n.dd-post .dd-file{display:inline-block;background:#151b3b;color:#c9d1ff;font:600 13px\/1 \"JetBrains Mono\",Consolas,monospace;padding:7px 12px;border-radius:8px 8px 0 0;margin:1em 0 -1.2em;position:relative}\n.dd-post .dd-hero{margin:0 0 1.6em;border-radius:16px;overflow:hidden;box-shadow:0 10px 30px rgba(11,16,32,.25)}\n.dd-post .dd-hero svg{display:block;width:100%;height:auto}\n.dd-post .dd-hero .node{transition:transform .25s,filter .25s;transform-box:fill-box;transform-origin:center;cursor:pointer}\n.dd-post .dd-hero .node:hover{transform:scale(1.08);filter:drop-shadow(0 0 10px #7c5cff)}\n.dd-post .dd-series{display:inline-flex;align-items:center;gap:8px;background:#151b3b;color:#dfe3ff;border-radius:999px;padding:6px 14px;font-size:.88em;font-weight:600;margin:0 0 .8em}\n.dd-post .dd-series span{background:var(--violet);color:#fff;border-radius:999px;padding:2px 10px}\n.dd-post .dd-prereq{font-size:.96em;color:var(--muted);border-left:3px solid var(--line);padding-left:12px;margin:.6em 0 1.2em}\n.dd-post .dd-summary{background:linear-gradient(135deg,#eef3ff,#f4efff);border:1px solid #d6dcf5;border-left:5px solid var(--violet);border-radius:12px;padding:18px 22px;margin:1.4em 0}\n.dd-post .dd-summary strong.lbl{display:block;font-size:1.05em;margin-bottom:6px;color:#3a2fa0}\n.dd-post .dd-summary ul{margin:.3em 0 0 1.1em}\n.dd-post .dd-toc{background:#f8f9fc;border:1px solid var(--line);border-radius:12px;padding:16px 22px;margin:1.4em 0}\n.dd-post .dd-toc ol{margin:.4em 0 0 1.2em;columns:2;column-gap:28px}\n.dd-post .dd-toc li{break-inside:avoid;margin:.15em 0}\n@media(max-width:640px){.dd-post .dd-toc ol{columns:1}}\n.dd-post .dd-tip,.dd-post .dd-note,.dd-post .dd-warn{border-radius:10px;padding:14px 18px;margin:1.3em 0}\n.dd-post .dd-tip{background:#ecfbf3;border-left:4px solid #1f9d61}\n.dd-post .dd-note{background:#eef4ff;border-left:4px solid var(--blue)}\n.dd-post .dd-warn{background:#fff6e8;border-left:4px solid #e08a00}\n.dd-post .dd-cards{display:grid;grid-template-columns:repeat(auto-fit,minmax(210px,1fr));gap:14px;margin:1.3em 0}\n.dd-post .dd-card{border:1px solid var(--line);border-radius:12px;padding:14px 16px;background:#fff;box-shadow:0 2px 8px rgba(20,30,70,.05)}\n.dd-post .dd-card b{display:block;color:#3a2fa0;margin-bottom:4px}\n.dd-post table{width:100%;border-collapse:collapse;margin:1.3em 0;font-size:.95em}\n.dd-post th,.dd-post td{border:1px solid var(--line);padding:10px 12px;text-align:left;vertical-align:top}\n.dd-post th{background:#151b3b;color:#fff}\n.dd-post tr:nth-child(even) td{background:#f8f9fc}\n.dd-post .dd-tablewrap{overflow-x:auto}\n.dd-post figure{margin:1.6em 0;text-align:center}\n.dd-post figure svg{width:100%;height:auto;border-radius:12px}\n.dd-post figcaption{font-size:.9em;color:var(--muted);margin-top:8px}\n.dd-post details{border:1px solid var(--line);border-radius:10px;padding:12px 16px;margin:.7em 0;background:#fff}\n.dd-post details summary{cursor:pointer;font-weight:600}\n.dd-post details[open] summary{margin-bottom:8px;color:#3a2fa0}\n.dd-post .dd-roadmap{border:2px solid #d6dcf5;background:#fbfbff}\n.dd-post .dd-roadmap h4{margin:1em 0 .3em;color:#151b3b;font-size:1em;text-transform:uppercase;letter-spacing:.04em}\n.dd-post .dd-roadmap ol{margin:.2em 0 .6em 1.4em;padding:0}\n.dd-post .dd-roadmap li{margin:.2em 0}\n.dd-post .dd-roadmap .here{background:var(--violet);color:#fff;border-radius:999px;padding:1px 9px;font-size:.8em;font-weight:700;margin-left:6px}\n.dd-post .dd-roadmap .soon{color:#8a90a6;font-size:.82em;margin-left:6px}\n.dd-post .dd-tabs{border:1px solid var(--line);border-radius:12px;padding:6px 16px 16px;margin:1.4em 0;background:#fbfbfe}\n.dd-post .dd-tabs>input{position:absolute;opacity:0;pointer-events:none}\n.dd-post .dd-tabs .labels label{display:inline-block;padding:8px 16px;margin:10px 6px 0 0;border-radius:999px;border:1px solid #cfd5ea;cursor:pointer;font-weight:600;font-size:.95em;background:#fff;transition:background .2s}\n.dd-post .dd-tabs .labels label:hover{border-color:var(--violet)}\n.dd-post .dd-tabs .panel{display:none;margin-top:12px}\n.dd-post .dd-tabs #ti1:checked~.labels label[for=ti1],.dd-post .dd-tabs #ti2:checked~.labels label[for=ti2],.dd-post .dd-tabs #ti3:checked~.labels label[for=ti3],.dd-post .dd-tabs #ti4:checked~.labels label[for=ti4]{background:var(--violet);color:#fff;border-color:var(--violet)}\n.dd-post .dd-tabs #ti1:checked~.p1,.dd-post .dd-tabs #ti2:checked~.p2,.dd-post .dd-tabs #ti3:checked~.p3,.dd-post .dd-tabs #ti4:checked~.p4{display:block}\n.dd-post .dd-tabs #ti1:focus-visible~.labels label[for=ti1],.dd-post .dd-tabs #ti2:focus-visible~.labels label[for=ti2],.dd-post .dd-tabs #ti3:focus-visible~.labels label[for=ti3],.dd-post .dd-tabs #ti4:focus-visible~.labels label[for=ti4]{outline:2px solid var(--blue);outline-offset:2px}\n.dd-post .dd-cta{background:linear-gradient(135deg,#0b1020,#151b3b);color:#e8ebff;border-radius:16px;padding:24px 26px;margin:2em 0;text-align:center}\n.dd-post .dd-cta h3{color:#fff;margin-top:0}\n.dd-post .dd-cta a{color:#a99bff}\n.dd-post .dd-vsc{position:relative;margin:1.5em 0;border-radius:12px;overflow:hidden;background:#1e1e1e;border:1px solid #2b2b2b;box-shadow:0 14px 34px rgba(0,0,0,.28);font-family:\"Segoe UI\",system-ui,sans-serif}\n.dd-post .dd-vsc>input{position:absolute;opacity:0;pointer-events:none}\n.dd-post .dd-vsc-bar{display:flex;align-items:center;gap:12px;background:#323233;color:#cccccc;font-size:12.5px;padding:8px 12px}\n.dd-post .dd-dots{display:inline-flex;gap:7px}.dd-post .dd-dots i{width:12px;height:12px;border-radius:50%;background:#ff5f57;display:block}.dd-post .dd-dots i:nth-child(2){background:#febc2e}.dd-post .dd-dots i:nth-child(3){background:#28c840}\n.dd-post .dd-vsc-title{flex:1;text-align:center;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;padding-right:50px;opacity:.85}\n.dd-post .dd-vsc-tabs{display:flex;align-items:stretch;background:#252526;border-bottom:1px solid #1e1e1e;overflow-x:auto}\n.dd-post .dd-vsc-tabs label{display:flex;align-items:center;gap:7px;padding:9px 16px;color:#969696;font-size:13px;cursor:pointer;background:#2d2d2d;border-right:1px solid #252526;border-top:1px solid transparent;white-space:nowrap;margin:0;transition:color .15s}\n.dd-post .dd-vsc-tabs label:hover{color:#e0e0e0}\n.dd-post .dd-vsc-tabs .ic{font:700 9.5px\/1 Consolas,monospace;padding:3px 4px;border-radius:3px;color:#1e1e1e}\n.dd-post .ic.py{background:#ffd43b}.dd-post .ic.js{background:#f1e05a}.dd-post .ic.sh{background:#89e051}\n.dd-post .dd-vsc-tabs label.run{margin-left:auto;background:transparent;border:0;color:#89d185;font-weight:600;display:none}\n.dd-post .dd-vsc-tabs label.run:hover{color:#b5f0b0;background:#2a2d2e}\n.dd-post .dd-vsc-pane{display:none}\n.dd-post .dd-vsc>.f1:checked~.dd-vsc-tabs .t1,.dd-post .dd-vsc>.f2:checked~.dd-vsc-tabs .t2,.dd-post .dd-vsc>.f3:checked~.dd-vsc-tabs .t3{background:#1e1e1e;color:#ffffff;border-top-color:#3178c6}\n.dd-post .dd-vsc>.f1:checked~.p1,.dd-post .dd-vsc>.f2:checked~.p2,.dd-post .dd-vsc>.f3:checked~.p3{display:block}\n.dd-post .dd-vsc>.f1:checked~.dd-vsc-tabs .run1,.dd-post .dd-vsc>.f2:checked~.dd-vsc-tabs .run2,.dd-post .dd-vsc>.f3:checked~.dd-vsc-tabs .run3{display:flex}\n.dd-post .dd-vsc>.f1:focus-visible~.dd-vsc-tabs .t1,.dd-post .dd-vsc>.f2:focus-visible~.dd-vsc-tabs .t2,.dd-post .dd-vsc>.f3:focus-visible~.dd-vsc-tabs .t3,.dd-post .dd-vsc>input[type=checkbox]:focus-visible~.dd-vsc-tabs .run{outline:2px solid #3178c6;outline-offset:-2px}\n.dd-post .dd-vsc-crumbs{background:#1e1e1e;color:#a9a9a9;font-size:12px;padding:5px 16px 2px}\n.dd-post .dd-vsc pre.dd-vsc-code{background:#1e1e1e;color:#d4d4d4;border:0;border-radius:0;margin:0;padding:8px 0 14px;counter-reset:ln;line-height:1.62;overflow-x:auto}\n.dd-post .dd-vsc pre code{font-family:Consolas,\"JetBrains Mono\",\"Fira Code\",Menlo,monospace;color:inherit;background:none;white-space:pre}\n.dd-post .dd-vsc .l{display:inline-block;min-width:100%;padding-right:18px;box-sizing:border-box}\n.dd-post .dd-vsc .l::before{counter-increment:ln;content:counter(ln);display:inline-block;width:3.2em;padding-right:1.4em;text-align:right;color:#6e7681;user-select:none;-webkit-user-select:none}\n.dd-post .dd-vsc .l:hover{background:#2a2d2e}.dd-post .dd-vsc .l:hover::before{color:#c6c6c6}\n.dd-post .dd-vsc .k,.dd-post .dd-vsc .kn{color:#c586c0}.dd-post .dd-vsc .kc{color:#569cd6}.dd-post .dd-vsc .s{color:#ce9178}.dd-post .dd-vsc .c{color:#6a9955}.dd-post .dd-vsc .m{color:#b5cea8}.dd-post .dd-vsc .nf{color:#dcdcaa}.dd-post .dd-vsc .nc{color:#4ec9b0}.dd-post .dd-vsc .nb{color:#4ec9b0}.dd-post .dd-vsc .nd{color:#dcdcaa}.dd-post .dd-vsc .n{color:#9cdcfe}.dd-post .dd-vsc .o{color:#d4d4d4}.dd-post .dd-vsc .gp{color:#89d185;user-select:none;-webkit-user-select:none}\n.dd-post .dd-vsc-term{display:none;border-top:1px solid #3c3c3c;background:#181818}\n.dd-post .dd-vsc>.r1:checked~.p1 .dd-vsc-term,.dd-post .dd-vsc>.r2:checked~.p2 .dd-vsc-term,.dd-post .dd-vsc>.r3:checked~.p3 .dd-vsc-term{display:block;animation:ddterm .35s ease-out}\n@keyframes ddterm{from{opacity:0;transform:translateY(6px)}to{opacity:1;transform:none}}\n.dd-post .dd-term-head{display:flex;gap:18px;align-items:center;font-size:11px;letter-spacing:.06em;color:#8b8b8b;padding:7px 16px 0}\n.dd-post .dd-term-head span:first-child{color:#e7e7e7;border-bottom:1px solid #e7e7e7;padding-bottom:4px}\n.dd-post .dd-term-head .dd-term-note{margin-left:auto;letter-spacing:0;text-transform:none;color:#d7ba7d;border:0;font-size:11.5px}\n.dd-post .dd-vsc-term pre{background:#181818;color:#cccccc;border:0;margin:0;padding:10px 16px 14px;border-radius:0}\n.dd-post .dd-vsc-status{display:flex;flex-wrap:wrap;gap:4px 14px;background:#007acc;color:#fff;font-size:11.5px;padding:4px 12px}\n.dd-post .dd-vsc-status .sp{flex:1}\n.dd-post .dd-vsc-termonly pre.dd-vsc-code{background:#181818;padding:12px 16px}\n@media(max-width:640px){.dd-post .dd-vsc-title{padding-right:0;text-align:left}.dd-post .dd-vsc-status span:nth-child(n+4){display:none}.dd-post .dd-vsc .l::before{width:2.2em;padding-right:1em}}\n.dd-post .dd-vsc-hint{font-size:.93em;color:var(--muted);margin-top:-.6em}\n.dd-post .dd-next{border:1px dashed var(--violet);border-radius:12px;padding:16px 20px;margin:1.6em 0;background:#f7f4ff}\n<\/style>\n<style>\n.dd-post .ic.sql{background:#e38c00}\n.dd-post .dd-vdb{display:grid;grid-template-columns:repeat(auto-fit,minmax(220px,1fr));gap:14px;margin:1.3em 0}\n.dd-post .dd-vdb div{border-radius:12px;padding:14px 16px;background:#151b3b;color:#e8ebff;font-size:.95em}\n.dd-post .dd-vdb b{display:block;font-size:1.08em;margin-bottom:4px}\n.dd-post .dd-vdb .ch b{color:#ffcf5c}.dd-post .dd-vdb .pg b{color:#7fb3ff}.dd-post .dd-vdb .pc b{color:#a99bff}\n.dd-post .dd-vdb small{display:block;color:#aab4e8;margin-top:6px}\n<\/style>\n\n<div class=\"dd-hero\">\n<svg viewBox=\"0 0 1200 520\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" role=\"img\" aria-label=\"Generative AI series Part 10 banner: an embedding vector is stored in a vector database that holds Chroma, pgvector and Pinecone, and a search returns the nearest matching documents\">\n<defs>\n<linearGradient id=\"ddbg\" x1=\"0\" y1=\"0\" x2=\"1\" y2=\"1\"><stop offset=\"0\" stop-color=\"#0b1020\"\/><stop offset=\"1\" stop-color=\"#151b3b\"\/><\/linearGradient>\n<linearGradient id=\"ddac\" x1=\"0\" y1=\"0\" x2=\"1\" y2=\"0\"><stop offset=\"0\" stop-color=\"#3178c6\"\/><stop offset=\"1\" stop-color=\"#7c5cff\"\/><\/linearGradient>\n<radialGradient id=\"ddglow\" cx=\".5\" cy=\".5\" r=\".5\"><stop offset=\"0\" stop-color=\"#7c5cff\" stop-opacity=\".45\"\/><stop offset=\"1\" stop-color=\"#7c5cff\" stop-opacity=\"0\"\/><\/radialGradient>\n<\/defs>\n<rect x=\"0\" y=\"-60\" width=\"1200\" height=\"640\" fill=\"url(#ddbg)\"\/>\n<circle cx=\"1000\" cy=\"110\" r=\"250\" fill=\"url(#ddglow)\"\/>\n<g opacity=\".12\" stroke=\"#9fb2ff\"><path d=\"M0 100H1200M0 200H1200M0 300H1200M0 400H1200M200 0V520M400 0V520M600 0V520M800 0V520M1000 0V520\"\/><\/g>\n<rect x=\"60\" y=\"46\" width=\"140\" height=\"38\" rx=\"19\" fill=\"url(#ddac)\"\/>\n<text x=\"130\" y=\"71\" text-anchor=\"middle\" font-family=\"Segoe UI,Arial,sans-serif\" font-size=\"18\" font-weight=\"700\" fill=\"#fff\">PART 10<\/text>\n<text x=\"216\" y=\"71\" font-family=\"Segoe UI,Arial,sans-serif\" font-size=\"18\" fill=\"#aab4e8\">Generative AI Series \u00b7 DevDojo<\/text>\n<text x=\"60\" y=\"148\" font-family=\"Segoe UI,Arial,sans-serif\" font-size=\"54\" font-weight=\"800\" fill=\"#ffffff\">Vector Databases<\/text>\n<text x=\"60\" y=\"206\" font-family=\"Segoe UI,Arial,sans-serif\" font-size=\"44\" font-weight=\"800\" fill=\"url(#ddac)\">pgvector, Chroma and Pinecone<\/text>\n<text x=\"60\" y=\"248\" font-family=\"Segoe UI,Arial,sans-serif\" font-size=\"23\" fill=\"#c9d1ff\">Store embeddings \u00b7 fast similarity search \u00b7 metadata filters<\/text>\n<g font-family=\"Segoe UI,Arial,sans-serif\">\n<g class=\"node\"><rect x=\"60\" y=\"300\" width=\"270\" height=\"170\" rx=\"16\" fill=\"#1b2250\" stroke=\"#3178c6\" stroke-width=\"2\"\/><text x=\"195\" y=\"330\" text-anchor=\"middle\" font-size=\"15\" fill=\"#aac8f0\">Question<\/text><text x=\"195\" y=\"368\" text-anchor=\"middle\" font-size=\"18\" fill=\"#e8ebff\">&#8220;I forgot my login&#8221;<\/text><text x=\"195\" y=\"410\" text-anchor=\"middle\" font-family=\"Consolas,monospace\" font-size=\"16\" fill=\"#b5cea8\">[0.70, 0.40, 0.10]<\/text><text x=\"195\" y=\"446\" text-anchor=\"middle\" font-size=\"13\" fill=\"#8f9acc\">query embedding<\/text><\/g>\n<g class=\"node\"><rect x=\"455\" y=\"290\" width=\"290\" height=\"190\" rx=\"20\" fill=\"#0b1020\" stroke=\"#7c5cff\" stroke-width=\"2.5\"\/><text x=\"600\" y=\"322\" text-anchor=\"middle\" font-size=\"22\" font-weight=\"800\" fill=\"#fff\">Vector database<\/text>\n<rect x=\"478\" y=\"340\" width=\"244\" height=\"34\" rx=\"9\" fill=\"#2a2410\" stroke=\"#ffcf5c\"\/><text x=\"600\" y=\"363\" text-anchor=\"middle\" font-size=\"15\" fill=\"#ffcf5c\">Chroma \u00b7 local and simple<\/text>\n<rect x=\"478\" y=\"382\" width=\"244\" height=\"34\" rx=\"9\" fill=\"#102240\" stroke=\"#7fb3ff\"\/><text x=\"600\" y=\"405\" text-anchor=\"middle\" font-size=\"15\" fill=\"#7fb3ff\">pgvector \u00b7 inside PostgreSQL<\/text>\n<rect x=\"478\" y=\"424\" width=\"244\" height=\"34\" rx=\"9\" fill=\"#1e1640\" stroke=\"#a99bff\"\/><text x=\"600\" y=\"447\" text-anchor=\"middle\" font-size=\"15\" fill=\"#a99bff\">Pinecone \u00b7 managed cloud<\/text><\/g>\n<g class=\"node\"><rect x=\"870\" y=\"300\" width=\"270\" height=\"170\" rx=\"16\" fill=\"#1b2250\" stroke=\"#61dafb\" stroke-width=\"2\"\/><text x=\"1005\" y=\"330\" text-anchor=\"middle\" font-size=\"15\" fill=\"#a8ecfb\">Top matches<\/text><text x=\"890\" y=\"368\" font-size=\"16\" fill=\"#e8ebff\">0.94  Change my email<\/text><text x=\"890\" y=\"400\" font-size=\"16\" fill=\"#e8ebff\">0.91  Reset password<\/text><text x=\"890\" y=\"440\" font-size=\"13\" fill=\"#8f9acc\">nearest neighbours<\/text><\/g>\n<\/g>\n<path id=\"ddf1\" d=\"M330 385 C 390 385, 395 385, 455 385\" fill=\"none\" stroke=\"url(#ddac)\" stroke-width=\"3\" stroke-dasharray=\"8 8\" opacity=\".8\"\/>\n<path id=\"ddf2\" d=\"M745 385 C 805 385, 810 385, 870 385\" fill=\"none\" stroke=\"url(#ddac)\" stroke-width=\"3\" stroke-dasharray=\"8 8\" opacity=\".8\"\/>\n<circle r=\"6\" fill=\"#61dafb\"><animateMotion dur=\"1.4s\" repeatCount=\"indefinite\"><mpath href=\"#ddf1\"\/><\/animateMotion><\/circle>\n<circle r=\"5\" fill=\"#ffffff\"><animateMotion dur=\"1.4s\" begin=\".7s\" repeatCount=\"indefinite\"><mpath href=\"#ddf1\"\/><\/animateMotion><\/circle>\n<circle r=\"6\" fill=\"#7c5cff\"><animateMotion dur=\"1.4s\" begin=\".35s\" repeatCount=\"indefinite\"><mpath href=\"#ddf2\"\/><\/animateMotion><\/circle>\n<circle r=\"5\" fill=\"#89e051\"><animateMotion dur=\"1.4s\" begin=\"1.05s\" repeatCount=\"indefinite\"><mpath href=\"#ddf2\"\/><\/animateMotion><\/circle>\n<text x=\"60\" y=\"510\" font-family=\"Segoe UI,Arial,sans-serif\" font-size=\"16\" fill=\"#7f89b5\">devdojo.co.in \u00b7 Beginner friendly \u00b7 Python + Node.js + SQL examples<\/text>\n<\/svg>\n<\/div>\n\n<div class=\"dd-series\">Series: Generative AI <span>Part 10 of 30<\/span><\/div>\n<p class=\"dd-prereq\"><strong>What you should know first:<\/strong> read <a href=\"https:\/\/devdojo.co.in\/?p=306\">Part 9: Embeddings Explained<\/a> (what a vector is and how cosine similarity works). Basic Python or Node.js is enough. Docker is helpful for the PostgreSQL example, but not required.<\/p>\n\n<p>In Part 9 we turned text into embeddings and searched them with a simple loop. That works for 100 documents, but what about 1 million? You need a place to <strong>store<\/strong> vectors and <strong>search<\/strong> them fast. That place is a <strong>vector database<\/strong>. In this part you will learn what a vector database is, how indexes like HNSW make search fast, and how to use the three most popular options: <strong>Chroma<\/strong> (local and simple), <strong>pgvector<\/strong> (vectors inside PostgreSQL) and <strong>Pinecone<\/strong> (fully managed cloud). Every example is runnable, and the Chroma and pgvector outputs below are from real runs.<\/p>\n\n<div class=\"dd-summary\">\n<strong class=\"lbl\">Quick Summary<\/strong>\n<ul>\n<li>A <strong>vector database<\/strong> stores embeddings (plus the original text and metadata) and finds the <strong>nearest<\/strong> vectors to a question very quickly.<\/li>\n<li>It uses an <strong>approximate nearest neighbour<\/strong> (ANN) index such as <strong>HNSW<\/strong>, so it does not compare the question with every row.<\/li>\n<li><strong>Chroma<\/strong>: <code>pip install chromadb<\/code>, runs inside your app, perfect for learning and prototypes.<\/li>\n<li><strong>pgvector<\/strong>: adds a <code>vector<\/code> column type to PostgreSQL. Search with <code>ORDER BY embedding &lt;=&gt; query LIMIT 5<\/code>.<\/li>\n<li><strong>Pinecone<\/strong>: a managed, serverless cloud service. No servers to run, pay for what you use.<\/li>\n<li>Use <strong>metadata filters<\/strong> (topic, user, language) together with vector search, and always use the <strong>same embedding model<\/strong> for documents and questions.<\/li>\n<\/ul>\n<\/div>\n\n<nav class=\"dd-toc\" aria-label=\"Table of contents\">\n<strong>In this guide<\/strong>\n<ol>\n<li><a href=\"#what-is-vector-database\">What is a vector database?<\/a><\/li>\n<li><a href=\"#how-it-works\">How vector search works<\/a><\/li>\n<li><a href=\"#indexes\">Indexes: HNSW and IVFFlat<\/a><\/li>\n<li><a href=\"#metrics\">Distance metrics<\/a><\/li>\n<li><a href=\"#setup\">Setup<\/a><\/li>\n<li><a href=\"#chroma\">Option 1: Chroma<\/a><\/li>\n<li><a href=\"#pgvector\">Option 2: pgvector<\/a><\/li>\n<li><a href=\"#pinecone\">Option 3: Pinecone<\/a><\/li>\n<li><a href=\"#real-embeddings\">Using real embeddings<\/a><\/li>\n<li><a href=\"#choose\">Which one should you choose?<\/a><\/li>\n<li><a href=\"#errors\">Common errors and fixes<\/a><\/li>\n<li><a href=\"#best-practices\">Best practices<\/a><\/li>\n<li><a href=\"#practice\">Practice task<\/a><\/li>\n<li><a href=\"#faq\">FAQ<\/a><\/li>\n<\/ol>\n<\/nav>\n\n<details class=\"dd-roadmap\">\n<summary>Full Generative AI roadmap (30 parts)<\/summary>\n<h4>Beginner<\/h4>\n<ol start=\"1\">\n<li><a href=\"https:\/\/devdojo.co.in\/?p=215\">What Is Generative AI and How Do LLMs Work?<\/a><\/li>\n<li><a href=\"https:\/\/devdojo.co.in\/?p=219\">Tokens, Context Windows and Model Parameters<\/a><\/li>\n<li><a href=\"https:\/\/devdojo.co.in\/?p=223\">Your First LLM API Calls in Python and Node.js (OpenAI, Anthropic, Gemini)<\/a><\/li>\n<li><a href=\"https:\/\/devdojo.co.in\/?p=240\">Prompt Engineering Basics: Roles, Instructions and Examples<\/a><\/li>\n<li><a href=\"https:\/\/devdojo.co.in\/?p=244\">Temperature, Top-p and Controlling Model Output<\/a><\/li>\n<li><a href=\"https:\/\/devdojo.co.in\/?p=281\">Run LLMs Locally with Ollama<\/a><\/li>\n<li><a href=\"https:\/\/devdojo.co.in\/?p=284\">Streaming Responses and Building a Simple Chat UI<\/a><\/li>\n<li><a href=\"https:\/\/devdojo.co.in\/?p=303\">Structured Outputs: Getting Reliable JSON from LLMs<\/a><\/li>\n<\/ol>\n<h4>Intermediate<\/h4>\n<ol start=\"9\">\n<li><a href=\"https:\/\/devdojo.co.in\/?p=306\">Embeddings Explained: Turning Text into Vectors<\/a><\/li>\n<li>Vector Databases: pgvector, Chroma and Pinecone <span class=\"here\">You are here<\/span><\/li>\n<li>RAG Fundamentals: Retrieval-Augmented Generation <span class=\"soon\">Coming soon<\/span><\/li>\n<li>Document Loading and Chunking Strategies <span class=\"soon\">Coming soon<\/span><\/li>\n<li>Better RAG: Hybrid Search, Re-ranking and Query Rewriting <span class=\"soon\">Coming soon<\/span><\/li>\n<li>Function Calling and Tool Use <span class=\"soon\">Coming soon<\/span><\/li>\n<li>Conversation Memory and Long Context Management <span class=\"soon\">Coming soon<\/span><\/li>\n<li>Multimodal AI: Vision, Images and Audio Inputs <span class=\"soon\">Coming soon<\/span><\/li>\n<li>How Image Generation Works: Diffusion Models Basics <span class=\"soon\">Coming soon<\/span><\/li>\n<li>LangChain vs LlamaIndex: When to Use a Framework <span class=\"soon\">Coming soon<\/span><\/li>\n<li>Testing LLM Apps: Evals, Metrics and Test Sets <span class=\"soon\">Coming soon<\/span><\/li>\n<li>Cutting Cost and Latency: Caching, Batching and Model Choice <span class=\"soon\">Coming soon<\/span><\/li>\n<\/ol>\n<h4>Advanced<\/h4>\n<ol start=\"21\">\n<li>Fine-Tuning vs Prompting vs RAG: Choosing the Right Tool <span class=\"soon\">Coming soon<\/span><\/li>\n<li>Fine-Tuning an Open Model with LoRA <span class=\"soon\">Coming soon<\/span><\/li>\n<li>Transformers Deep Dive: Attention Explained Simply <span class=\"soon\">Coming soon<\/span><\/li>\n<li>Reasoning Models and Thinking Time <span class=\"soon\">Coming soon<\/span><\/li>\n<li>Guardrails, Safety and Prompt Injection Defence <span class=\"soon\">Coming soon<\/span><\/li>\n<li>Monitoring and Tracing LLM Apps in Production <span class=\"soon\">Coming soon<\/span><\/li>\n<li>Serving Open Models: vLLM, Quantization and GPUs <span class=\"soon\">Coming soon<\/span><\/li>\n<li>Building a Production GenAI App End to End <span class=\"soon\">Coming soon<\/span><\/li>\n<li>Responsible AI: Privacy, Licensing and Bias <span class=\"soon\">Coming soon<\/span><\/li>\n<li>Final Project: Build Your Own AI Knowledge Assistant <span class=\"soon\">Coming soon<\/span><\/li>\n<\/ol>\n<\/details>\n<\/div>\n\n\n\n<div class=\"dd-post\">\n<h2 id=\"what-is-vector-database\">What Is a Vector Database?<\/h2>\n<p>A normal database answers questions like &#8220;give me the order with id 42&#8221; or &#8220;all users from Pune&#8221;. It matches <em>exact<\/em> values. A <strong>vector database<\/strong> answers a different question: &#8220;which stored items are <em>most similar in meaning<\/em> to this one?&#8221;<\/p>\n<p>Each row in a vector database usually has four things:<\/p>\n<div class=\"dd-cards\">\n<div class=\"dd-card\"><b>id<\/b>A unique key, like <code>\"d1\"<\/code> or a UUID.<\/div>\n<div class=\"dd-card\"><b>vector<\/b>The embedding, for example 1,536 numbers from <code>text-embedding-3-small<\/code>.<\/div>\n<div class=\"dd-card\"><b>document<\/b>The original text (or a link to it), so you can show or send it to an LLM.<\/div>\n<div class=\"dd-card\"><b>metadata<\/b>Extra fields like <code>topic<\/code>, <code>user_id<\/code>, <code>language<\/code> or <code>created_at<\/code> for filtering.<\/div>\n<\/div>\n<p>This is the engine behind semantic search, &#8220;related articles&#8221;, recommendation systems and, most importantly for this series, <strong>RAG<\/strong> (Retrieval-Augmented Generation), which we build in Part 11. If you want a sneak peek, our standalone <a href=\"https:\/\/devdojo.co.in\/?p=198\">RAG tutorial with Python and pgvector<\/a> shows the full flow.<\/p>\n\n<h2 id=\"how-it-works\">How Vector Search Works<\/h2>\n<p>Every vector database, from a tiny local Chroma file to a huge Pinecone index, follows the same two steps:<\/p>\n<figure>\n<svg viewBox=\"0 0 900 260\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" role=\"img\" aria-label=\"Diagram of the two flows in a vector database: indexing documents once, and searching for every question\">\n<rect width=\"900\" height=\"260\" fill=\"#0b1020\"\/>\n<defs><marker id=\"ar10\" viewBox=\"0 0 10 10\" refX=\"8\" refY=\"5\" markerWidth=\"7\" markerHeight=\"7\" orient=\"auto\"><path d=\"M0 0L10 5L0 10z\" fill=\"#7c5cff\"\/><\/marker><\/defs>\n<g font-family=\"Segoe UI,Arial,sans-serif\" font-size=\"15\">\n<text x=\"30\" y=\"40\" font-size=\"16\" font-weight=\"700\" fill=\"#ffcf5c\">1. Indexing (once)<\/text>\n<rect x=\"30\" y=\"58\" width=\"160\" height=\"56\" rx=\"12\" fill=\"#1b2250\" stroke=\"#3178c6\"\/><text x=\"110\" y=\"91\" text-anchor=\"middle\" fill=\"#fff\">Your documents<\/text>\n<rect x=\"250\" y=\"58\" width=\"160\" height=\"56\" rx=\"12\" fill=\"#1b2250\" stroke=\"#3178c6\"\/><text x=\"330\" y=\"91\" text-anchor=\"middle\" fill=\"#fff\">Embedding model<\/text>\n<rect x=\"470\" y=\"58\" width=\"190\" height=\"56\" rx=\"12\" fill=\"#1b2250\" stroke=\"#3178c6\"\/><text x=\"565\" y=\"84\" text-anchor=\"middle\" fill=\"#fff\">id + vector<\/text><text x=\"565\" y=\"103\" text-anchor=\"middle\" font-size=\"12\" fill=\"#aab4e8\">+ text + metadata<\/text>\n<rect x=\"720\" y=\"88\" width=\"150\" height=\"110\" rx=\"16\" fill=\"#7c5cff\"\/><text x=\"795\" y=\"138\" text-anchor=\"middle\" font-weight=\"700\" fill=\"#fff\">Vector<\/text><text x=\"795\" y=\"158\" text-anchor=\"middle\" font-weight=\"700\" fill=\"#fff\">database<\/text>\n<path d=\"M192 86H246M412 86H466M662 86H716\" stroke=\"#7c5cff\" stroke-width=\"3\" marker-end=\"url(#ar10)\"\/>\n<text x=\"30\" y=\"160\" font-size=\"16\" font-weight=\"700\" fill=\"#61dafb\">2. Searching (every question)<\/text>\n<rect x=\"30\" y=\"178\" width=\"160\" height=\"56\" rx=\"12\" fill=\"#1b2250\" stroke=\"#61dafb\"\/><text x=\"110\" y=\"211\" text-anchor=\"middle\" fill=\"#fff\">User question<\/text>\n<rect x=\"250\" y=\"178\" width=\"160\" height=\"56\" rx=\"12\" fill=\"#1b2250\" stroke=\"#61dafb\"\/><text x=\"330\" y=\"211\" text-anchor=\"middle\" fill=\"#fff\">Same model<\/text>\n<rect x=\"470\" y=\"178\" width=\"190\" height=\"56\" rx=\"12\" fill=\"#1b2250\" stroke=\"#61dafb\"\/><text x=\"565\" y=\"204\" text-anchor=\"middle\" fill=\"#fff\">Query vector<\/text><text x=\"565\" y=\"223\" text-anchor=\"middle\" font-size=\"12\" fill=\"#aab4e8\">top_k = 3, filter<\/text>\n<path d=\"M192 206H246M412 206H466M662 206H716\" stroke=\"#61dafb\" stroke-width=\"3\" marker-end=\"url(#ar10)\"\/>\n<\/g>\n<\/svg>\n<figcaption>Every vector database works the same way: embed and store your documents once, then embed each question with the same model and ask for the nearest vectors.<\/figcaption>\n<\/figure>\n<ol>\n<li><strong>Indexing (once):<\/strong> split your content into pieces, create an embedding for each piece, and store <em>id + vector + text + metadata<\/em>.<\/li>\n<li><strong>Searching (every question):<\/strong> embed the user&#8217;s question with the <em>same<\/em> model, then ask the database for the <code>top_k<\/code> nearest vectors, optionally with a filter like <code>topic = \"payments\"<\/code>.<\/li>\n<\/ol>\n<div class=\"dd-note\"><strong>Remember:<\/strong> the database never &#8220;understands&#8221; text. It only compares numbers. The meaning comes from the embedding model, which is why you must use the same model for documents and questions.<\/div>\n\n<h2 id=\"indexes\">Indexes: HNSW and IVFFlat (Why Search Is Fast)<\/h2>\n<p>The simple way to search is to compare the question with every stored vector. This is called <strong>exact<\/strong> or <strong>brute-force<\/strong> search. It is 100% accurate, but it gets slow when you have millions of rows.<\/p>\n<p>Vector databases solve this with an <strong>approximate nearest neighbour (ANN) index<\/strong>. It gives you almost the same results (usually 95&#8211;99% of the true top matches) in a tiny fraction of the time.<\/p>\n<figure>\n<svg viewBox=\"0 0 900 340\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" role=\"img\" aria-label=\"Diagram comparing exact search, which checks every vector, with an HNSW index, which jumps through a few layers of linked points to reach the nearest neighbours quickly\">\n<rect width=\"900\" height=\"340\" fill=\"#0b1020\"\/>\n<g font-family=\"Segoe UI,Arial,sans-serif\">\n<text x=\"225\" y=\"36\" text-anchor=\"middle\" font-size=\"19\" font-weight=\"700\" fill=\"#fff\">Exact search (no index)<\/text>\n<text x=\"225\" y=\"60\" text-anchor=\"middle\" font-size=\"14\" fill=\"#aab4e8\">compare the question with every vector<\/text>\n<g fill=\"#3a4580\">\n<circle cx=\"90\" cy=\"110\" r=\"9\"\/><circle cx=\"150\" cy=\"150\" r=\"9\"\/><circle cx=\"210\" cy=\"105\" r=\"9\"\/><circle cx=\"270\" cy=\"160\" r=\"9\"\/><circle cx=\"330\" cy=\"115\" r=\"9\"\/><circle cx=\"380\" cy=\"175\" r=\"9\"\/>\n<circle cx=\"100\" cy=\"220\" r=\"9\"\/><circle cx=\"170\" cy=\"250\" r=\"9\"\/><circle cx=\"240\" cy=\"215\" r=\"9\"\/><circle cx=\"300\" cy=\"260\" r=\"9\"\/><circle cx=\"360\" cy=\"230\" r=\"9\"\/>\n<\/g>\n<circle cx=\"225\" cy=\"190\" r=\"11\" fill=\"#61dafb\"\/>\n<g stroke=\"#61dafb\" stroke-opacity=\".35\" stroke-width=\"1.5\"><path d=\"M225 190L90 110M225 190L150 150M225 190L210 105M225 190L270 160M225 190L330 115M225 190L380 175M225 190L100 220M225 190L170 250M225 190L240 215M225 190L300 260M225 190L360 230\"\/><\/g>\n<text x=\"225\" y=\"305\" text-anchor=\"middle\" font-size=\"15\" fill=\"#ffb4a8\">1 million vectors = 1 million comparisons<\/text>\n<path d=\"M450 30V320\" stroke=\"#2a3266\" stroke-width=\"2\"\/>\n<text x=\"675\" y=\"36\" text-anchor=\"middle\" font-size=\"19\" font-weight=\"700\" fill=\"#fff\">HNSW index (approximate)<\/text>\n<text x=\"675\" y=\"60\" text-anchor=\"middle\" font-size=\"14\" fill=\"#aab4e8\">hop through a graph of linked points<\/text>\n<rect x=\"500\" y=\"80\" width=\"350\" height=\"50\" rx=\"10\" fill=\"#151b3b\"\/><text x=\"512\" y=\"100\" font-size=\"12\" fill=\"#8f9acc\">Layer 2<\/text>\n<rect x=\"500\" y=\"145\" width=\"350\" height=\"50\" rx=\"10\" fill=\"#151b3b\"\/><text x=\"512\" y=\"165\" font-size=\"12\" fill=\"#8f9acc\">Layer 1<\/text>\n<rect x=\"500\" y=\"210\" width=\"350\" height=\"70\" rx=\"10\" fill=\"#151b3b\"\/><text x=\"512\" y=\"230\" font-size=\"12\" fill=\"#8f9acc\">Layer 0 (all points)<\/text>\n<g fill=\"#3a4580\"><circle cx=\"600\" cy=\"110\" r=\"8\"\/><circle cx=\"780\" cy=\"110\" r=\"8\"\/><circle cx=\"580\" cy=\"172\" r=\"8\"\/><circle cx=\"680\" cy=\"172\" r=\"8\"\/><circle cx=\"790\" cy=\"172\" r=\"8\"\/>\n<circle cx=\"560\" cy=\"250\" r=\"8\"\/><circle cx=\"620\" cy=\"262\" r=\"8\"\/><circle cx=\"680\" cy=\"245\" r=\"8\"\/><circle cx=\"740\" cy=\"262\" r=\"8\"\/><circle cx=\"800\" cy=\"248\" r=\"8\"\/><\/g>\n<path d=\"M600 110L780 110M780 110L790 172M790 172L680 172M680 172L680 245M680 245L740 262\" stroke=\"#7c5cff\" stroke-width=\"3\" fill=\"none\"\/>\n<circle cx=\"740\" cy=\"262\" r=\"11\" fill=\"#89e051\"\/>\n<text x=\"675\" y=\"305\" text-anchor=\"middle\" font-size=\"15\" fill=\"#b8f0a0\">only a few hops = milliseconds<\/text>\n<\/g>\n<\/svg>\n<figcaption>Without an index, the database checks every vector. An HNSW index links vectors into layers, so a search jumps quickly to the right neighbourhood.<\/figcaption>\n<\/figure>\n<div class=\"dd-tablewrap\"><table>\n<thead><tr><th>Index<\/th><th>How it works (simple)<\/th><th>Good for<\/th><th>Trade-off<\/th><\/tr><\/thead>\n<tbody>\n<tr><td><strong>None (exact)<\/strong><\/td><td>Checks every vector<\/td><td>Under ~10,000 rows, tests<\/td><td>Slow on big data<\/td><\/tr>\n<tr><td><strong>HNSW<\/strong><\/td><td>A layered graph of &#8220;neighbour&#8221; links; search hops toward the closest point<\/td><td>Most apps; fast and accurate<\/td><td>Uses more memory, slower to build<\/td><\/tr>\n<tr><td><strong>IVFFlat<\/strong><\/td><td>Groups vectors into clusters, then searches only the closest clusters<\/td><td>Large data with less memory<\/td><td>Build it <em>after<\/em> loading data; tune <code>lists<\/code>\/<code>probes<\/code><\/td><\/tr>\n<\/tbody><\/table><\/div>\n<p>Chroma and Pinecone choose and manage the index for you. In pgvector you create it yourself with one SQL line, as you will see below.<\/p>\n\n<h2 id=\"metrics\">Distance Metrics: Cosine, Euclidean and Dot Product<\/h2>\n<p>A vector database needs to know <em>how<\/em> to measure &#8220;closeness&#8221;. You pick one metric when you create the collection or index:<\/p>\n<div class=\"dd-tablewrap\"><table>\n<thead><tr><th>Metric<\/th><th>Meaning<\/th><th>pgvector operator<\/th><th>When to use<\/th><\/tr><\/thead>\n<tbody>\n<tr><td><strong>Cosine<\/strong><\/td><td>Angle between vectors (direction only)<\/td><td><code>&lt;=&gt;<\/code><\/td><td>Default choice for text embeddings<\/td><\/tr>\n<tr><td><strong>Euclidean (L2)<\/strong><\/td><td>Straight-line distance<\/td><td><code>&lt;-&gt;<\/code><\/td><td>Images and some older models<\/td><\/tr>\n<tr><td><strong>Inner product (dot)<\/strong><\/td><td>Dot product; equals cosine when vectors are normalised<\/td><td><code>&lt;#&gt;<\/code> (returns the negative)<\/td><td>Normalised embeddings, max speed<\/td><\/tr>\n<\/tbody><\/table><\/div>\n<p>Most databases return a <strong>distance<\/strong> (smaller is closer). For cosine, <code>similarity = 1 - distance<\/code>. You will see this conversion in every example.<\/p>\n\n<h2 id=\"setup\">Setup<\/h2>\n<p>Create a folder called <code>devdojo-vectordb<\/code> and install the packages. You only need the ones for the database you want to try.<\/p>\n<div class=\"dd-vsc dd-vsc-termonly\" role=\"group\" aria-label=\"Terminal: Terminal \u2014 devdojo-vectordb\">\n<div class=\"dd-vsc-bar\"><span class=\"dd-dots\"><i><\/i><i><\/i><i><\/i><\/span><span class=\"dd-vsc-title\">Terminal \u2014 devdojo-vectordb<\/span><\/div>\n<pre class=\"dd-vsc-code\"><code><span class=\"l\"><span class=\"c\"># Python packages for this part<\/span><\/span>\n<span class=\"l\"><span class=\"gp\">$<\/span> pip install chromadb \"psycopg[binary]\" pgvector numpy pinecone<\/span>\n<span class=\"l\"><span class=\"c\"># Node.js packages<\/span><\/span>\n<span class=\"l\"><span class=\"gp\">$<\/span> npm install pg pgvector<\/span>\n<span class=\"l\"><span class=\"c\"># PostgreSQL 17 with pgvector already installed (needs Docker)<\/span><\/span>\n<span class=\"l\"><span class=\"gp\">$<\/span> docker run -d --name pgvector -e POSTGRES_PASSWORD=postgres -p 5432:5432 pgvector\/pgvector:pg17<\/span><\/code><\/pre>\n<\/div>\n<p>To keep the examples free and runnable without an API key, we use tiny 3-number &#8220;embeddings&#8221;. Think of the numbers as <em>[account, payments, delivery]<\/em>. Real models give 384 to 3,072 numbers, but the code is exactly the same. Later we swap in real embeddings.<\/p>\n<\/div>\n\n\n\n<div class=\"dd-post\">\n<h2 id=\"chroma\">Option 1: Chroma &#8211; The Easiest Vector Database<\/h2>\n<p><a href=\"https:\/\/docs.trychroma.com\/\" rel=\"noopener\" target=\"_blank\">Chroma<\/a> is an open-source vector database that runs inside your Python app, like SQLite. No server, no account. <code>PersistentClient<\/code> saves everything to a folder so your data survives restarts.<\/p>\n<div class=\"dd-vsc\" role=\"group\" aria-label=\"Code editor: chroma_demo.py, data.py\">\n<input type=\"radio\" name=\"v1\" id=\"v1f1\" class=\"f1\" checked>\n<input type=\"radio\" name=\"v1\" id=\"v1f2\" class=\"f2\">\n<input type=\"checkbox\" id=\"v1r1\" class=\"r1\">\n<div class=\"dd-vsc-bar\"><span class=\"dd-dots\"><i><\/i><i><\/i><i><\/i><\/span><span class=\"dd-vsc-title\">chroma_demo.py \u2014 devdojo-vectordb \u2014 Visual Studio Code<\/span><\/div>\n<div class=\"dd-vsc-tabs\">\n<label for=\"v1f1\" class=\"t1\"><b class=\"ic py\">PY<\/b>chroma_demo.py<\/label>\n<label for=\"v1f2\" class=\"t2\"><b class=\"ic py\">PY<\/b>data.py<\/label>\n<label for=\"v1r1\" class=\"run run1\" title=\"Show the output in the terminal\">\u25b6 Run<\/label>\n<\/div>\n<div class=\"dd-vsc-pane p1\">\n<div class=\"dd-vsc-crumbs\">devdojo-vectordb \u203a chroma_demo.py<\/div>\n<pre class=\"dd-vsc-code\"><code><span class=\"l\"><span class=\"kn\">import<\/span> <span class=\"n\">chromadb<\/span><\/span>\n<span class=\"l\"><span class=\"kn\">from<\/span> <span class=\"n\">data<\/span> <span class=\"kn\">import<\/span> <span class=\"n\">DOCS<\/span><\/span>\n<span class=\"l\"><\/span>\n<span class=\"l\"><span class=\"c\"># Saves data in .\/chroma_db so it survives restarts<\/span><\/span>\n<span class=\"l\"><span class=\"n\">client<\/span> = <span class=\"n\">chromadb<\/span>.<span class=\"n\">PersistentClient<\/span>(<span class=\"n\">path<\/span>=<span class=\"s\">\".\/chroma_db\"<\/span>)<\/span>\n<span class=\"l\"><\/span>\n<span class=\"l\"><span class=\"n\">collection<\/span> = <span class=\"n\">client<\/span>.<span class=\"n\">get_or_create_collection<\/span>(<\/span>\n<span class=\"l\">    <span class=\"n\">name<\/span>=<span class=\"s\">\"support_faq\"<\/span>,<\/span>\n<span class=\"l\">    <span class=\"n\">configuration<\/span>={<span class=\"s\">\"hnsw\"<\/span>: {<span class=\"s\">\"space\"<\/span>: <span class=\"s\">\"cosine\"<\/span>}},<\/span>\n<span class=\"l\">)<\/span>\n<span class=\"l\"><\/span>\n<span class=\"l\"><span class=\"n\">collection<\/span>.<span class=\"n\">upsert<\/span>(<\/span>\n<span class=\"l\">    <span class=\"n\">ids<\/span>=[<span class=\"n\">d<\/span>[<span class=\"m\">0<\/span>] <span class=\"k\">for<\/span> <span class=\"n\">d<\/span> in <span class=\"n\">DOCS<\/span>],<\/span>\n<span class=\"l\">    <span class=\"n\">documents<\/span>=[<span class=\"n\">d<\/span>[<span class=\"m\">1<\/span>] <span class=\"k\">for<\/span> <span class=\"n\">d<\/span> in <span class=\"n\">DOCS<\/span>],<\/span>\n<span class=\"l\">    <span class=\"n\">embeddings<\/span>=[<span class=\"n\">d<\/span>[<span class=\"m\">2<\/span>] <span class=\"k\">for<\/span> <span class=\"n\">d<\/span> in <span class=\"n\">DOCS<\/span>],<\/span>\n<span class=\"l\">    <span class=\"n\">metadatas<\/span>=[{<span class=\"s\">\"topic\"<\/span>: <span class=\"n\">d<\/span>[<span class=\"m\">3<\/span>]} <span class=\"k\">for<\/span> <span class=\"n\">d<\/span> in <span class=\"n\">DOCS<\/span>],<\/span>\n<span class=\"l\">)<\/span>\n<span class=\"l\"><span class=\"nb\">print<\/span>(<span class=\"s\">\"Stored:\"<\/span>, <span class=\"n\">collection<\/span>.<span class=\"n\">count<\/span>(), <span class=\"s\">\"documents\"<\/span>)<\/span>\n<span class=\"l\"><\/span>\n<span class=\"l\"><span class=\"c\"># Question: \"I forgot my login\" (its embedding)<\/span><\/span>\n<span class=\"l\"><span class=\"n\">results<\/span> = <span class=\"n\">collection<\/span>.<span class=\"n\">query<\/span>(<\/span>\n<span class=\"l\">    <span class=\"n\">query_embeddings<\/span>=[[<span class=\"m\">0.70<\/span>, <span class=\"m\">0.40<\/span>, <span class=\"m\">0.10<\/span>]],<\/span>\n<span class=\"l\">    <span class=\"n\">n_results<\/span>=<span class=\"m\">2<\/span>,<\/span>\n<span class=\"l\">)<\/span>\n<span class=\"l\"><span class=\"k\">for<\/span> <span class=\"n\">doc<\/span>, <span class=\"n\">dist<\/span> in <span class=\"nb\">zip<\/span>(<span class=\"n\">results<\/span>[<span class=\"s\">\"documents\"<\/span>][<span class=\"m\">0<\/span>], <span class=\"n\">results<\/span>[<span class=\"s\">\"distances\"<\/span>][<span class=\"m\">0<\/span>]):<\/span>\n<span class=\"l\">    <span class=\"nb\">print<\/span>(<span class=\"s\">f\"{<\/span><span class=\"m\">1<\/span> - <span class=\"n\">dist<\/span><span class=\"s\">:.3f}  {<\/span><span class=\"n\">doc<\/span><span class=\"s\">}\"<\/span>)<\/span>\n<span class=\"l\"><\/span>\n<span class=\"l\"><span class=\"c\"># Same search, but only inside the \"payments\" topic<\/span><\/span>\n<span class=\"l\"><span class=\"n\">results<\/span> = <span class=\"n\">collection<\/span>.<span class=\"n\">query<\/span>(<\/span>\n<span class=\"l\">    <span class=\"n\">query_embeddings<\/span>=[[<span class=\"m\">0.20<\/span>, <span class=\"m\">0.90<\/span>, <span class=\"m\">0.20<\/span>]],<\/span>\n<span class=\"l\">    <span class=\"n\">n_results<\/span>=<span class=\"m\">1<\/span>,<\/span>\n<span class=\"l\">    <span class=\"n\">where<\/span>={<span class=\"s\">\"topic\"<\/span>: <span class=\"s\">\"payments\"<\/span>},<\/span>\n<span class=\"l\">)<\/span>\n<span class=\"l\"><span class=\"nb\">print<\/span>(<span class=\"s\">\"Filtered:\"<\/span>, <span class=\"n\">results<\/span>[<span class=\"s\">\"documents\"<\/span>][<span class=\"m\">0<\/span>][<span class=\"m\">0<\/span>])<\/span><\/code><\/pre>\n<div class=\"dd-vsc-term\"><div class=\"dd-term-head\"><span>TERMINAL<\/span><span>OUTPUT<\/span><span>PROBLEMS<\/span><\/div><pre><code><span class=\"gp\">$<\/span> python chroma_demo.py\nStored: 6 documents\n0.940  Change the email on my account\n0.911  How do I reset my password?\nFiltered: Refund not received yet<\/code><\/pre><\/div>\n<div class=\"dd-vsc-status\"><span>\u2387 main<\/span><span>Ln 34, Col 1<\/span><span class=\"sp\"><\/span><span>Spaces: 4<\/span><span>UTF-8<\/span><span>LF<\/span><span>Python<\/span><\/div>\n<\/div>\n<div class=\"dd-vsc-pane p2\">\n<div class=\"dd-vsc-crumbs\">devdojo-vectordb \u203a data.py<\/div>\n<pre class=\"dd-vsc-code\"><code><span class=\"l\"><span class=\"c\"># Tiny 3-number \"embeddings\" so the demo runs without an API key.<\/span><\/span>\n<span class=\"l\"><span class=\"c\"># Numbers mean roughly [account, payments, delivery].<\/span><\/span>\n<span class=\"l\"><span class=\"n\">DOCS<\/span> = [<\/span>\n<span class=\"l\">    (<span class=\"s\">\"d1\"<\/span>, <span class=\"s\">\"How do I reset my password?\"<\/span>,    [<span class=\"m\">0.95<\/span>, <span class=\"m\">0.10<\/span>, <span class=\"m\">0.02<\/span>], <span class=\"s\">\"account\"<\/span>),<\/span>\n<span class=\"l\">    (<span class=\"s\">\"d2\"<\/span>, <span class=\"s\">\"Change the email on my account\"<\/span>, [<span class=\"m\">0.85<\/span>, <span class=\"m\">0.15<\/span>, <span class=\"m\">0.05<\/span>], <span class=\"s\">\"account\"<\/span>),<\/span>\n<span class=\"l\">    (<span class=\"s\">\"d3\"<\/span>, <span class=\"s\">\"My UPI payment failed\"<\/span>,          [<span class=\"m\">0.10<\/span>, <span class=\"m\">0.95<\/span>, <span class=\"m\">0.05<\/span>], <span class=\"s\">\"payments\"<\/span>),<\/span>\n<span class=\"l\">    (<span class=\"s\">\"d4\"<\/span>, <span class=\"s\">\"Refund not received yet\"<\/span>,        [<span class=\"m\">0.12<\/span>, <span class=\"m\">0.80<\/span>, <span class=\"m\">0.30<\/span>], <span class=\"s\">\"payments\"<\/span>),<\/span>\n<span class=\"l\">    (<span class=\"s\">\"d5\"<\/span>, <span class=\"s\">\"When will my order reach Pune?\"<\/span>, [<span class=\"m\">0.03<\/span>, <span class=\"m\">0.10<\/span>, <span class=\"m\">0.97<\/span>], <span class=\"s\">\"delivery\"<\/span>),<\/span>\n<span class=\"l\">    (<span class=\"s\">\"d6\"<\/span>, <span class=\"s\">\"Track my parcel\"<\/span>,                [<span class=\"m\">0.05<\/span>, <span class=\"m\">0.15<\/span>, <span class=\"m\">0.90<\/span>], <span class=\"s\">\"delivery\"<\/span>),<\/span>\n<span class=\"l\">]<\/span><\/code><\/pre>\n<div class=\"dd-vsc-status\"><span>\u2387 main<\/span><span>Ln 10, Col 1<\/span><span class=\"sp\"><\/span><span>Spaces: 4<\/span><span>UTF-8<\/span><span>LF<\/span><span>Python<\/span><\/div>\n<\/div>\n<\/div>\n<p class=\"dd-vsc-hint\">This editor has two files: <strong>chroma_demo.py<\/strong> and the shared <strong>data.py<\/strong>. Click the tabs to switch, then press <strong>\u25b6 Run<\/strong> to see the real output.<\/p>\n<p>What happened:<\/p>\n<ul>\n<li><code>get_or_create_collection<\/code> creates a &#8220;table&#8221; for vectors. We set <code>\"space\": \"cosine\"<\/code> so distances use cosine.<\/li>\n<li><code>upsert<\/code> inserts new rows or updates existing ones with the same id, so you can run the script again safely.<\/li>\n<li><code>query<\/code> returns the closest documents with their <strong>distances<\/strong>. We print <code>1 - dist<\/code> to show similarity.<\/li>\n<li><code>where={\"topic\": \"payments\"}<\/code> is a <strong>metadata filter<\/strong>: search only inside rows that match.<\/li>\n<\/ul>\n<div class=\"dd-tip\"><strong>Tip:<\/strong> if you do not pass <code>embeddings<\/code>, Chroma creates them for you with a small default model (it downloads the model the first time). That is handy for demos, but for real apps choose your model on purpose, as we did in Part 9.<\/div>\n\n<h2 id=\"pgvector\">Option 2: pgvector &#8211; Vectors Inside PostgreSQL<\/h2>\n<p><a href=\"https:\/\/github.com\/pgvector\/pgvector\" rel=\"noopener\" target=\"_blank\">pgvector<\/a> is a PostgreSQL extension that adds a <code>vector<\/code> column type, distance operators and HNSW\/IVFFlat indexes. If your app already uses PostgreSQL (Supabase, Neon, AWS RDS and Google Cloud SQL all support it), this is often the best choice: your vectors live next to your users, orders and permissions, and you can use normal SQL <code>WHERE<\/code>, <code>JOIN<\/code> and transactions.<\/p>\n<h3>Step 1: Create the table and index<\/h3>\n<div class=\"dd-vsc\" role=\"group\" aria-label=\"Code editor: schema.sql\">\n<input type=\"radio\" name=\"v2\" id=\"v2f1\" class=\"f1\" checked>\n<input type=\"checkbox\" id=\"v2r1\" class=\"r1\">\n<div class=\"dd-vsc-bar\"><span class=\"dd-dots\"><i><\/i><i><\/i><i><\/i><\/span><span class=\"dd-vsc-title\">schema.sql \u2014 devdojo-vectordb \u2014 Visual Studio Code<\/span><\/div>\n<div class=\"dd-vsc-tabs\">\n<label for=\"v2f1\" class=\"t1\"><b class=\"ic sql\">SQL<\/b>schema.sql<\/label>\n<label for=\"v2r1\" class=\"run run1\" title=\"Show the output in the terminal\">\u25b6 Run<\/label>\n<\/div>\n<div class=\"dd-vsc-pane p1\">\n<div class=\"dd-vsc-crumbs\">devdojo-vectordb \u203a schema.sql<\/div>\n<pre class=\"dd-vsc-code\"><code><span class=\"l\"><span class=\"c\">-- 1. Turn on the pgvector extension (once per database)<\/span><\/span>\n<span class=\"l\"><span class=\"k\">CREATE<\/span> <span class=\"k\">EXTENSION<\/span> <span class=\"k\">IF<\/span> <span class=\"k\">NOT<\/span> <span class=\"k\">EXISTS<\/span> vector;<\/span>\n<span class=\"l\"><\/span>\n<span class=\"l\"><span class=\"c\">-- 2. A normal table with one extra column of type vector(3)<\/span><\/span>\n<span class=\"l\"><span class=\"k\">CREATE<\/span> <span class=\"k\">TABLE<\/span> <span class=\"k\">IF<\/span> <span class=\"k\">NOT<\/span> <span class=\"k\">EXISTS<\/span> faq (<\/span>\n<span class=\"l\">  id        <span class=\"nb\">text<\/span> <span class=\"k\">PRIMARY<\/span> <span class=\"k\">KEY<\/span>,<\/span>\n<span class=\"l\">  question  <span class=\"nb\">text<\/span> <span class=\"k\">NOT<\/span> <span class=\"k\">NULL<\/span>,<\/span>\n<span class=\"l\">  topic     <span class=\"nb\">text<\/span> <span class=\"k\">NOT<\/span> <span class=\"k\">NULL<\/span>,<\/span>\n<span class=\"l\">  embedding vector(<span class=\"m\">3<\/span>) <span class=\"k\">NOT<\/span> <span class=\"k\">NULL<\/span>   <span class=\"c\">-- use vector(1536) for text-embedding-3-small<\/span><\/span>\n<span class=\"l\">);<\/span>\n<span class=\"l\"><\/span>\n<span class=\"l\"><span class=\"c\">-- 3. An HNSW index for fast cosine search<\/span><\/span>\n<span class=\"l\"><span class=\"k\">CREATE<\/span> <span class=\"k\">INDEX<\/span> <span class=\"k\">IF<\/span> <span class=\"k\">NOT<\/span> <span class=\"k\">EXISTS<\/span> faq_embedding_idx<\/span>\n<span class=\"l\">  <span class=\"k\">ON<\/span> faq <span class=\"k\">USING<\/span> hnsw (embedding vector_cosine_ops);<\/span>\n<span class=\"l\"><\/span>\n<span class=\"l\"><span class=\"k\">INSERT<\/span> <span class=\"k\">INTO<\/span> faq <span class=\"k\">VALUES<\/span><\/span>\n<span class=\"l\">  (<span class=\"s\">'d1'<\/span>, <span class=\"s\">'How do I reset my password?'<\/span>,    <span class=\"s\">'account'<\/span>,  <span class=\"s\">'[0.95,0.10,0.02]'<\/span>),<\/span>\n<span class=\"l\">  (<span class=\"s\">'d3'<\/span>, <span class=\"s\">'My UPI payment failed'<\/span>,          <span class=\"s\">'payments'<\/span>, <span class=\"s\">'[0.10,0.95,0.05]'<\/span>),<\/span>\n<span class=\"l\">  (<span class=\"s\">'d5'<\/span>, <span class=\"s\">'When will my order reach Pune?'<\/span>, <span class=\"s\">'delivery'<\/span>, <span class=\"s\">'[0.03,0.10,0.97]'<\/span>)<\/span>\n<span class=\"l\"><span class=\"k\">ON<\/span> <span class=\"k\">CONFLICT<\/span> (id) <span class=\"k\">DO<\/span> <span class=\"k\">NOTHING<\/span>;<\/span>\n<span class=\"l\"><\/span>\n<span class=\"l\"><span class=\"c\">-- 4. Nearest neighbours: &lt;=&gt; is cosine distance<\/span><\/span>\n<span class=\"l\"><span class=\"k\">SELECT<\/span> question, round((<span class=\"m\">1<\/span> - (embedding &lt;=&gt; <span class=\"s\">'[0.70,0.40,0.10]'<\/span>))::<span class=\"nb\">numeric<\/span>, <span class=\"m\">3<\/span>) <span class=\"k\">AS<\/span> similarity<\/span>\n<span class=\"l\"><span class=\"k\">FROM<\/span> faq<\/span>\n<span class=\"l\"><span class=\"k\">ORDER<\/span> <span class=\"k\">BY<\/span> embedding &lt;=&gt; <span class=\"s\">'[0.70,0.40,0.10]'<\/span><\/span>\n<span class=\"l\"><span class=\"k\">LIMIT<\/span> <span class=\"m\">2<\/span>;<\/span><\/code><\/pre>\n<div class=\"dd-vsc-term\"><div class=\"dd-term-head\"><span>TERMINAL<\/span><span>OUTPUT<\/span><span>PROBLEMS<\/span><\/div><pre><code><span class=\"gp\">$<\/span> psql -h localhost -U postgres -f schema.sql\nCREATE EXTENSION\nCREATE TABLE\nCREATE INDEX\nINSERT 0 3\n          question           | similarity \n-----------------------------+------------\n How do I reset my password? |      0.911\n My UPI payment failed       |      0.586\n(2 rows)<\/code><\/pre><\/div>\n<div class=\"dd-vsc-status\"><span>\u2387 main<\/span><span>Ln 26, Col 1<\/span><span class=\"sp\"><\/span><span>Spaces: 2<\/span><span>UTF-8<\/span><span>LF<\/span><span>SQL<\/span><\/div>\n<\/div>\n<\/div>\n<p class=\"dd-vsc-hint\">Press <strong>\u25b6 Run<\/strong> to see what <code>psql<\/code> printed when we ran this file against PostgreSQL with pgvector.<\/p>\n<p>The key line is <code>ORDER BY embedding &lt;=&gt; '[...]' LIMIT 2<\/code>: &#8220;sort by cosine distance to the question and give me the two closest rows&#8221;. The HNSW index makes this fast. Use <code>vector_cosine_ops<\/code> for <code>&lt;=&gt;<\/code>, <code>vector_l2_ops<\/code> for <code>&lt;-&gt;<\/code> and <code>vector_ip_ops<\/code> for <code>&lt;#&gt;<\/code>; the operator in your query must match the index or PostgreSQL will not use it.<\/p>\n<h3>Step 2: Insert and search from Python and Node.js<\/h3>\n<div class=\"dd-vsc\" role=\"group\" aria-label=\"Code editor: pg_search.py, pg_search.mjs\">\n<input type=\"radio\" name=\"v3\" id=\"v3f1\" class=\"f1\" checked>\n<input type=\"radio\" name=\"v3\" id=\"v3f2\" class=\"f2\">\n<input type=\"checkbox\" id=\"v3r1\" class=\"r1\">\n<input type=\"checkbox\" id=\"v3r2\" class=\"r2\">\n<div class=\"dd-vsc-bar\"><span class=\"dd-dots\"><i><\/i><i><\/i><i><\/i><\/span><span class=\"dd-vsc-title\">pg_search.py \u2014 devdojo-vectordb \u2014 Visual Studio Code<\/span><\/div>\n<div class=\"dd-vsc-tabs\">\n<label for=\"v3f1\" class=\"t1\"><b class=\"ic py\">PY<\/b>pg_search.py<\/label>\n<label for=\"v3f2\" class=\"t2\"><b class=\"ic js\">JS<\/b>pg_search.mjs<\/label>\n<label for=\"v3r1\" class=\"run run1\" title=\"Show the output in the terminal\">\u25b6 Run<\/label>\n<label for=\"v3r2\" class=\"run run2\" title=\"Show the output in the terminal\">\u25b6 Run<\/label>\n<\/div>\n<div class=\"dd-vsc-pane p1\">\n<div class=\"dd-vsc-crumbs\">devdojo-vectordb \u203a pg_search.py<\/div>\n<pre class=\"dd-vsc-code\"><code><span class=\"l\"><span class=\"kn\">import<\/span> <span class=\"n\">numpy<\/span> <span class=\"k\">as<\/span> <span class=\"n\">np<\/span><\/span>\n<span class=\"l\"><span class=\"kn\">import<\/span> <span class=\"n\">psycopg<\/span><\/span>\n<span class=\"l\"><span class=\"kn\">from<\/span> <span class=\"n\">pgvector.psycopg<\/span> <span class=\"kn\">import<\/span> <span class=\"n\">register_vector<\/span><\/span>\n<span class=\"l\"><span class=\"kn\">from<\/span> <span class=\"n\">data<\/span> <span class=\"kn\">import<\/span> <span class=\"n\">DOCS<\/span><\/span>\n<span class=\"l\"><\/span>\n<span class=\"l\"><span class=\"n\">conn<\/span> = <span class=\"n\">psycopg<\/span>.<span class=\"n\">connect<\/span>(<span class=\"s\">\"postgresql:\/\/postgres:postgres@localhost:5432\/postgres\"<\/span>,<\/span>\n<span class=\"l\">                       <span class=\"n\">autocommit<\/span>=<span class=\"kc\">True<\/span>)<\/span>\n<span class=\"l\"><span class=\"n\">register_vector<\/span>(<span class=\"n\">conn<\/span>)  <span class=\"c\"># lets psycopg send\/receive numpy arrays as vectors<\/span><\/span>\n<span class=\"l\"><\/span>\n<span class=\"l\"><span class=\"k\">for<\/span> <span class=\"n\">doc_id<\/span>, <span class=\"n\">text<\/span>, <span class=\"n\">emb<\/span>, <span class=\"n\">topic<\/span> in <span class=\"n\">DOCS<\/span>:<\/span>\n<span class=\"l\">    <span class=\"n\">conn<\/span>.<span class=\"n\">execute<\/span>(<\/span>\n<span class=\"l\">        <span class=\"s\">\"\"\"INSERT INTO faq (id, question, topic, embedding)<\/span><\/span>\n<span class=\"l\"><span class=\"s\">           VALUES (%s, %s, %s, %s)<\/span><\/span>\n<span class=\"l\"><span class=\"s\">           ON CONFLICT (id) DO UPDATE SET embedding = EXCLUDED.embedding\"\"\"<\/span>,<\/span>\n<span class=\"l\">        (<span class=\"n\">doc_id<\/span>, <span class=\"n\">text<\/span>, <span class=\"n\">topic<\/span>, <span class=\"n\">np<\/span>.<span class=\"n\">array<\/span>(<span class=\"n\">emb<\/span>)),<\/span>\n<span class=\"l\">    )<\/span>\n<span class=\"l\"><\/span>\n<span class=\"l\"><span class=\"n\">query<\/span> = <span class=\"n\">np<\/span>.<span class=\"n\">array<\/span>([<span class=\"m\">0.20<\/span>, <span class=\"m\">0.90<\/span>, <span class=\"m\">0.20<\/span>])  <span class=\"c\"># \"money is stuck\"<\/span><\/span>\n<span class=\"l\"><span class=\"n\">rows<\/span> = <span class=\"n\">conn<\/span>.<span class=\"n\">execute<\/span>(<\/span>\n<span class=\"l\">    <span class=\"s\">\"\"\"SELECT question, 1 - (embedding &lt;=&gt; %s) AS similarity<\/span><\/span>\n<span class=\"l\"><span class=\"s\">       FROM faq<\/span><\/span>\n<span class=\"l\"><span class=\"s\">       WHERE topic = %s<\/span><\/span>\n<span class=\"l\"><span class=\"s\">       ORDER BY embedding &lt;=&gt; %s<\/span><\/span>\n<span class=\"l\"><span class=\"s\">       LIMIT 2\"\"\"<\/span>,<\/span>\n<span class=\"l\">    (<span class=\"n\">query<\/span>, <span class=\"s\">\"payments\"<\/span>, <span class=\"n\">query<\/span>),<\/span>\n<span class=\"l\">).<span class=\"n\">fetchall<\/span>()<\/span>\n<span class=\"l\"><\/span>\n<span class=\"l\"><span class=\"k\">for<\/span> <span class=\"n\">question<\/span>, <span class=\"n\">sim<\/span> in <span class=\"n\">rows<\/span>:<\/span>\n<span class=\"l\">    <span class=\"nb\">print<\/span>(<span class=\"s\">f\"{<\/span><span class=\"n\">sim<\/span><span class=\"s\">:.3f}  {<\/span><span class=\"n\">question<\/span><span class=\"s\">}\"<\/span>)<\/span><\/code><\/pre>\n<div class=\"dd-vsc-term\"><div class=\"dd-term-head\"><span>TERMINAL<\/span><span>OUTPUT<\/span><span>PROBLEMS<\/span><\/div><pre><code><span class=\"gp\">$<\/span> python pg_search.py\n0.988  Refund not received yet\n0.981  My UPI payment failed<\/code><\/pre><\/div>\n<div class=\"dd-vsc-status\"><span>\u2387 main<\/span><span>Ln 29, Col 1<\/span><span class=\"sp\"><\/span><span>Spaces: 4<\/span><span>UTF-8<\/span><span>LF<\/span><span>Python<\/span><\/div>\n<\/div>\n<div class=\"dd-vsc-pane p2\">\n<div class=\"dd-vsc-crumbs\">devdojo-vectordb \u203a pg_search.mjs<\/div>\n<pre class=\"dd-vsc-code\"><code><span class=\"l\"><span class=\"k\">import<\/span> <span class=\"n\">pg<\/span> <span class=\"kc\">from<\/span> <span class=\"s\">\"pg\"<\/span>;<\/span>\n<span class=\"l\"><span class=\"k\">import<\/span> <span class=\"n\">pgvector<\/span> <span class=\"kc\">from<\/span> <span class=\"s\">\"pgvector\/pg\"<\/span>;<\/span>\n<span class=\"l\"><\/span>\n<span class=\"l\"><span class=\"kc\">const<\/span> <span class=\"n\">client<\/span> = new <span class=\"n\">pg<\/span>.<span class=\"n\">Client<\/span>(<\/span>\n<span class=\"l\">  <span class=\"s\">\"postgresql:\/\/postgres:postgres@localhost:5432\/postgres\"<\/span><\/span>\n<span class=\"l\">);<\/span>\n<span class=\"l\"><span class=\"k\">await<\/span> <span class=\"n\">client<\/span>.<span class=\"n\">connect<\/span>();<\/span>\n<span class=\"l\"><span class=\"k\">await<\/span> <span class=\"n\">pgvector<\/span>.<span class=\"n\">registerTypes<\/span>(<span class=\"n\">client<\/span>); <span class=\"c\">\/\/ teaches pg about the vector type<\/span><\/span>\n<span class=\"l\"><\/span>\n<span class=\"l\"><span class=\"kc\">const<\/span> <span class=\"n\">query<\/span> = <span class=\"n\">pgvector<\/span>.<span class=\"n\">toSql<\/span>([<span class=\"m\">0.2<\/span>, <span class=\"m\">0.9<\/span>, <span class=\"m\">0.2<\/span>]); <span class=\"c\">\/\/ \"money is stuck\"<\/span><\/span>\n<span class=\"l\"><span class=\"kc\">const<\/span> { <span class=\"n\">rows<\/span> } = <span class=\"k\">await<\/span> <span class=\"n\">client<\/span>.<span class=\"n\">query<\/span>(<\/span>\n<span class=\"l\">  <span class=\"s\">`SELECT question, 1 - (embedding &lt;=&gt; $1) AS similarity<\/span><\/span>\n<span class=\"l\"><span class=\"s\">   FROM faq<\/span><\/span>\n<span class=\"l\"><span class=\"s\">   WHERE topic = $2<\/span><\/span>\n<span class=\"l\"><span class=\"s\">   ORDER BY embedding &lt;=&gt; $1<\/span><\/span>\n<span class=\"l\"><span class=\"s\">   LIMIT 2`<\/span>,<\/span>\n<span class=\"l\">  [<span class=\"n\">query<\/span>, <span class=\"s\">\"payments\"<\/span>]<\/span>\n<span class=\"l\">);<\/span>\n<span class=\"l\"><\/span>\n<span class=\"l\"><span class=\"k\">for<\/span> (<span class=\"kc\">const<\/span> <span class=\"n\">r<\/span> <span class=\"k\">of<\/span> <span class=\"n\">rows<\/span>) {<\/span>\n<span class=\"l\">  <span class=\"n\">console<\/span>.<span class=\"n\">log<\/span>(<span class=\"s\">`${<\/span><span class=\"nb\">Number<\/span>(<span class=\"n\">r<\/span>.<span class=\"n\">similarity<\/span>).<span class=\"n\">toFixed<\/span>(<span class=\"m\">3<\/span>)<span class=\"s\">}  ${<\/span><span class=\"n\">r<\/span>.<span class=\"n\">question<\/span><span class=\"s\">}`<\/span>);<\/span>\n<span class=\"l\">}<\/span>\n<span class=\"l\"><span class=\"k\">await<\/span> <span class=\"n\">client<\/span>.<span class=\"n\">end<\/span>();<\/span><\/code><\/pre>\n<div class=\"dd-vsc-term\"><div class=\"dd-term-head\"><span>TERMINAL<\/span><span>OUTPUT<\/span><span>PROBLEMS<\/span><\/div><pre><code><span class=\"gp\">$<\/span> node pg_search.mjs\n0.988  Refund not received yet\n0.981  My UPI payment failed<\/code><\/pre><\/div>\n<div class=\"dd-vsc-status\"><span>\u2387 main<\/span><span>Ln 23, Col 1<\/span><span class=\"sp\"><\/span><span>Spaces: 2<\/span><span>UTF-8<\/span><span>LF<\/span><span>JavaScript<\/span><\/div>\n<\/div>\n<\/div>\n<p class=\"dd-vsc-hint\">Same search in <strong>Python<\/strong> and <strong>Node.js<\/strong>. Click the tabs to switch language, then press <strong>\u25b6 Run<\/strong>.<\/p>\n<p>Both versions load all six documents, then search with a <strong>filter plus vector sort<\/strong> in one SQL query. Notice how normal SQL (<code>WHERE topic = ...<\/code>) and vector search mix naturally. The helper libraries <code>pgvector.psycopg<\/code> and <code>pgvector\/pg<\/code> convert between arrays and the <code>vector<\/code> type for you.<\/p>\n<div class=\"dd-warn\"><strong>Watch out:<\/strong> the size in <code>vector(3)<\/code> must equal your model&#8217;s output size. For <code>text-embedding-3-small<\/code> use <code>vector(1536)<\/code>; for <code>nomic-embed-text<\/code> in Ollama use <code>vector(768)<\/code>.<\/div>\n\n<h2 id=\"pinecone\">Option 3: Pinecone &#8211; Fully Managed in the Cloud<\/h2>\n<p><a href=\"https:\/\/docs.pinecone.io\/\" rel=\"noopener\" target=\"_blank\">Pinecone<\/a> is a hosted vector database. You do not install or scale anything; you create an index with an API call and send vectors over HTTPS. Its <strong>serverless<\/strong> indexes grow automatically and there is a free starter plan. Sign up, copy your API key and set it as <code>PINECONE_API_KEY<\/code>.<\/p>\n<div class=\"dd-vsc\" role=\"group\" aria-label=\"Code editor: pinecone_demo.py\">\n<input type=\"radio\" name=\"v4\" id=\"v4f1\" class=\"f1\" checked>\n<input type=\"checkbox\" id=\"v4r1\" class=\"r1\">\n<div class=\"dd-vsc-bar\"><span class=\"dd-dots\"><i><\/i><i><\/i><i><\/i><\/span><span class=\"dd-vsc-title\">pinecone_demo.py \u2014 devdojo-vectordb \u2014 Visual Studio Code<\/span><\/div>\n<div class=\"dd-vsc-tabs\">\n<label for=\"v4f1\" class=\"t1\"><b class=\"ic py\">PY<\/b>pinecone_demo.py<\/label>\n<label for=\"v4r1\" class=\"run run1\" title=\"Show the output in the terminal\">\u25b6 Run<\/label>\n<\/div>\n<div class=\"dd-vsc-pane p1\">\n<div class=\"dd-vsc-crumbs\">devdojo-vectordb \u203a pinecone_demo.py<\/div>\n<pre class=\"dd-vsc-code\"><code><span class=\"l\"><span class=\"kn\">import<\/span> <span class=\"n\">os<\/span><\/span>\n<span class=\"l\"><span class=\"kn\">from<\/span> <span class=\"n\">pinecone<\/span> <span class=\"kn\">import<\/span> <span class=\"n\">Pinecone<\/span>, <span class=\"n\">ServerlessSpec<\/span><\/span>\n<span class=\"l\"><span class=\"kn\">from<\/span> <span class=\"n\">data<\/span> <span class=\"kn\">import<\/span> <span class=\"n\">DOCS<\/span><\/span>\n<span class=\"l\"><\/span>\n<span class=\"l\"><span class=\"n\">pc<\/span> = <span class=\"n\">Pinecone<\/span>(<span class=\"n\">api_key<\/span>=<span class=\"n\">os<\/span>.<span class=\"n\">environ<\/span>[<span class=\"s\">\"PINECONE_API_KEY\"<\/span>])<\/span>\n<span class=\"l\"><span class=\"n\">index_name<\/span> = <span class=\"s\">\"support-faq\"<\/span><\/span>\n<span class=\"l\"><\/span>\n<span class=\"l\"><span class=\"c\"># Create a serverless index once (dimension = size of your vectors)<\/span><\/span>\n<span class=\"l\"><span class=\"k\">if<\/span> not <span class=\"n\">pc<\/span>.<span class=\"n\">has_index<\/span>(<span class=\"n\">index_name<\/span>):<\/span>\n<span class=\"l\">    <span class=\"n\">pc<\/span>.<span class=\"n\">create_index<\/span>(<\/span>\n<span class=\"l\">        <span class=\"n\">name<\/span>=<span class=\"n\">index_name<\/span>,<\/span>\n<span class=\"l\">        <span class=\"n\">dimension<\/span>=<span class=\"m\">3<\/span>,<\/span>\n<span class=\"l\">        <span class=\"n\">metric<\/span>=<span class=\"s\">\"cosine\"<\/span>,<\/span>\n<span class=\"l\">        <span class=\"n\">spec<\/span>=<span class=\"n\">ServerlessSpec<\/span>(<span class=\"n\">cloud<\/span>=<span class=\"s\">\"aws\"<\/span>, <span class=\"n\">region<\/span>=<span class=\"s\">\"us-east-1\"<\/span>),<\/span>\n<span class=\"l\">    )<\/span>\n<span class=\"l\"><\/span>\n<span class=\"l\"><span class=\"n\">index<\/span> = <span class=\"n\">pc<\/span>.<span class=\"n\">Index<\/span>(<span class=\"n\">index_name<\/span>)<\/span>\n<span class=\"l\"><\/span>\n<span class=\"l\"><span class=\"n\">index<\/span>.<span class=\"n\">upsert<\/span>(<\/span>\n<span class=\"l\">    <span class=\"n\">vectors<\/span>=[<\/span>\n<span class=\"l\">        {<span class=\"s\">\"id\"<\/span>: <span class=\"n\">d<\/span>[<span class=\"m\">0<\/span>], <span class=\"s\">\"values\"<\/span>: <span class=\"n\">d<\/span>[<span class=\"m\">2<\/span>], <span class=\"s\">\"metadata\"<\/span>: {<span class=\"s\">\"text\"<\/span>: <span class=\"n\">d<\/span>[<span class=\"m\">1<\/span>], <span class=\"s\">\"topic\"<\/span>: <span class=\"n\">d<\/span>[<span class=\"m\">3<\/span>]}}<\/span>\n<span class=\"l\">        <span class=\"k\">for<\/span> <span class=\"n\">d<\/span> in <span class=\"n\">DOCS<\/span><\/span>\n<span class=\"l\">    ],<\/span>\n<span class=\"l\">    <span class=\"n\">namespace<\/span>=<span class=\"s\">\"demo\"<\/span>,<\/span>\n<span class=\"l\">)<\/span>\n<span class=\"l\"><\/span>\n<span class=\"l\"><span class=\"n\">result<\/span> = <span class=\"n\">index<\/span>.<span class=\"n\">query<\/span>(<\/span>\n<span class=\"l\">    <span class=\"n\">vector<\/span>=[<span class=\"m\">0.20<\/span>, <span class=\"m\">0.90<\/span>, <span class=\"m\">0.20<\/span>],          <span class=\"c\"># \"money is stuck\"<\/span><\/span>\n<span class=\"l\">    <span class=\"n\">top_k<\/span>=<span class=\"m\">2<\/span>,<\/span>\n<span class=\"l\">    <span class=\"n\">include_metadata<\/span>=<span class=\"kc\">True<\/span>,<\/span>\n<span class=\"l\">    <span class=\"nb\">filter<\/span>={<span class=\"s\">\"topic\"<\/span>: {<span class=\"s\">\"$eq\"<\/span>: <span class=\"s\">\"payments\"<\/span>}},<\/span>\n<span class=\"l\">    <span class=\"n\">namespace<\/span>=<span class=\"s\">\"demo\"<\/span>,<\/span>\n<span class=\"l\">)<\/span>\n<span class=\"l\"><span class=\"k\">for<\/span> <span class=\"n\">match<\/span> in <span class=\"n\">result<\/span>.<span class=\"n\">matches<\/span>:<\/span>\n<span class=\"l\">    <span class=\"nb\">print<\/span>(<span class=\"s\">f\"{<\/span><span class=\"n\">match<\/span>.<span class=\"n\">score<\/span><span class=\"s\">:.3f}  {<\/span><span class=\"n\">match<\/span>.<span class=\"n\">metadata<\/span>[<span class=\"s\">'text'<\/span>]<span class=\"s\">}\"<\/span>)<\/span><\/code><\/pre>\n<div class=\"dd-vsc-term\"><div class=\"dd-term-head\"><span>TERMINAL<\/span><span>OUTPUT<\/span><span>PROBLEMS<\/span><span class=\"dd-term-note\">Example output \u2013 needs your own Pinecone API key<\/span><\/div><pre><code><span class=\"gp\">$<\/span> python pinecone_demo.py\n0.988  Refund not received yet\n0.981  My UPI payment failed<\/code><\/pre><\/div>\n<div class=\"dd-vsc-status\"><span>\u2387 main<\/span><span>Ln 35, Col 1<\/span><span class=\"sp\"><\/span><span>Spaces: 4<\/span><span>UTF-8<\/span><span>LF<\/span><span>Python<\/span><\/div>\n<\/div>\n<\/div>\n<p class=\"dd-vsc-hint\">Pinecone runs in the cloud, so you need a free API key. Press <strong>\u25b6 Run<\/strong> to see what the output looks like.<\/p>\n<ul>\n<li><code>ServerlessSpec(cloud=\"aws\", region=\"us-east-1\")<\/code> chooses where the index lives.<\/li>\n<li><code>namespace<\/code> splits one index into separate groups, for example one per customer.<\/li>\n<li>Pinecone returns a <strong>similarity score<\/strong> (higher is better) instead of a distance, and filters use MongoDB-style operators like <code>{\"$eq\": \"payments\"}<\/code>.<\/li>\n<li>Pinecone is <em>eventually consistent<\/em>: a vector you just upserted can take a moment to appear in queries.<\/li>\n<\/ul>\n\n<h2 id=\"real-embeddings\">Using Real Embeddings Instead of Toy Vectors<\/h2>\n<p>Toy vectors helped us see the mechanics. In a real app you get vectors from an embedding model, exactly like Part 9. Here is Chroma with OpenAI embeddings; the same <code>embed()<\/code> function also works with pgvector and Pinecone.<\/p>\n<div class=\"dd-vsc\" role=\"group\" aria-label=\"Code editor: real_embeddings.py\">\n<input type=\"radio\" name=\"v5\" id=\"v5f1\" class=\"f1\" checked>\n<input type=\"checkbox\" id=\"v5r1\" class=\"r1\">\n<div class=\"dd-vsc-bar\"><span class=\"dd-dots\"><i><\/i><i><\/i><i><\/i><\/span><span class=\"dd-vsc-title\">real_embeddings.py \u2014 devdojo-vectordb \u2014 Visual Studio Code<\/span><\/div>\n<div class=\"dd-vsc-tabs\">\n<label for=\"v5f1\" class=\"t1\"><b class=\"ic py\">PY<\/b>real_embeddings.py<\/label>\n<label for=\"v5r1\" class=\"run run1\" title=\"Show the output in the terminal\">\u25b6 Run<\/label>\n<\/div>\n<div class=\"dd-vsc-pane p1\">\n<div class=\"dd-vsc-crumbs\">devdojo-vectordb \u203a real_embeddings.py<\/div>\n<pre class=\"dd-vsc-code\"><code><span class=\"l\"><span class=\"kn\">import<\/span> <span class=\"n\">chromadb<\/span><\/span>\n<span class=\"l\"><span class=\"kn\">from<\/span> <span class=\"n\">openai<\/span> <span class=\"kn\">import<\/span> <span class=\"n\">OpenAI<\/span><\/span>\n<span class=\"l\"><\/span>\n<span class=\"l\"><span class=\"n\">openai_client<\/span> = <span class=\"n\">OpenAI<\/span>()  <span class=\"c\"># reads OPENAI_API_KEY<\/span><\/span>\n<span class=\"l\"><span class=\"n\">MODEL<\/span> = <span class=\"s\">\"text-embedding-3-small\"<\/span><\/span>\n<span class=\"l\"><\/span>\n<span class=\"l\"><span class=\"k\">def<\/span> <span class=\"nf\">embed<\/span>(<span class=\"n\">texts<\/span>):<\/span>\n<span class=\"l\">    <span class=\"n\">response<\/span> = <span class=\"n\">openai_client<\/span>.<span class=\"n\">embeddings<\/span>.<span class=\"n\">create<\/span>(<span class=\"n\">model<\/span>=<span class=\"n\">MODEL<\/span>, <span class=\"nb\">input<\/span>=<span class=\"n\">texts<\/span>)<\/span>\n<span class=\"l\">    <span class=\"k\">return<\/span> [<span class=\"n\">item<\/span>.<span class=\"n\">embedding<\/span> <span class=\"k\">for<\/span> <span class=\"n\">item<\/span> in <span class=\"n\">response<\/span>.<span class=\"n\">data<\/span>]<\/span>\n<span class=\"l\"><\/span>\n<span class=\"l\"><span class=\"n\">faq<\/span> = [<\/span>\n<span class=\"l\">    <span class=\"s\">\"How do I reset my password?\"<\/span>,<\/span>\n<span class=\"l\">    <span class=\"s\">\"My UPI payment failed\"<\/span>,<\/span>\n<span class=\"l\">    <span class=\"s\">\"When will my order reach Pune?\"<\/span>,<\/span>\n<span class=\"l\">]<\/span>\n<span class=\"l\"><\/span>\n<span class=\"l\"><span class=\"n\">db<\/span> = <span class=\"n\">chromadb<\/span>.<span class=\"n\">PersistentClient<\/span>(<span class=\"n\">path<\/span>=<span class=\"s\">\".\/chroma_db\"<\/span>)<\/span>\n<span class=\"l\"><span class=\"n\">collection<\/span> = <span class=\"n\">db<\/span>.<span class=\"n\">get_or_create_collection<\/span>(<\/span>\n<span class=\"l\">    <span class=\"n\">name<\/span>=<span class=\"s\">\"support_faq_openai\"<\/span>,<\/span>\n<span class=\"l\">    <span class=\"n\">configuration<\/span>={<span class=\"s\">\"hnsw\"<\/span>: {<span class=\"s\">\"space\"<\/span>: <span class=\"s\">\"cosine\"<\/span>}},<\/span>\n<span class=\"l\">)<\/span>\n<span class=\"l\"><span class=\"n\">collection<\/span>.<span class=\"n\">upsert<\/span>(<\/span>\n<span class=\"l\">    <span class=\"n\">ids<\/span>=[<span class=\"s\">f\"faq-{<\/span><span class=\"n\">i<\/span><span class=\"s\">}\"<\/span> <span class=\"k\">for<\/span> <span class=\"n\">i<\/span> in <span class=\"nb\">range<\/span>(<span class=\"nb\">len<\/span>(<span class=\"n\">faq<\/span>))],<\/span>\n<span class=\"l\">    <span class=\"n\">documents<\/span>=<span class=\"n\">faq<\/span>,<\/span>\n<span class=\"l\">    <span class=\"n\">embeddings<\/span>=<span class=\"n\">embed<\/span>(<span class=\"n\">faq<\/span>),<\/span>\n<span class=\"l\">    <span class=\"n\">metadatas<\/span>=[{<span class=\"s\">\"model\"<\/span>: <span class=\"n\">MODEL<\/span>}] * <span class=\"nb\">len<\/span>(<span class=\"n\">faq<\/span>),<\/span>\n<span class=\"l\">)<\/span>\n<span class=\"l\"><\/span>\n<span class=\"l\"><span class=\"n\">question<\/span> = <span class=\"s\">\"I forgot my login\"<\/span><\/span>\n<span class=\"l\"><span class=\"n\">results<\/span> = <span class=\"n\">collection<\/span>.<span class=\"n\">query<\/span>(<span class=\"n\">query_embeddings<\/span>=<span class=\"n\">embed<\/span>([<span class=\"n\">question<\/span>]), <span class=\"n\">n_results<\/span>=<span class=\"m\">1<\/span>)<\/span>\n<span class=\"l\"><span class=\"nb\">print<\/span>(<span class=\"s\">\"Question:\"<\/span>, <span class=\"n\">question<\/span>)<\/span>\n<span class=\"l\"><span class=\"nb\">print<\/span>(<span class=\"s\">\"Best match:\"<\/span>, <span class=\"n\">results<\/span>[<span class=\"s\">\"documents\"<\/span>][<span class=\"m\">0<\/span>][<span class=\"m\">0<\/span>])<\/span><\/code><\/pre>\n<div class=\"dd-vsc-term\"><div class=\"dd-term-head\"><span>TERMINAL<\/span><span>OUTPUT<\/span><span>PROBLEMS<\/span><span class=\"dd-term-note\">Example output \u2013 scores depend on the model<\/span><\/div><pre><code><span class=\"gp\">$<\/span> python real_embeddings.py\nQuestion: I forgot my login\nBest match: How do I reset my password?<\/code><\/pre><\/div>\n<div class=\"dd-vsc-status\"><span>\u2387 main<\/span><span>Ln 32, Col 1<\/span><span class=\"sp\"><\/span><span>Spaces: 4<\/span><span>UTF-8<\/span><span>LF<\/span><span>Python<\/span><\/div>\n<\/div>\n<\/div>\n<p class=\"dd-vsc-hint\">Swap the toy vectors for real ones from Part 9. Press <strong>\u25b6 Run<\/strong> to see example output.<\/p>\n<p>Notice that <code>\"I forgot my login\"<\/code> shares no words with &#8220;How do I reset my password?&#8221;, yet it is the top result. That is the power of semantic search, and it is exactly the &#8220;retrieval&#8221; step of RAG.<\/p>\n<\/div>\n\n\n\n<div class=\"dd-post\">\n<h2 id=\"choose\">Which Vector Database Should You Choose?<\/h2>\n<div class=\"dd-vdb\">\n<div class=\"ch\"><b>Chroma<\/b>Local, open source, runs in your app.<small>Best for: learning, prototypes, small apps<\/small><\/div>\n<div class=\"pg\"><b>pgvector<\/b>PostgreSQL extension, full SQL.<small>Best for: apps that already use Postgres<\/small><\/div>\n<div class=\"pc\"><b>Pinecone<\/b>Managed, serverless cloud.<small>Best for: no-ops teams, large scale<\/small><\/div>\n<\/div>\n<p>Click your situation to see a recommendation:<\/p>\n<div class=\"dd-tabs\" role=\"group\" aria-label=\"Which vector database should I choose?\">\n<input type=\"radio\" name=\"ti\" id=\"ti1\" checked><input type=\"radio\" name=\"ti\" id=\"ti2\"><input type=\"radio\" name=\"ti\" id=\"ti3\"><input type=\"radio\" name=\"ti\" id=\"ti4\">\n<div class=\"labels\"><label for=\"ti1\">I am learning<\/label><label for=\"ti2\">I already use PostgreSQL<\/label><label for=\"ti3\">I want zero servers<\/label><label for=\"ti4\">Huge scale<\/label><\/div>\n<div class=\"panel p1\"><p><strong>Pick Chroma.<\/strong> One <code>pip install<\/code>, no account, data saved in a local folder. Perfect for tutorials, hackathons and prototypes. When you grow, Chroma also offers a server mode and a hosted cloud.<\/p><\/div>\n<div class=\"panel p2\"><p><strong>Pick pgvector.<\/strong> No new system to learn or pay for. You keep one database, one backup and one set of permissions, and you can join vectors with your existing tables. It comfortably handles millions of vectors with an HNSW index.<\/p><\/div>\n<div class=\"panel p3\"><p><strong>Pick Pinecone<\/strong> (or another managed service). You get an API key and an endpoint; scaling, backups and replicas are handled for you. Great for small teams that do not want to run databases.<\/p><\/div>\n<div class=\"panel p4\"><p><strong>Hundreds of millions of vectors?<\/strong> Look at Pinecone, or dedicated engines like Qdrant, Weaviate and Milvus, which add features such as sharding, quantization and hybrid search. Measure with your own data before you decide.<\/p><\/div>\n<\/div>\n<div class=\"dd-tablewrap\"><table>\n<thead><tr><th>Feature<\/th><th>Chroma<\/th><th>pgvector<\/th><th>Pinecone<\/th><\/tr><\/thead>\n<tbody>\n<tr><td>Setup<\/td><td><code>pip install chromadb<\/code><\/td><td>Extension in PostgreSQL<\/td><td>Sign up + API key<\/td><\/tr>\n<tr><td>Where it runs<\/td><td>In your app or a Chroma server<\/td><td>Your PostgreSQL server<\/td><td>Pinecone cloud<\/td><\/tr>\n<tr><td>Cost<\/td><td>Free (open source)<\/td><td>Free (you pay for Postgres)<\/td><td>Free tier, then usage-based<\/td><\/tr>\n<tr><td>Filtering<\/td><td><code>where={...}<\/code><\/td><td>Any SQL <code>WHERE<\/code> \/ <code>JOIN<\/code><\/td><td><code>filter={...}<\/code><\/td><\/tr>\n<tr><td>Index<\/td><td>HNSW (automatic)<\/td><td>HNSW or IVFFlat (you create)<\/td><td>Managed (automatic)<\/td><\/tr>\n<tr><td>Result value<\/td><td>Distance<\/td><td>Distance (via operator)<\/td><td>Similarity score<\/td><\/tr>\n<\/tbody><\/table><\/div>\n\n<h2 id=\"errors\">Common Errors and Fixes<\/h2>\n<div class=\"dd-tablewrap\"><table>\n<thead><tr><th>Error \/ symptom<\/th><th>Why it happens<\/th><th>Fix<\/th><\/tr><\/thead>\n<tbody>\n<tr><td><code>expected 1536 dimensions, not 768<\/code> (pgvector)<\/td><td>Column size and model output size are different<\/td><td>Use <code>vector(N)<\/code> that matches your model, or re-embed with the right model<\/td><\/tr>\n<tr><td><code>type \"vector\" does not exist<\/code><\/td><td>Extension not enabled in this database<\/td><td>Run <code>CREATE EXTENSION vector;<\/code> (once per database)<\/td><\/tr>\n<tr><td>Chroma: <code>Collection expecting embedding with dimension of 3, got 1536<\/code><\/td><td>The collection was first filled with a different model<\/td><td>Create a new collection per model, or delete and re-index<\/td><\/tr>\n<tr><td>Search results look random<\/td><td>Documents and questions embedded with different models<\/td><td>Always use the same model (and version) for both<\/td><\/tr>\n<tr><td>pgvector query is slow even with an index<\/td><td>Operator does not match the index ops, or the filter removes most rows<\/td><td>Match <code>&lt;=&gt;<\/code> with <code>vector_cosine_ops<\/code>; add a normal index on the filter column<\/td><\/tr>\n<tr><td>Pinecone: new vectors missing from results<\/td><td>Writes are eventually consistent<\/td><td>Wait a moment, or check with <code>describe_index_stats()<\/code><\/td><\/tr>\n<tr><td>Pinecone: <code>401 Unauthorized<\/code><\/td><td>API key missing or wrong<\/td><td>Set <code>PINECONE_API_KEY<\/code> and never hard-code it<\/td><\/tr>\n<\/tbody><\/table><\/div>\n\n<h2 id=\"best-practices\">Best Practices<\/h2>\n<ul>\n<li><strong>Store the text with the vector.<\/strong> You need it to show results and to send context to the LLM in RAG.<\/li>\n<li><strong>Save the model name<\/strong> in metadata (for example <code>model: \"text-embedding-3-small\"<\/code>). When you change models, you must re-embed everything.<\/li>\n<li><strong>Use <code>upsert<\/code> with stable ids<\/strong> (like <code>file_name + chunk_number<\/code>) so re-running your indexing script does not create duplicates.<\/li>\n<li><strong>Batch your inserts.<\/strong> Send 100&#8211;500 vectors per request instead of one at a time.<\/li>\n<li><strong>Filter by user or tenant<\/strong> so one customer can never see another customer&#8217;s documents.<\/li>\n<li><strong>Start simple.<\/strong> Chroma or pgvector covers most projects. Move to a dedicated service only when you measure a real need.<\/li>\n<li><strong>Measure quality.<\/strong> Keep 10&#8211;20 test questions with the expected answers and check that they appear in the top results after every change.<\/li>\n<\/ul>\n\n<h2 id=\"practice\">Practice Task<\/h2>\n<p>Build a small &#8220;DevDojo article finder&#8221;:<\/p>\n<ol>\n<li>Write 8&#8211;10 short article summaries (one line each) about any topics you like, and give each one a <code>category<\/code> such as <code>ai<\/code>, <code>frontend<\/code> or <code>devops<\/code>.<\/li>\n<li>Create embeddings for them with OpenAI or Ollama (Part 9) and store them in <strong>Chroma<\/strong>.<\/li>\n<li>Ask three questions and print the top 3 results with their similarity.<\/li>\n<li>Bonus: repeat with <strong>pgvector<\/strong> and add <code>WHERE category = 'ai'<\/code>. Do both databases return the same order?<\/li>\n<\/ol>\n\n<h2 id=\"faq\">FAQ<\/h2>\n<details><summary>Do I really need a vector database for a small project?<\/summary><p>No. For a few thousand vectors, a simple list in memory with cosine similarity (like Part 9) is fine. Use a vector database when you need to save data, search quickly at scale, filter by metadata or share the data between servers.<\/p><\/details>\n<details><summary>Is pgvector as good as a dedicated vector database?<\/summary><p>For most apps, yes. With an HNSW index, pgvector handles millions of vectors with fast queries, and you keep all the benefits of PostgreSQL. Dedicated databases shine at very large scale or when you need advanced features out of the box.<\/p><\/details>\n<details><summary>What is the difference between distance and similarity?<\/summary><p>Distance says how far apart two vectors are (smaller is closer). Similarity says how alike they are (bigger is closer). For cosine, similarity = 1 &#8722; distance.<\/p><\/details>\n<details><summary>Can I change the embedding model later?<\/summary><p>Yes, but you must re-create the embeddings for all documents with the new model. Vectors from different models cannot be compared. Keep the original text so re-embedding is easy.<\/p><\/details>\n<details><summary>Is Chroma ready for production?<\/summary><p>Chroma works well for small and medium apps, and it has a client-server mode and a hosted cloud for bigger deployments. Many teams prototype in Chroma and move to pgvector or a managed service later; because the concepts are the same, the switch is small.<\/p><\/details>\n<details><summary>How many results (top_k) should I fetch?<\/summary><p>For search pages, 5&#8211;10. For RAG, 3&#8211;8 chunks is a good start. Too few may miss the answer; too many add noise and cost. We will tune this in Part 11 and Part 13.<\/p><\/details>\n\n<h2>Conclusion<\/h2>\n<p>A vector database is simply a place to store embeddings and find the nearest ones fast. You learned how ANN indexes like HNSW make search quick, how to choose a distance metric, and how to store and search vectors with <strong>Chroma<\/strong>, <strong>pgvector<\/strong> and <strong>Pinecone<\/strong>, including metadata filters. With embeddings (Part 9) and a vector database (Part 10), you now have everything needed for the most popular GenAI pattern of all.<\/p>\n\n<div class=\"dd-next\"><strong>Next part (Part 11): RAG Fundamentals &#8211; Retrieval-Augmented Generation.<\/strong> We will connect today&#8217;s vector search to an LLM so it can answer questions about <em>your<\/em> documents, with sources, instead of guessing.<\/div>\n\n<div class=\"dd-cta\">\n<h3>New posts every day on DevDojo<\/h3>\n<p>Follow the full Generative AI series: one practical part at a time, from beginner to production. Bookmark <a href=\"https:\/\/devdojo.co.in\/\">devdojo.co.in<\/a> and share this part with a friend who is learning AI.<\/p>\n<p><a href=\"https:\/\/devdojo.co.in\/?p=306\">&#8592; Part 9: Embeddings Explained<\/a><\/p>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Learn what a vector database is and how to store and search embeddings with Chroma, pgvector and Pinecone, using runnable Python, Node.js and SQL examples.<\/p>\n","protected":false},"author":1,"featured_media":309,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[38],"tags":[170,89,87,171,86,112,169],"class_list":["post-310","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ai","tag-chromadb","tag-embeddings","tag-pgvector","tag-pinecone","tag-rag","tag-series-generative-ai","tag-vector-database"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.4 - aioseo.com -->\n\t<meta name=\"description\" content=\"Learn what a vector database is and how to store and search embeddings with Chroma, pgvector and Pinecone, using runnable Python, Node.js and SQL examples.\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Lokendra\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/devdojo.co.in\/index.php\/2026\/11\/23\/genai-series-part-10-vector-databases\/\" \/>\n\t\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.4\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"DevDojo - Empowering Developers\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Vector Databases: pgvector, Chroma and Pinecone\" \/>\n\t\t<meta property=\"og:description\" content=\"Learn what a vector database is and how to store and search embeddings with Chroma, pgvector and Pinecone, using runnable Python, Node.js and SQL examples.\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/devdojo.co.in\/index.php\/2026\/11\/23\/genai-series-part-10-vector-databases\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2026-11-23T13:00:03+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2026-11-23T13:00:05+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Vector Databases: pgvector, Chroma and Pinecone\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Learn what a vector database is and how to store and search embeddings with Chroma, pgvector and Pinecone, using runnable Python, Node.js and SQL examples.\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"BlogPosting\",\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/2026\\\/11\\\/23\\\/genai-series-part-10-vector-databases\\\/#blogposting\",\"name\":\"Vector Database Guide: pgvector, Chroma and Pinecone\",\"headline\":\"Generative AI Part 10: Vector Databases: pgvector, Chroma and Pinecone\",\"author\":{\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/author\\\/lokendra\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/#organization\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/devdojo.co.in\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/genai-series-part-10-vector-databases.jpg\",\"width\":1200,\"height\":630,\"caption\":\"Generative AI Part 10 banner: a question embedding goes into a vector database (Chroma, pgvector, Pinecone) and returns the nearest matching documents\"},\"datePublished\":\"2026-11-23T13:00:03+00:00\",\"dateModified\":\"2026-11-23T13:00:05+00:00\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/2026\\\/11\\\/23\\\/genai-series-part-10-vector-databases\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/2026\\\/11\\\/23\\\/genai-series-part-10-vector-databases\\\/#webpage\"},\"articleSection\":\"AI, ChromaDB, Embeddings, pgvector, Pinecone, RAG, Series: Generative AI, Vector Database\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/2026\\\/11\\\/23\\\/genai-series-part-10-vector-databases\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/devdojo.co.in\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/category\\\/ai\\\/#listItem\",\"name\":\"AI\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/category\\\/ai\\\/#listItem\",\"position\":2,\"name\":\"AI\",\"item\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/category\\\/ai\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/2026\\\/11\\\/23\\\/genai-series-part-10-vector-databases\\\/#listItem\",\"name\":\"Generative AI Part 10: Vector Databases: pgvector, Chroma and Pinecone\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/2026\\\/11\\\/23\\\/genai-series-part-10-vector-databases\\\/#listItem\",\"position\":3,\"name\":\"Generative AI Part 10: Vector Databases: pgvector, Chroma and Pinecone\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/category\\\/ai\\\/#listItem\",\"name\":\"AI\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/#organization\",\"name\":\"DevDojo\",\"description\":\"Empowering Developers\",\"url\":\"https:\\\/\\\/devdojo.co.in\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/author\\\/lokendra\\\/#author\",\"url\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/author\\\/lokendra\\\/\",\"name\":\"Lokendra\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/2026\\\/11\\\/23\\\/genai-series-part-10-vector-databases\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/99f102f0cc9080237ce54b91304fd1b3b6fa29925cbaeba93cd796872e58b45c?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Lokendra\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/2026\\\/11\\\/23\\\/genai-series-part-10-vector-databases\\\/#webpage\",\"url\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/2026\\\/11\\\/23\\\/genai-series-part-10-vector-databases\\\/\",\"name\":\"Vector Database Guide: pgvector, Chroma and Pinecone\",\"description\":\"Learn what a vector database is and how to store and search embeddings with Chroma, pgvector and Pinecone, using runnable Python, Node.js and SQL examples.\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/2026\\\/11\\\/23\\\/genai-series-part-10-vector-databases\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/author\\\/lokendra\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/author\\\/lokendra\\\/#author\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/devdojo.co.in\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/genai-series-part-10-vector-databases.jpg\",\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/2026\\\/11\\\/23\\\/genai-series-part-10-vector-databases\\\/#mainImage\",\"width\":1200,\"height\":630,\"caption\":\"Generative AI Part 10 banner: a question embedding goes into a vector database (Chroma, pgvector, Pinecone) and returns the nearest matching documents\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/2026\\\/11\\\/23\\\/genai-series-part-10-vector-databases\\\/#mainImage\"},\"datePublished\":\"2026-11-23T13:00:03+00:00\",\"dateModified\":\"2026-11-23T13:00:05+00:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/#website\",\"url\":\"https:\\\/\\\/devdojo.co.in\\\/\",\"name\":\"DevDojo\",\"description\":\"Empowering Developers\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Vector Database Guide: pgvector, Chroma and Pinecone","description":"Learn what a vector database is and how to store and search embeddings with Chroma, pgvector and Pinecone, using runnable Python, Node.js and SQL examples.","canonical_url":"https:\/\/devdojo.co.in\/index.php\/2026\/11\/23\/genai-series-part-10-vector-databases\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"BlogPosting","@id":"https:\/\/devdojo.co.in\/index.php\/2026\/11\/23\/genai-series-part-10-vector-databases\/#blogposting","name":"Vector Database Guide: pgvector, Chroma and Pinecone","headline":"Generative AI Part 10: Vector Databases: pgvector, Chroma and Pinecone","author":{"@id":"https:\/\/devdojo.co.in\/index.php\/author\/lokendra\/#author"},"publisher":{"@id":"https:\/\/devdojo.co.in\/#organization"},"image":{"@type":"ImageObject","url":"https:\/\/devdojo.co.in\/wp-content\/uploads\/2026\/11\/genai-series-part-10-vector-databases.jpg","width":1200,"height":630,"caption":"Generative AI Part 10 banner: a question embedding goes into a vector database (Chroma, pgvector, Pinecone) and returns the nearest matching documents"},"datePublished":"2026-11-23T13:00:03+00:00","dateModified":"2026-11-23T13:00:05+00:00","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/devdojo.co.in\/index.php\/2026\/11\/23\/genai-series-part-10-vector-databases\/#webpage"},"isPartOf":{"@id":"https:\/\/devdojo.co.in\/index.php\/2026\/11\/23\/genai-series-part-10-vector-databases\/#webpage"},"articleSection":"AI, ChromaDB, Embeddings, pgvector, Pinecone, RAG, Series: Generative AI, Vector Database"},{"@type":"BreadcrumbList","@id":"https:\/\/devdojo.co.in\/index.php\/2026\/11\/23\/genai-series-part-10-vector-databases\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/devdojo.co.in\/#listItem","position":1,"name":"Home","item":"https:\/\/devdojo.co.in\/","nextItem":{"@type":"ListItem","@id":"https:\/\/devdojo.co.in\/index.php\/category\/ai\/#listItem","name":"AI"}},{"@type":"ListItem","@id":"https:\/\/devdojo.co.in\/index.php\/category\/ai\/#listItem","position":2,"name":"AI","item":"https:\/\/devdojo.co.in\/index.php\/category\/ai\/","nextItem":{"@type":"ListItem","@id":"https:\/\/devdojo.co.in\/index.php\/2026\/11\/23\/genai-series-part-10-vector-databases\/#listItem","name":"Generative AI Part 10: Vector Databases: pgvector, Chroma and Pinecone"},"previousItem":{"@type":"ListItem","@id":"https:\/\/devdojo.co.in\/#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/devdojo.co.in\/index.php\/2026\/11\/23\/genai-series-part-10-vector-databases\/#listItem","position":3,"name":"Generative AI Part 10: Vector Databases: pgvector, Chroma and Pinecone","previousItem":{"@type":"ListItem","@id":"https:\/\/devdojo.co.in\/index.php\/category\/ai\/#listItem","name":"AI"}}]},{"@type":"Organization","@id":"https:\/\/devdojo.co.in\/#organization","name":"DevDojo","description":"Empowering Developers","url":"https:\/\/devdojo.co.in\/"},{"@type":"Person","@id":"https:\/\/devdojo.co.in\/index.php\/author\/lokendra\/#author","url":"https:\/\/devdojo.co.in\/index.php\/author\/lokendra\/","name":"Lokendra","image":{"@type":"ImageObject","@id":"https:\/\/devdojo.co.in\/index.php\/2026\/11\/23\/genai-series-part-10-vector-databases\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/99f102f0cc9080237ce54b91304fd1b3b6fa29925cbaeba93cd796872e58b45c?s=96&d=mm&r=g","width":96,"height":96,"caption":"Lokendra"}},{"@type":"WebPage","@id":"https:\/\/devdojo.co.in\/index.php\/2026\/11\/23\/genai-series-part-10-vector-databases\/#webpage","url":"https:\/\/devdojo.co.in\/index.php\/2026\/11\/23\/genai-series-part-10-vector-databases\/","name":"Vector Database Guide: pgvector, Chroma and Pinecone","description":"Learn what a vector database is and how to store and search embeddings with Chroma, pgvector and Pinecone, using runnable Python, Node.js and SQL examples.","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/devdojo.co.in\/#website"},"breadcrumb":{"@id":"https:\/\/devdojo.co.in\/index.php\/2026\/11\/23\/genai-series-part-10-vector-databases\/#breadcrumblist"},"author":{"@id":"https:\/\/devdojo.co.in\/index.php\/author\/lokendra\/#author"},"creator":{"@id":"https:\/\/devdojo.co.in\/index.php\/author\/lokendra\/#author"},"image":{"@type":"ImageObject","url":"https:\/\/devdojo.co.in\/wp-content\/uploads\/2026\/11\/genai-series-part-10-vector-databases.jpg","@id":"https:\/\/devdojo.co.in\/index.php\/2026\/11\/23\/genai-series-part-10-vector-databases\/#mainImage","width":1200,"height":630,"caption":"Generative AI Part 10 banner: a question embedding goes into a vector database (Chroma, pgvector, Pinecone) and returns the nearest matching documents"},"primaryImageOfPage":{"@id":"https:\/\/devdojo.co.in\/index.php\/2026\/11\/23\/genai-series-part-10-vector-databases\/#mainImage"},"datePublished":"2026-11-23T13:00:03+00:00","dateModified":"2026-11-23T13:00:05+00:00"},{"@type":"WebSite","@id":"https:\/\/devdojo.co.in\/#website","url":"https:\/\/devdojo.co.in\/","name":"DevDojo","description":"Empowering Developers","inLanguage":"en-US","publisher":{"@id":"https:\/\/devdojo.co.in\/#organization"}}]},"og:locale":"en_US","og:site_name":"DevDojo - Empowering Developers","og:type":"article","og:title":"Vector Databases: pgvector, Chroma and Pinecone","og:description":"Learn what a vector database is and how to store and search embeddings with Chroma, pgvector and Pinecone, using runnable Python, Node.js and SQL examples.","og:url":"https:\/\/devdojo.co.in\/index.php\/2026\/11\/23\/genai-series-part-10-vector-databases\/","article:published_time":"2026-11-23T13:00:03+00:00","article:modified_time":"2026-11-23T13:00:05+00:00","twitter:card":"summary_large_image","twitter:title":"Vector Databases: pgvector, Chroma and Pinecone","twitter:description":"Learn what a vector database is and how to store and search embeddings with Chroma, pgvector and Pinecone, using runnable Python, Node.js and SQL examples."},"aioseo_meta_data":{"post_id":"310","title":"Vector Database Guide: pgvector, Chroma and Pinecone","description":"Learn what a vector database is and how to store and search embeddings with Chroma, pgvector and Pinecone, using runnable Python, Node.js and SQL examples.","keywords":null,"keyphrases":{"focus":{"keyphrase":"vector database","score":79},"additional":[]},"primary_term":null,"canonical_url":null,"og_title":"Vector Databases: pgvector, Chroma and Pinecone","og_description":"Learn what a vector database is and how to store and search embeddings with Chroma, pgvector and Pinecone, using runnable Python, Node.js and SQL examples.","og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"BlogPosting","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":"-1","robots_max_videopreview":"-1","robots_max_imagepreview":"large","priority":0,"frequency":"default","local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":{"faqs":[],"keyPoints":[],"schemas":[],"titles":[],"descriptions":[],"socialPosts":{"email":{"subject":"","preview":"","content":""},"linkedin":[],"twitter":[],"facebook":[],"instagram":[]}},"created":"2026-11-23 12:59:28","updated":"2026-11-23 13:14:27","focus_keyword":"vector database","additional_keywords":null,"truseo_locale":null,"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/devdojo.co.in\/\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">\u00bb<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/devdojo.co.in\/index.php\/category\/ai\/\" title=\"AI\">AI<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">\u00bb<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tGenerative AI Part 10: Vector Databases: pgvector, Chroma and Pinecone\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/devdojo.co.in\/"},{"label":"AI","link":"https:\/\/devdojo.co.in\/index.php\/category\/ai\/"},{"label":"Generative AI Part 10: Vector Databases: pgvector, Chroma and Pinecone","link":"https:\/\/devdojo.co.in\/index.php\/2026\/11\/23\/genai-series-part-10-vector-databases\/"}],"_links":{"self":[{"href":"https:\/\/devdojo.co.in\/index.php\/wp-json\/wp\/v2\/posts\/310","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devdojo.co.in\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devdojo.co.in\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devdojo.co.in\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/devdojo.co.in\/index.php\/wp-json\/wp\/v2\/comments?post=310"}],"version-history":[{"count":1,"href":"https:\/\/devdojo.co.in\/index.php\/wp-json\/wp\/v2\/posts\/310\/revisions"}],"predecessor-version":[{"id":311,"href":"https:\/\/devdojo.co.in\/index.php\/wp-json\/wp\/v2\/posts\/310\/revisions\/311"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devdojo.co.in\/index.php\/wp-json\/wp\/v2\/media\/309"}],"wp:attachment":[{"href":"https:\/\/devdojo.co.in\/index.php\/wp-json\/wp\/v2\/media?parent=310"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devdojo.co.in\/index.php\/wp-json\/wp\/v2\/categories?post=310"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devdojo.co.in\/index.php\/wp-json\/wp\/v2\/tags?post=310"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}