Vector search enables you to perform similarity searches on vectors stored in Postgres. With the pgvector extension, you can store and efficiently query vector embeddings, making Postgres a viable option for AI-driven applications like retrieval-augmented generation (RAG) and semantic search.

Steps

  • Install and enable pgvector
  • Create a table with a vector column
  • Insert and retrieve vector data
  • Perform nearest neighbor searches
  • Index using HNSW indexes
  • Insert and retrieve embeddings

Install and enable pgvector

Before using vector search, you need to install the pgvector extension. The pgvector extension adds a vector data type, operators for similarity search (<->, <#>, <=>) , and support for ANN indexes. In Neon, pgvector is already installed, you just need to enable it using the following command.

CREATE EXTENSION IF NOT EXISTS vector;

Create a table with a vector column

To store embeddings, you need a table with a column defined as the vector data type. You must specify the dimensions of the vector (also known as dimensionality), which is determined by the embedding model you plan to use (e.g., OpenAI's text-embedding-3-small uses 1536 dimensions).

For example, the following command creates a table embeddings with a 3-dimensional vector column data.

CREATE TABLE embeddings (
  id SERIAL PRIMARY KEY,
  data VECTOR(3) -- 3-dimensional vector example
);

Insert and retrieve vector data

You can insert vectors as arrays using the following command. Under the hood, vectors are just fixed-length arrays of floats.

INSERT INTO embeddings (data)
VALUES ('[0.1, 0.2, 0.3]'),
       ('[0.5, 0.1, 0.8]');

You can retrieve all stored vectors using the following command.

SELECT * FROM embeddings;

Perform nearest neighbor searches

Vector search typically means finding the closest vectors in the database to a given vector. There are different distance metrics to calculate which vector is closest, like Euclidean distance (<->), cosine distance (<=>), and inner product (<#>).

  • <->: Euclidean distance (L2). Measues straight-line distance between two vectors. Good for general similarity tasks when magnitude matters.
  • <=>: Cosine distance. Compares the angle between two vectors. Common for text embeddings, where direction matters more than magnitude.
  • <#>: Negative inner product. Used for maximizing similarity. Often used in ranking or recommendation systems.

For example, the following command runs nearest neighbor search to find the most similar vector to [0.2, 0.1, 0.3] using Euclidean distance, which is [0.1, 0.2, 0.3].

SELECT * FROM embeddings
ORDER BY data <-> '[0.2, 0.1, 0.3]'
LIMIT 1;

You should see the following output.

id |     data
----+--------------
  1 | [0.1,0.2,0.3]
(1 row)

Index using HNSW indexes

By default, the query above performs a sequential scan of the embeddings table, which can be slow for large datasets. To speed up nearest neighbor searches, you can create an approximate nearest neighbor (ANN) index.

pgvector supports two different indexes for nearest neighbor search: HNSW and IVFFlat.

The following command creates a HNSW index.

CREATE INDEX ON embeddings USING hnsw (data);

Insert and retrieve embeddings

Vector databases are typically used to store embeddings. An embedding is a numerical representation of data in a high-dimensional space that captures semantic relationships and similarities between entities. First, run the following command to recreate the embeddings table to store vectors with dimensionality 512.

DROP TABLE embeddings;

CREATE TABLE embeddings (
  id SERIAL PRIMARY KEY,
  content TEXT,
  data VECTOR(512)
);

How to generate embeddings

In most cases, embeddings are created using external services such as OpenAI or Gemini etc. Once generated, they can be stored in Postgres for vector search with pgvector. The dimensionality of the embedding must match the model you use (for example, 512, 768, or 1536 dimensions), ensuring consistency between the stored vectors and the queries you run.

For this example, we will use embeddings generated from the Nomic API.

Insert embeddings

You can insert embeddings into the embeddings table using the following SQL command.

INSERT INTO embeddings (content, data)
VALUES
  ('i like to eat tacos', '[0.017120361,0.09112549,-0.24157715,0.0045776367,-0.024642944,0.0062828064,-0.06707764,0.022094727,-0.022232056,-0.019546509,0.010147095,0.05722046,0.027832031,0.07006836,-0.0051574707,-0.041259766,0.0008292198,-0.08605957,0.014213562,0.10180664,-0.045318604,-0.046447754,-0.002002716,-0.04144287,0.11590576,0.0093688965,-0.019638062,0.08929443,-0.057739258,0.031173706,-0.030471802,-0.07293701,0.019317627,0.100097656,0.017288208,-0.053222656,0.082092285,0.018234253,0.024536133,-0.0541687,-0.027191162,0.038635254,0.05657959,-0.050445557,0.06378174,-0.015579224,0.0736084,0.059173584,0.029037476,-0.03451538,-0.030151367,-0.027633667,-0.038604736,-0.06750488,-0.0038433075,-0.06210327,0.055664062,-0.06677246,-0.01828003,0.025848389,0.10809326,0.021942139,0.016067505,0.08532715,0.02708435,0.031311035,-0.046691895,0.078125,-0.07287598,-0.021347046,0.07159424,-0.0037384033,0.03878784,0.014350891,-0.02381897,-0.04309082,-0.031463623,-0.00541687,-0.03274536,-0.015464783,-0.0046539307,-0.017654419,0.08538818,-0.025238037,0.035949707,-0.012565613,0.0625,-0.057647705,-0.0418396,0.052825928,0.024276733,0.002412796,0.051452637,0.01663208,-0.029724121,0.035247803,-0.025817871,0.046081543,-0.007888794,-0.05114746,-0.036346436,0.017074585,0.009651184,-0.010925293,0.103759766,0.022567749,0.056121826,-0.0058555603,0.0362854,0.0031356812,0.03062439,0.042755127,-0.026870728,-0.05215454,-0.006095886,0.00006586313,0.010673523,-0.09136963,0.033721924,0.040740967,-0.01991272,-0.01953125,0.00033140182,0.05831909,0.015686035,0.024383545,-0.005264282,0.022613525,-0.048858643,-0.028945923,-0.002817154,0.03781128,0.014976501,-0.014030457,0.011795044,0.06008911,0.03262329,-0.066101074,0.015686035,0.008361816,0.005657196,0.06335449,0.051635742,-0.015274048,0.02571106,-0.044281006,0.0140686035,-0.09503174,0.011451721,-0.039886475,-0.02571106,0.0073432922,-0.0067329407,0.042541504,-0.022781372,-0.061798096,0.025634766,-0.05718994,-0.0023117065,0.015312195,0.04937744,-0.029815674,-0.009246826,0.05505371,0.014663696,-0.049468994,-0.0051002502,0.06573486,0.030593872,0.07922363,-0.026885986,-0.019348145,-0.051452637,-0.06427002,-0.04324341,-0.076171875,-0.09637451,-0.03753662,0.04888916,-0.017456055,0.02520752,-0.070129395,0.0022792816,0.08203125,-0.038635254,-0.044769287,-0.0020809174,0.025283813,-0.06549072,-0.028427124,0.011878967,0.010292053,-0.07965088,-0.05239868,-0.03062439,0.025115967,0.033081055,0.0035209656,0.014038086,-0.038909912,-0.023147583,-0.03616333,-0.10192871,0.027648926,-0.054382324,0.030395508,-0.05493164,-0.0048446655,-0.03756714,0.022705078,0.06274414,-0.030807495,-0.023605347,-0.02330017,-0.026519775,-0.034210205,-0.004245758,-0.014305115,-0.014213562,0.03845215,0.045684814,-0.014465332,0.009208679,-0.032562256,0.022567749,-0.027557373,-0.0033683777,-0.038085938,-0.04937744,-0.022033691,-0.014198303,-0.07611084,0.14099121,0.003921509,0.034576416,0.05404663,0.066345215,0.0847168,-0.0026435852,-0.051452637,-0.013175964,0.01701355,0.034820557,-0.039642334,-0.05734253,0.039093018,-0.004928589,-0.052215576,-0.027740479,0.050689697,0.049041748,-0.016693115,0.015731812,-0.01158905,0.024597168,-0.01878357,-0.012107849,0.040100098,0.031158447,-0.06994629,0.045135498,-0.10028076,0.033843994,-0.08734131,-0.021850586,-0.009010315,-0.03894043,0.052642822,-0.015525818,-0.07067871,0.023330688,0.011230469,-0.00018012524,0.046447754,-0.06591797,0.019104004,0.02494812,-0.0345459,-0.03277588,-0.0038433075,0.031051636,-0.03744507,-0.011779785,0.031234741,0.0041542053,0.070373535,0.023498535,0.0054016113,-0.011703491,-0.0067710876,0.04724121,0.06185913,-0.025558472,0.040130615,0.03439331,0.013008118,0.08886719,-0.032836914,-0.032958984,-0.043029785,-0.009384155,0.04269409,0.037475586,0.022415161,-0.038513184,0.035064697,0.07702637,-0.057861328,0.06274414,-0.028869629,0.0027332306,-0.024215698,-0.0067977905,0.07885742,-0.047668457,0.03137207,-0.020477295,0.0036449432,0.053375244,-0.002811432,0.03074646,-0.051513672,-0.0021152496,-0.05166626,-0.03869629,0.012924194,0.03878784,0.05831909,0.014884949,-0.07141113,0.001496315,0.01776123,0.03353882,-0.030471802,-0.028747559,0.028167725,0.068725586,0.025894165,-0.030807495,0.05807495,-0.007843018,-0.028762817,0.018737793,-0.04714966,-0.03149414,-0.007259369,-0.057128906,0.014770508,0.095458984,0.016723633,-0.039123535,0.02015686,-0.022628784,0.04852295,-0.0047912598,-0.026687622,0.055267334,-0.048736572,0.014633179,-0.005859375,0.02470398,-0.026916504,0.01083374,-0.010940552,-0.007030487,0.027557373,0.027526855,-0.015853882,0.013328552,0.030960083,-0.048919678,-0.051086426,-0.017242432,0.04147339,-0.004863739,0.017288208,-0.13586426,-0.035247803,0.057891846,-0.037750244,-0.0022220612,0.01576233,-0.057861328,0.039489746,0.055114746,0.037200928,0.04522705,0.0023956299,-0.030136108,-0.004131317,-0.006034851,-0.02619934,-0.07397461,-0.008293152,0.027572632,-0.061828613,0.07537842,-0.038635254,0.031341553,-0.002708435,-0.022384644,-0.057861328,0.00024557114,-0.024810791,-0.047729492,0.06677246,-0.030838013,-0.052520752,0.0579834,-0.03805542,-0.010284424,0.06323242,0.04699707,-0.030380249,-0.0010614395,0.0057678223,0.04824829,-0.014038086,0.016036987,-0.026031494,0.02708435,0.05987549,-0.0025463104,0.030838013,-0.046691895,0.041381836,-0.008102417,0.08227539,0.006324768,-0.07458496,-0.058410645,-0.0014505386,0.04196167,-0.014968872,-0.04714966,-0.03579712,-0.085876465,0.013183594,-0.005340576,0.06896973,0.012649536,-0.029388428,-0.11816406,-0.044128418,0.052124023,0.074645996,0.06384277,-0.023330688,0.019119263,-0.0146865845,0.02279663,0.015640259,0.05090332,0.021072388,0.09814453,-0.066711426,0.02671814,-0.027130127,0.038757324,-0.019317627,0.03741455,0.02746582,-0.03463745,0.00001001358,0.01638794,-0.0362854,0.02861023,0.0057754517,0.045562744,0.013206482,-0.010543823,0.03213501,0.044952393,-0.00018644333,-0.0040397644,-0.027236938,-0.026794434,0.004016876,0.016860962,0.0949707,-0.0129852295,0.024124146,-0.06185913,-0.08068848,-0.005054474,0.037353516,0.028411865,0.008850098,0.04940796,0.018356323,0.008979797,0.016098022,0.013702393,-0.03942871,0.03463745,0.006729126,-0.042541504,0.02607727,0.06451416,-0.029632568,-0.029647827,-0.014167786,-0.01675415,-0.0017442703,0.07269287,0.00013709068,-0.044708252,-0.059417725,-0.097839355,0.013648987,-0.0041923523,0.0025196075]'),
  ('An embedding is a numerical representation of data in a high-dimensional space that captures semantic relationships and similarities between entities.', '[0.043701172,0.09063721,-0.24499512,-0.1385498,0.025177002,-0.020385742,0.0074653625,-0.016143799,-0.08294678,-0.03427124,-0.04864502,0.003490448,0.1060791,0.035461426,-0.023712158,0.04220581,-0.016342163,-0.039001465,-0.06008911,0.034362793,-0.048858643,0.023666382,0.012779236,0.012001038,0.057250977,0.038970947,0.08312988,-0.046936035,-0.02229309,0.00674057,0.04751587,-0.015289307,0.0027866364,-0.028762817,-0.043548584,-0.037200928,-0.0045547485,0.09539795,0.026290894,0.018051147,0.0000140070915,-0.002450943,-0.04751587,0.013076782,-0.031982422,-0.0035572052,0.044952393,-0.04220581,0.08660889,-0.037109375,-0.010673523,-0.013221741,-0.015609741,-0.028411865,0.11138916,0.02218628,0.008255005,0.015991211,0.043395996,-0.044189453,0.09460449,0.1005249,-0.06817627,0.09283447,0.0625,0.026916504,-0.097961426,0.05682373,-0.011253357,-0.085510254,0.10241699,-0.010391235,0.03656006,0.028320312,-0.025604248,-0.0149383545,-0.00881958,0.0362854,-0.002401352,0.052734375,0.04220581,0.03640747,0.09686279,-0.040527344,0.09460449,0.045043945,-0.010475159,0.00006771088,-0.06567383,0.060913086,0.016830444,0.009277344,0.02458191,0.05444336,-0.024734497,0.006401062,-0.00166893,0.028289795,-0.033447266,-0.03704834,-0.055389404,-0.01486969,-0.021697998,0.01322937,-0.005695343,0.053649902,-0.000044941902,0.026565552,-0.06561279,0.022399902,-0.022094727,0.015525818,-0.06402588,-0.06585693,-0.0055732727,-0.018295288,0.09020996,-0.07720947,-0.014472961,0.057434082,0.01537323,-0.041870117,0.042419434,0.05392456,0.007080078,0.011199951,-0.020095825,0.007774353,-0.044433594,-0.04031372,-0.016448975,-0.060394287,-0.009780884,0.010131836,0.005207062,0.038879395,-0.048675537,-0.024917603,-0.0069351196,0.08514404,-0.0041885376,-0.015586853,-0.0029888153,-0.0546875,0.008361816,-0.09490967,0.035705566,-0.02935791,0.009742737,-0.015213013,-0.00970459,0.08270264,-0.03753662,-0.045074463,0.01612854,-0.0030441284,0.024749756,0.0041542053,0.064697266,-0.007019043,0.038970947,0.04284668,-0.030029297,0.04623413,0.019699097,-0.074523926,-0.0024147034,0.019836426,0.011489868,0.009597778,-0.04751587,-0.03125,-0.023025513,-0.0064201355,0.0007266998,-0.007888794,0.036834717,-0.068359375,0.056671143,0.006175995,0.021530151,-0.04324341,0.07232666,-0.004169464,-0.025619507,-0.019226074,-0.007259369,-0.01902771,-0.060760498,-0.03161621,-0.055877686,0.012390137,-0.031280518,-0.00705719,-0.019470215,-0.00061893463,0.06774902,-0.034301758,-0.003293991,-0.023925781,-0.007820129,0.011604309,-0.024002075,0.05206299,-0.012214661,0.043304443,-0.04232788,-0.0005931854,-0.050872803,0.04647827,0.06555176,-0.017486572,0.001001358,0.010131836,0.04776001,-0.0076560974,0.0063323975,-0.04147339,-0.02243042,-0.00008791685,0.028717041,-0.01927185,0.039794922,-0.0769043,0.03289795,-0.019439697,-0.03137207,0.047088623,-0.045532227,0.0011854172,-0.03768921,-0.04663086,0.044525146,-0.031173706,0.011817932,0.06109619,-0.01701355,0.06524658,0.006614685,0.037841797,0.018707275,0.053833008,-0.02468872,-0.03387451,-0.02897644,0.05923462,0.024429321,-0.060516357,-0.0435791,0.07159424,-0.04446411,-0.036712646,0.012107849,0.007286072,0.07183838,-0.031829834,-0.047790527,-0.07092285,0.014518738,-0.008964539,0.05621338,-0.017486572,-0.0129470825,-0.036499023,-0.06890869,-0.021835327,0.027175903,-0.007709503,0.02960205,-0.02003479,0.01058197,0.017303467,0.018112183,0.019622803,0.011024475,-0.013412476,0.02229309,-0.012329102,-0.05053711,0.01197052,-0.05316162,-0.018341064,-0.07086182,0.0146865845,-0.018798828,0.021240234,0.036895752,0.020812988,0.025863647,0.031097412,0.037475586,-0.042053223,-0.03768921,0.04321289,-0.00054073334,0.045806885,0.06732178,-0.001572609,0.049682617,-0.064086914,-0.010314941,0.049835205,0.099975586,0.011741638,-0.0135269165,-0.033843994,0.040924072,-0.056121826,0.020202637,-0.04135132,-0.06286621,-0.0056762695,-0.054840088,0.0025749207,-0.0647583,0.051208496,0.027694702,-0.00026249886,0.03201294,-0.07409668,-0.005104065,-0.12463379,0.036010742,-0.031173706,0.0036354065,0.07354736,-0.050201416,0.013839722,-0.01612854,0.021835327,-0.039001465,0.012069702,0.055603027,-0.005886078,-0.034606934,0.017791748,-0.02961731,-0.033721924,0.011795044,0.0029697418,0.08337402,-0.008636475,0.02470398,-0.09301758,0.026794434,0.03869629,-0.061767578,-0.004070282,0.04171753,0.021850586,-0.03186035,0.00680542,0.009895325,-0.032104492,0.022888184,-0.0076675415,0.0440979,-0.00548172,-0.006793976,-0.0138168335,0.060913086,-0.0035152435,-0.02609253,-0.053619385,-0.0090789795,0.012084961,0.03604126,0.040924072,0.020462036,0.031585693,0.0057411194,-0.0006456375,-0.060272217,0.042297363,0.04827881,-0.0340271,-0.087646484,-0.06738281,0.005554199,-0.014373779,-0.017181396,0.03753662,0.015686035,0.005493164,0.037750244,-0.0031909943,0.035125732,0.00712204,0.017791748,0.007865906,0.004673004,-0.015129089,-0.052978516,0.01751709,0.026031494,-0.06939697,-0.018112183,0.010276794,0.03741455,-0.010620117,-0.014030457,-0.066223145,0.0015687943,-0.023376465,-0.0043296814,-0.029556274,-0.008255005,-0.07354736,0.044281006,-0.031341553,-0.0026378632,0.049835205,0.03503418,-0.10040283,0.0003578663,0.039642334,0.037841797,0.040100098,-0.017211914,0.014572144,0.019897461,0.101989746,-0.03503418,0.025268555,0.040802002,-0.015068054,0.006248474,0.0960083,0.016464233,-0.050231934,-0.015098572,0.041625977,0.062927246,0.0340271,-0.034210205,-0.026412964,-0.045013428,-0.0032138824,-0.0058021545,0.07849121,0.009056091,-0.06359863,-0.019699097,-0.016143799,0.016113281,0.12384033,-0.0044937134,-0.01789856,-0.08276367,0.069885254,0.07110596,0.018173218,-0.0017271042,0.033447266,0.12609863,-0.036712646,-0.012878418,-0.042633057,-0.00087690353,-0.00091171265,0.002943039,0.04800415,-0.08984375,0.035003662,-0.004058838,-0.058410645,-0.007270813,-0.07141113,0.068237305,0.10491943,-0.012290955,0.02571106,0.020767212,-0.03253174,0.04916382,0.05633545,-0.008430481,-0.052886963,0.026992798,0.016601562,0.014930725,0.0026130676,-0.07116699,-0.031280518,0.0006713867,0.049682617,0.012771606,0.00046944618,0.034973145,0.02885437,0.020858765,-0.050842285,0.04437256,0.015289307,-0.027572632,-0.11541748,-0.008483887,0.005844116,0.037109375,-0.0057868958,0.03164673,0.06451416,0.000603199,0.004924774,0.053344727,-0.027374268,0.08270264,-0.04724121,-0.11883545,-0.010147095,0.008865356,0.044281006]');

The above SQL command inserts two rows into the embeddings table:

  • Row 1: The text "i like to eat tacos" and its corresponding embedding vector.
  • Row 2: A longer text about embeddings itself: "An embedding is a numerical representation of data in a high-dimensional space that captures semantic relationships and similarities between entities." and its corresponding embedding vector.

The embedding vectors are generated using the Nomic API's nomic-embed-text-v1.5 model with 512 dimensions.

You can then query for which embeddings are closest to a new vector. For example, the following query finds the closest vector to the embedding for "burgers are tasty" using the cosine distance operator <=>.

SELECT content, data <=> '[0.001080513,0.08959961,-0.29296875,0.0014181137,-0.019119263,0.021392822,-0.015617371,0.0345459,-0.0690918,0.009246826,-0.018981934,0.091796875,0.0041160583,0.02947998,-0.021835327,-0.03503418,-0.07702637,-0.07989502,-0.021102905,0.09667969,0.024597168,0.0124053955,0.027420044,-0.039001465,0.10235596,0.008583069,-0.06512451,0.08111572,-0.031982422,0.013595581,0.009635925,-0.036315918,-0.08148193,-0.014015198,0.0082092285,-0.0793457,0.0597229,0.024673462,-0.032440186,-0.047332764,0.0021572113,0.037597656,0.009010315,-0.019104004,0.03967285,0.011817932,0.02178955,0.06695557,0.091308594,-0.020004272,-0.022216797,-0.051361084,-0.031402588,-0.076416016,0.050109863,-0.00223732,0.07714844,0.0385437,0.032440186,0.016860962,0.08496094,0.039123535,-0.026733398,0.044921875,0.034698486,-0.025970459,-0.046142578,0.09326172,-0.030349731,0.022888184,0.06933594,-0.04663086,0.049987793,-0.011802673,-0.015655518,0.013885498,-0.04559326,0.00554657,-0.032836914,-0.007724762,0.013305664,0.01574707,0.0519104,0.024887085,0.044128418,0.010795593,0.055603027,-0.054901123,-0.045837402,0.036468506,0.047302246,0.024810791,0.05645752,0.062805176,-0.07165527,0.027282715,-0.011566162,0.040283203,-0.019454956,-0.04058838,-0.032196045,0.024856567,0.0023899078,0.016921997,0.062316895,0.054748535,0.04498291,0.012550354,-0.0043678284,-0.01309967,0.010169983,0.011619568,-0.022766113,-0.032806396,0.016647339,0.049713135,0.03414917,-0.07495117,0.027526855,0.07147217,0.037597656,-0.015792847,-0.0010890961,0.024108887,0.015419006,0.041870117,-0.035705566,0.015434265,-0.038238525,-0.03668213,-0.0011501312,-0.0234375,0.013130188,-0.054748535,0.010276794,0.074523926,0.015075684,0.01109314,0.047698975,0.0103302,0.03717041,0.030288696,0.0032520294,-0.025756836,-0.019424438,-0.05316162,0.04171753,-0.061798096,-0.014389038,0.039855957,0.003578186,0.018844604,0.032562256,0.04837036,-0.0023269653,-0.08227539,0.0446167,-0.042022705,0.016723633,0.023666382,0.03869629,-0.053985596,0.0029525757,0.052124023,0.024337769,-0.03427124,0.0262146,0.057861328,-0.020095825,0.10736084,-0.08642578,-0.07116699,-0.06298828,-0.039398193,0.0034751892,-0.0927124,-0.03677368,-0.026733398,0.044769287,-0.020767212,-0.02268982,-0.020584106,0.015777588,0.1083374,0.015617371,-0.02407837,-0.009567261,0.03842163,-0.0597229,-0.044799805,-0.013885498,0.045318604,-0.070373535,-0.06274414,-0.02027893,0.015327454,0.060546875,-0.0058174133,0.056396484,-0.04336548,-0.036346436,-0.044036865,-0.08642578,-0.017105103,-0.060516357,0.06915283,-0.027557373,0.068359375,0.010856628,-0.007587433,0.043945312,-0.03378296,0.031951904,-0.044433594,0.009857178,-0.013473511,0.00003117323,-0.004611969,-0.006034851,0.021774292,0.018936157,0.036132812,-0.03555298,-0.014785767,0.057800293,-0.036895752,-0.050323486,-0.020721436,-0.016647339,0.030593872,-0.0025672913,-0.05908203,0.06549072,-0.0019426346,0.009986877,0.022094727,0.053375244,0.09222412,0.025772095,0.033935547,-0.0058135986,0.031402588,-0.00065660477,-0.019119263,-0.05419922,0.029510498,0.022735596,-0.04534912,0.018798828,0.04397583,0.03881836,0.0067596436,0.035339355,0.03378296,0.07281494,-0.037597656,-0.035064697,-0.006439209,0.015007019,-0.07867432,-0.015945435,-0.10491943,0.019180298,-0.04498291,0.0010375977,-0.020828247,-0.045959473,0.0075912476,0.007785797,-0.056365967,0.012489319,-0.01574707,-0.014175415,0.07446289,-0.0058784485,-0.015113831,0.0082473755,0.010566711,-0.026016235,-0.007232666,-0.0340271,-0.04611206,-0.05783081,0.027282715,0.00010895729,0.07336426,0.06262207,0.00085544586,0.011199951,0.018447876,0.023620605,0.016677856,0.0335083,0.057250977,0.0013751984,0.0012817383,0.07122803,-0.030960083,-0.0058670044,-0.079589844,0.031188965,-0.023361206,0.054901123,0.03768921,-0.049957275,0.03604126,0.038604736,-0.022659302,0.085510254,-0.03479004,-0.031951904,0.015419006,-0.024887085,0.025009155,-0.06262207,0.01574707,0.015945435,0.031982422,0.09954834,-0.032714844,0.00178051,-0.046905518,-0.011581421,-0.039367676,-0.013847351,0.028335571,0.012199402,0.024276733,0.010948181,-0.03036499,0.0079956055,0.06933594,0.0062446594,-0.055786133,-0.031677246,0.030548096,0.029815674,0.0021915436,-0.032196045,0.07525635,0.022064209,-0.014625549,0.03717041,-0.02999878,-0.072631836,0.0010557175,-0.07318115,-0.05340576,0.050201416,0.016723633,-0.06274414,0.042419434,-0.004119873,0.014839172,-0.042175293,-0.041503906,0.040527344,-0.03591919,0.036987305,-0.0005173683,0.072265625,-0.021835327,-0.01689148,-0.005054474,-0.03012085,-0.002128601,-0.0046463013,-0.011474609,0.041534424,0.026062012,-0.03286743,-0.024169922,-0.005432129,0.014198303,0.024719238,-0.034698486,-0.13830566,-0.037750244,0.0053977966,-0.015106201,-0.012840271,-0.01802063,-0.004131317,0.0043945312,0.00042247772,0.050933838,-0.015274048,-0.0026550293,-0.012771606,0.024887085,-0.012039185,0.014595032,-0.06744385,0.039398193,0.035858154,-0.049957275,0.084106445,-0.014602661,0.009880066,0.04208374,-0.0637207,-0.07525635,-0.015319824,-0.052612305,-0.0031909943,0.038116455,-0.019561768,-0.054351807,0.020751953,-0.024337769,-0.0069236755,0.04043579,0.061676025,-0.052978516,-0.0061302185,0.022094727,0.03894043,-0.03213501,-0.026260376,-0.03050232,0.019104004,0.06640625,0.0076293945,0.040527344,-0.0357666,0.007484436,0.008728027,0.09289551,-0.02178955,-0.07244873,-0.009490967,0.014511108,-0.0084991455,0.0057640076,-0.02168274,0.008926392,-0.084350586,-0.008476257,0.009986877,0.09112549,0.05078125,-0.08001709,-0.046722412,-0.050933838,0.04296875,0.09881592,0.072631836,-0.09197998,0.0047340393,-0.025939941,0.048919678,0.017501831,-0.0037174225,0.046661377,0.13549805,-0.08215332,0.0181427,-0.015930176,0.022705078,0.004009247,-0.030014038,0.014945984,-0.04776001,-0.008041382,-0.054473877,-0.042633057,0.037994385,-0.012489319,0.051116943,0.06933594,0.01612854,0.07757568,0.047698975,-0.019378662,-0.019744873,0.0015363693,-0.021011353,0.0021209717,0.07318115,0.061920166,0.026687622,-0.024475098,-0.027694702,-0.07867432,-0.02645874,0.02218628,0.007041931,-0.018508911,0.05105591,-0.01612854,-0.0007419586,0.018554688,0.025772095,0.0012435913,-0.010955811,-0.024887085,-0.088012695,0.0077705383,0.056915283,-0.011207581,0.0073928833,-0.011749268,-0.0021152496,-0.008453369,-0.019515991,0.020965576,0.042022705,-0.08166504,-0.07745361,0.009712219,-0.03048706,0.026046753]' as distance
FROM embeddings
ORDER BY distance ASC

You should see the following output:

contentdistance
i like to eat tacos0.25041233062525814
An embedding is a numerical representation of data in a high-dimensional space that captures semantic relationships and similarities between entities.0.4526167402866883

Unsurprisingly, Postgres finds that the embedding for "i like to eat tacos" is the closest to the embedding for "burgers are tasty".

Resources