Skip to main content

CohereEmbeddings

This will help you get started with Cohere embedding models using LangChain. For detailed documentation on CohereEmbeddings features and configuration options, please refer to the API reference.

Overviewโ€‹

Integration detailsโ€‹

ProviderPackage
Coherelangchain-cohere

Setupโ€‹

To access Cohere embedding models you'll need to create a/an Cohere account, get an API key, and install the langchain-cohere integration package.

Credentialsโ€‹

Head to cohere.com to sign up to Cohere and generate an API key. Once youโ€™ve done this set the COHERE_API_KEY environment variable:

import getpass
import os

if not os.getenv("COHERE_API_KEY"):
os.environ["COHERE_API_KEY"] = getpass.getpass("Enter your Cohere API key: ")

If you want to get automated tracing of your model calls you can also set your LangSmith API key by uncommenting below:

# os.environ["LANGCHAIN_TRACING_V2"] = "true"
# os.environ["LANGCHAIN_API_KEY"] = getpass.getpass("Enter your LangSmith API key: ")

Installationโ€‹

The LangChain Cohere integration lives in the langchain-cohere package:

%pip install -qU langchain-cohere

[notice] A new release of pip is available: 24.0 -> 24.2
[notice] To update, run: python -m pip install --upgrade pip
Note: you may need to restart the kernel to use updated packages.

Instantiationโ€‹

Now we can instantiate our model object and generate chat completions:

from langchain_cohere import CohereEmbeddings

embeddings = CohereEmbeddings(
model="embed-english-v3.0",
)
API Reference:CohereEmbeddings
embeddings.embed_documents(["h", "b"])
[[0.0028572083,
0.015930176,
-0.02935791,
-0.06213379,
0.017105103,
-0.0024280548,
-0.043701172,
0.0054473877,
0.021759033,
0.045288086,
-0.037963867,
-0.022506714,
0.03427124,
-0.029769897,
0.030563354,
-0.01537323,
0.001830101,
0.025558472,
-0.026947021,
-0.028076172,
-0.03463745,
-0.029205322,
-0.032958984,
-0.0022850037,
0.022888184,
0.0096206665,
-0.02507019,
-0.028717041,
-0.002216339,
-0.027267456,
-0.011619568,
0.025115967,
0.032073975,
0.005722046,
-0.004737854,
0.031707764,
-0.034698486,
-0.018005371,
-0.0030460358,
-0.0027198792,
-0.016723633,
0.017730713,
-0.07244873,
-0.015914917,
-0.111816406,
-0.042144775,
-0.031829834,
0.030212402,
0.012664795,
0.04498291,
0.013641357,
-0.006713867,
-0.008171082,
0.0647583,
-0.010322571,
-0.0022773743,
-0.017333984,
-0.014122009,
-0.0064468384,
-0.0035114288,
-0.015625,
-0.0011920929,
0.049682617,
0.049957275,
-0.022613525,
-0.022033691,
0.022354126,
0.017303467,
0.0065345764,
-0.032165527,
-0.0027770996,
0.0046157837,
0.01914978,
-0.012039185,
0.0011959076,
-0.028427124,
0.04751587,
0.037719727,
-0.01626587,
-0.0031280518,
-0.04675293,
-0.010620117,
-0.038116455,
0.019470215,
-0.019302368,
0.050628662,
-0.009788513,
-0.058502197,
0.02204895,
-0.019241333,
-0.016143799,
0.045013428,
0.06402588,
0.027496338,
-0.061340332,
0.029434204,
-0.014175415,
-0.007980347,
-0.022750854,
0.00856781,
-0.0077056885,
-0.027923584,
-0.031555176,
-0.020980835,
-0.0079574585,
0.042114258,
-0.02218628,
-0.0007224083,
0.028839111,
0.040008545,
0.0051116943,
0.0335083,
0.00012886524,
0.016937256,
-0.019607544,
0.025161743,
0.031829834,
0.003835678,
-0.009750366,
0.0335083,
0.047821045,
0.0423584,
0.022445679,
-0.03326416,
-0.032043457,
-0.008361816,
-0.03567505,
-0.05038452,
0.032104492,
-0.047729492,
-0.0065574646,
0.04977417,
-0.115356445,
-0.021514893,
-0.032592773,
0.023849487,
-0.010597229,
-0.057739258,
-0.012420654,
0.024734497,
0.0096206665,
-0.011932373,
0.050445557,
-0.018997192,
-0.042877197,
0.015220642,
0.01259613,
-0.020736694,
-0.012184143,
-0.0101623535,
-0.041625977,
-0.046661377,
0.025268555,
0.026535034,
-0.022216797,
0.04724121,
-0.048187256,
0.015670776,
-0.02545166,
0.01108551,
-0.00057029724,
-0.012588501,
0.0063934326,
-0.049591064,
-0.029418945,
0.04067993,
-0.029342651,
0.029449463,
0.02180481,
0.068725586,
-0.025939941,
-0.007461548,
0.021820068,
0.0184021,
-0.01424408,
0.01576233,
0.006378174,
-0.038208008,
0.0390625,
0.05770874,
0.0029125214,
-0.030014038,
-0.015388489,
0.074645996,
-0.033813477,
-0.016616821,
0.004497528,
-0.021835327,
0.01020813,
0.0020923615,
0.024490356,
0.014152527,
-0.026779175,
-0.028671265,
-0.029464722,
-0.04537964,
0.009483337,
-0.017150879,
-0.014671326,
0.06188965,
0.017456055,
-0.003271103,
0.011375427,
-0.040252686,
-0.020446777,
-0.010520935,
0.0068130493,
0.022018433,
0.03704834,
0.05050659,
-0.0079422,
0.008102417,
-0.02268982,
-0.010353088,
-0.032104492,
-0.023254395,
-0.06097412,
0.028457642,
-0.0079956055,
0.06719971,
0.023651123,
-0.02330017,
0.00082063675,
0.02583313,
0.011634827,
-0.0010271072,
-0.021743774,
-0.0060195923,
0.013313293,
-0.0012722015,
0.019515991,
0.014137268,
0.05340576,
0.05142212,
-0.027511597,
-0.0152282715,
0.03086853,
0.04046631,
0.0066223145,
0.0049934387,
0.004776001,
-0.012176514,
0.0037765503,
0.0206604,
0.007041931,
0.010635376,
0.02557373,
0.005443573,
0.0075149536,
-0.0054359436,
0.048065186,
0.011878967,
0.045562744,
0.0030612946,
0.008171082,
0.07159424,
0.009086609,
0.03265381,
-0.054229736,
0.021362305,
-0.014671326,
0.0007405281,
-0.034301758,
-0.0032291412,
-0.051208496,
0.008598328,
-0.026855469,
0.026657104,
0.008125305,
-0.0034675598,
0.009170532,
-0.020706177,
-0.012878418,
-0.003124237,
0.029266357,
0.002571106,
-0.024658203,
-0.017227173,
-0.0034046173,
-0.024932861,
-0.007774353,
0.026748657,
5.364418e-07,
0.013626099,
0.023513794,
0.018692017,
-0.007419586,
0.0039901733,
0.0036201477,
0.04876709,
0.065979004,
0.029922485,
0.018554688,
0.015792847,
0.05050659,
0.046875,
0.04135132,
0.005115509,
0.007461548,
-0.020889282,
0.02973938,
0.050567627,
0.0067710876,
-0.011054993,
0.0047302246,
0.023254395,
0.019577026,
0.026550293,
0.020141602,
-0.012237549,
0.0027656555,
0.0054473877,
0.0039253235,
-0.027023315,
-0.002872467,
-0.04724121,
-0.008872986,
-0.009727478,
-0.064941406,
-0.017730713,
0.025024414,
0.0026359558,
-0.057037354,
-0.0038585663,
0.018112183,
-0.025222778,
-0.027999878,
-0.03390503,
-0.054718018,
0.00617218,
0.04763794,
-0.016723633,
0.011787415,
-0.036987305,
0.0096206665,
-0.008079529,
0.0017185211,
-0.03933716,
-0.024871826,
0.019546509,
0.015449524,
0.013969421,
0.05404663,
-0.03302002,
-0.055541992,
-0.0057373047,
-0.017684937,
0.023971558,
-0.043426514,
-0.023544312,
0.04626465,
-0.03967285,
-0.058563232,
-0.014671326,
0.049743652,
-0.009262085,
0.03652954,
0.043151855,
0.10961914,
-0.024276733,
-0.0011787415,
-0.026504517,
-0.053894043,
0.0069503784,
0.02986145,
-0.008049011,
-0.0020771027,
-0.009498596,
-0.026565552,
0.017456055,
-0.022857666,
-0.023757935,
-0.009460449,
-0.008651733,
-0.047546387,
0.048553467,
-0.04067993,
-0.06976318,
0.020950317,
-0.017181396,
0.00029063225,
0.013786316,
0.046844482,
-0.03201294,
0.06427002,
-0.0062408447,
-0.006614685,
0.0072746277,
0.093933105,
0.036193848,
-0.0024547577,
-0.022262573,
0.0040016174,
0.008369446,
-0.03604126,
-0.0033302307,
0.0061950684,
-0.019958496,
-0.054595947,
-0.006969452,
0.031555176,
-0.0026283264,
-0.041931152,
-0.004837036,
-0.07147217,
0.021896362,
-0.01448822,
-0.031311035,
0.026870728,
0.04647827,
-0.050628662,
0.10809326,
-0.04751587,
0.037384033,
-0.013580322,
0.0049324036,
-0.009056091,
0.033294678,
-0.0004901886,
0.026550293,
-0.005870819,
0.0047950745,
-0.022857666,
0.007911682,
-0.011985779,
0.05429077,
-0.012161255,
0.03552246,
0.034210205,
-0.038482666,
-0.039978027,
-0.029327393,
-0.019592285,
-0.026351929,
-0.04119873,
0.008773804,
-0.018539429,
0.042633057,
0.0028209686,
-0.032928467,
-0.032196045,
0.028900146,
0.025009155,
0.00092315674,
0.008300781,
-0.0067825317,
0.04449463,
-0.022369385,
-0.030136108,
0.031799316,
-0.04159546,
-0.005054474,
-0.028244019,
0.034088135,
-0.03488159,
0.066589355,
0.02508545,
0.0023441315,
0.021896362,
0.028045654,
0.02784729,
0.0012083054,
-0.045043945,
-0.01737976,
-0.02053833,
0.022903442,
0.010765076,
0.024810791,
-0.045166016,
-0.016555786,
0.022659302,
0.017669678,
0.05178833,
0.0010061264,
0.053344727,
0.03640747,
-0.07293701,
-0.038970947,
-0.018447876,
0.05886841,
0.008407593,
0.0072288513,
-0.015899658,
-0.0960083,
-0.055725098,
0.013084412,
-0.103027344,
-0.0071792603,
-0.015197754,
-0.0045166016,
-0.07244873,
0.0029659271,
0.034698486,
-0.084228516,
-0.031829834,
-0.0056037903,
-0.006160736,
-0.07281494,
0.019699097,
-0.03527832,
-0.058929443,
0.0211792,
0.030014038,
-0.038513184,
0.012329102,
-0.035125732,
-0.037017822,
0.01927185,
0.06976318,
-0.013053894,
0.022598267,
-0.0043182373,
0.06573486,
0.03277588,
-0.028686523,
0.05831909,
-0.007003784,
0.051513672,
-0.01890564,
-0.010017395,
0.039520264,
0.05230713,
0.022979736,
-0.0062217712,
0.019866943,
0.055358887,
-0.022857666,
0.038635254,
-0.006832123,
-0.038635254,
0.04598999,
-0.0047035217,
0.012420654,
0.029449463,
-0.007286072,
0.05682373,
-0.009811401,
0.006099701,
0.0053367615,
-0.031463623,
0.007286072,
0.008415222,
-0.0090408325,
-0.020095825,
0.0070877075,
-0.019561768,
0.012832642,
0.052520752,
-0.011459351,
0.04360962,
0.010063171,
-0.007484436,
0.010253906,
0.048583984,
0.03781128,
-0.05908203,
-0.06384277,
-0.017150879,
-0.031402588,
0.024490356,
0.02218628,
-0.003982544,
-0.005794525,
-0.027740479,
0.008972168,
-0.01953125,
0.048675537,
-0.008239746,
-0.009422302,
-0.012069702,
-0.024505615,
-0.008514404,
0.026885986,
-0.07513428,
0.00573349,
-0.019805908,
0.02407837,
-0.005882263,
0.011581421,
0.0035991669,
-0.016860962,
0.026443481,
-0.006252289,
0.011428833,
-0.0069885254,
-0.04550171,
0.039978027,
-0.08087158,
-0.020767212,
-0.007637024,
0.07946777,
-0.025283813,
-0.001364708,
0.016693115,
0.03656006,
-0.016860962,
0.07019043,
-0.06274414,
-0.019378662,
-0.0058021545,
-0.013786316,
0.014953613,
0.0093688965,
-0.012504578,
-0.05380249,
0.052215576,
0.016708374,
0.038208008,
0.01398468,
-0.0073890686,
0.023406982,
-0.004333496,
-0.019180298,
0.046722412,
-0.006801605,
-0.03933716,
0.04711914,
0.009056091,
0.013801575,
0.017318726,
-0.0096588135,
0.011734009,
0.040618896,
-0.006893158,
0.033355713,
-0.05581665,
0.038848877,
0.026657104,
0.014122009,
0.0055351257,
-0.0029411316,
0.009292603,
-0.024841309,
-0.075805664,
-0.020736694,
0.076660156,
-0.041168213,
-0.042510986,
-0.03781128,
0.070129395,
-0.00598526,
-0.0019512177,
0.008598328,
-0.023513794,
0.015365601,
-0.059906006,
0.0061950684,
0.016586304,
-0.019134521,
-0.017807007,
-0.028549194,
0.02798462,
0.029830933,
-0.011627197,
0.041900635,
-0.023483276,
-0.002779007,
0.06341553,
-0.02822876,
-0.025421143,
0.00881958,
0.0496521,
-0.01889038,
-0.008346558,
0.03652954,
-0.0058288574,
0.055541992,
0.028015137,
0.0033550262,
-0.021881104,
-0.0053100586,
0.006160736,
-0.003446579,
-0.005168915,
-0.022277832,
0.030548096,
0.020584106,
0.012069702,
0.0014572144,
0.01687622,
-0.02067566,
-0.07885742,
0.0034484863,
0.015075684,
-0.030303955,
-0.020553589,
0.003414154,
0.032836914,
0.0015439987,
-0.009712219,
-0.082458496,
-0.040496826,
-0.0024108887,
-0.05130005,
-0.032592773,
0.0014181137,
-0.004875183,
-0.025970459,
0.022262573,
0.0046958923,
0.05255127,
-0.032470703,
0.013687134,
-0.021774292,
0.0039863586,
0.005138397,
-0.035461426,
-0.008262634,
-0.059051514,
0.01927185,
-0.0093688965,
0.03604126,
-0.052215576,
-0.03366089,
-0.015571594,
-0.0024204254,
0.026107788,
-0.0037174225,
0.013389587,
-0.025939941,
-0.008003235,
-0.042266846,
0.009101868,
0.018859863,
0.035308838,
0.00019907951,
-0.050872803,
0.0079193115,
-0.0041389465,
-0.0061798096,
0.033111572,
-0.04034424,
-0.0029315948,
-0.0032234192,
-0.024978638,
-0.0670166,
-0.0062217712,
-0.0015144348,
-0.030593872,
0.031707764,
-0.017791748,
-0.003004074,
0.03060913,
0.030136108,
-0.00071048737,
0.04525757,
0.0005903244,
0.040893555,
-0.034057617,
0.0069389343,
-0.013198853,
-0.013175964,
-0.007129669,
0.020889282,
-0.028564453,
0.00023853779,
0.023544312,
-0.0050582886,
-0.010261536,
-0.012283325,
-0.027053833,
-0.010604858,
-0.019546509,
0.016921997,
0.027877808,
0.03643799,
-0.020263672,
0.024932861,
0.036071777,
0.0041503906,
0.061828613,
0.021850586,
0.014480591,
-0.02734375,
-0.03677368,
0.037139893,
0.0007696152,
-0.020401001,
-0.002729416,
-0.02166748,
0.019119263,
-0.02130127,
0.0012197495,
0.01260376,
-0.0131073,
-0.01473999,
0.039733887,
0.008926392,
-0.028961182,
-0.0059165955,
-0.009780884,
0.07550049,
0.004436493,
0.016143799,
0.059051514,
0.0042381287,
0.0112838745,
0.0040779114,
0.024902344,
-0.025665283,
0.020523071,
-0.018554688,
0.028808594,
0.010810852,
-0.029083252,
0.019348145,
-0.026184082,
0.047180176,
0.018692017,
0.02420044,
0.01776123,
-0.02229309,
-0.03161621,
0.020690918,
0.020095825,
0.05026245,
0.052825928,
-0.027801514,
0.038909912,
-0.028289795,
-0.011764526,
0.07318115,
0.03704834,
-0.04159546,
-0.035064697,
0.048431396,
0.031829834,
-0.039367676,
0.008476257,
0.023345947,
0.035949707,
-0.0019168854,
-0.0066719055,
0.031585693,
0.039245605,
-0.013580322,
0.00655365,
-0.045928955,
0.03161621,
-0.0041122437,
0.021331787,
-0.015312195,
0.03390503,
0.030273438,
-0.034973145,
0.038238525,
0.015052795,
-0.013908386,
0.026916504,
0.007167816,
0.07043457,
0.010368347,
-0.021118164,
-0.008613586,
0.045196533,
0.0104904175,
0.056030273,
-0.0418396,
0.0042495728,
-0.0012893677,
0.011917114,
0.035583496,
0.002588272,
-0.023132324,
0.041992188,
0.022781372,
-0.030517578,
0.006565094,
-0.037017822,
0.03881836,
0.038909912,
0.006801605,
-0.008758545,
0.012046814,
-0.017471313,
0.027542114,
0.00087213516,
-0.019348145,
0.04437256,
-0.00617218,
-0.036956787,
0.026565552,
0.031082153,
0.009681702,
-0.011047363,
-0.05935669,
-0.018615723,
0.024902344,
0.017837524,
0.006416321,
0.046966553,
-0.033050537,
-0.0058403015,
0.03149414,
-0.06011963,
-0.018081665,
-0.049926758,
-0.009986877,
-0.043060303,
0.020874023,
-0.041168213,
-0.024429321,
-0.00038290024,
-0.047027588,
0.0340271,
-0.00856781,
0.01525116,
-0.00970459,
-0.0028133392,
-0.059783936,
0.044311523,
-0.015548706,
0.013824463,
0.016082764,
-0.028930664,
-0.0074882507,
-0.064941406,
-0.01739502,
-0.00065517426,
0.005630493,
-0.052764893,
-0.005580902,
-0.0068626404,
0.0027008057,
-0.035064697,
0.01689148,
-0.05895996,
-0.032287598,
0.036621094,
-0.029159546,
-0.012275696,
-0.0028133392,
0.028884888,
0.02659607,
0.04977417,
-0.026306152,
0.034942627,
-0.008613586,
-0.0024147034,
-0.012290955,
-0.008804321,
0.0031795502,
0.0025577545,
-0.00015699863,
-0.030136108,
0.026885986,
-0.0284729,
-0.033966064,
-0.01159668,
0.0008702278,
0.043914795,
-0.035186768,
-0.07171631,
0.024627686,
-0.012756348,
0.029571533,
-0.03881836,
-0.046447754,
0.009559631,
0.043304443,
0.02243042,
0.044677734,
-0.0068206787,
-0.008049011,
-0.06402588,
0.015823364,
-0.027572632,
-0.00065135956,
0.006210327,
-0.0049858093,
0.019973755,
-0.007888794,
-0.041900635,
0.029434204,
0.029953003,
-0.039245605,
0.009498596,
0.006980896,
-0.033111572,
0.004558563,
-0.0065841675,
0.04071045,
0.014389038,
0.041748047,
-0.016189575,
0.041931152,
-0.033996582,
-0.02027893,
0.031066895,
-0.01550293,
-0.051483154,
0.0002156496,
-0.032562256,
-0.033111572,
0.030014038,
0.009513855,
0.012870789,
-0.024017334,
-0.0027999878,
0.020828247,
...],
[0.005279541,
-0.011100769,
-0.03100586,
-0.062408447,
0.055603027,
-0.0082473755,
-0.028884888,
-0.0073928833,
0.0287323,
0.005592346,
-0.02406311,
0.046966553,
-0.0440979,
-0.014083862,
0.00756073,
0.004085541,
-0.010627747,
0.0071907043,
-0.021774292,
-0.03555298,
-0.02458191,
-0.043518066,
-0.002002716,
0.012878418,
0.010467529,
-0.005771637,
-0.03768921,
0.016326904,
-0.04446411,
0.004219055,
-0.006790161,
0.06210327,
0.02798462,
0.013404846,
0.013725281,
-0.016113281,
-0.03817749,
0.0017538071,
-0.01626587,
0.018157959,
0.00090789795,
0.009986877,
-0.0758667,
-0.029800415,
-0.10449219,
-0.022888184,
-0.046325684,
0.00094509125,
0.031311035,
0.016525269,
0.037353516,
-0.040924072,
-0.018951416,
0.04119873,
-0.02368164,
0.014427185,
-0.00983429,
0.009010315,
0.003944397,
0.03756714,
0.003353119,
-0.02532959,
0.05142212,
0.0034103394,
-0.051208496,
0.0064964294,
0.013534546,
0.016189575,
0.03366089,
-0.012519836,
-0.026428223,
0.019165039,
0.006137848,
-0.027526855,
0.0024547577,
0.005836487,
0.060028076,
0.059326172,
-0.016494751,
0.020690918,
-0.017608643,
-0.038513184,
-0.022369385,
-0.034210205,
-0.0088272095,
-0.01676941,
0.0068244934,
-0.032073975,
0.009429932,
-0.06347656,
-0.022216797,
0.058410645,
-0.036224365,
0.01979065,
-0.033599854,
0.01499939,
-0.0030174255,
0.05142212,
-0.050445557,
-0.03439331,
0.0034809113,
-0.0035152435,
-0.04071045,
0.008094788,
-0.002735138,
0.02619934,
-0.004173279,
-0.0009441376,
-0.011680603,
0.05319214,
0.009651184,
0.0146102905,
0.008483887,
-0.027160645,
-0.021194458,
-0.0020809174,
-0.023971558,
0.03173828,
0.034973145,
0.021987915,
-0.0043907166,
-0.0040359497,
0.020645142,
-0.03866577,
-0.00082731247,
0.009811401,
-0.024536133,
-0.009819031,
0.004558563,
-0.0115737915,
-0.0044517517,
0.011886597,
-0.11450195,
-0.06903076,
-0.06323242,
0.031341553,
0.0010623932,
-0.018966675,
-0.03225708,
0.044281006,
-0.013153076,
-0.022918701,
0.00945282,
-0.02772522,
-0.012031555,
0.0067825317,
0.046936035,
-0.017456055,
-0.05014038,
-0.010429382,
-0.026412964,
0.008636475,
0.03781128,
0.026031494,
-0.060058594,
0.039642334,
-0.13256836,
0.026947021,
-0.031082153,
0.02607727,
0.011367798,
0.0032539368,
-0.0022716522,
-0.04156494,
0.052581787,
0.005252838,
-0.07879639,
0.04550171,
0.027191162,
0.029968262,
-0.020126343,
-0.0004284382,
0.0028247833,
0.0008378029,
-0.017562866,
0.0012960434,
0.075805664,
0.0011138916,
0.052459717,
0.01889038,
-0.03640747,
-0.022644043,
0.066467285,
0.050964355,
-0.0021533966,
-0.025756836,
0.025878906,
-0.013442993,
0.02218628,
0.032470703,
-0.03781128,
-0.007911682,
-0.03164673,
-0.0692749,
-0.02130127,
-0.011993408,
0.023895264,
0.021347046,
-0.01977539,
0.040649414,
-0.0035705566,
-0.008842468,
0.032287598,
-0.008781433,
0.021957397,
-0.0018177032,
-0.02041626,
0.035491943,
0.009185791,
0.036010742,
0.014892578,
-0.014091492,
-0.029006958,
0.023712158,
-0.026611328,
-0.029464722,
-0.0025520325,
0.0050086975,
0.018676758,
0.04385376,
0.030685425,
-0.028656006,
0.0031833649,
0.044921875,
0.007019043,
0.0051193237,
-0.025939941,
-0.024612427,
0.005897522,
0.017822266,
0.02520752,
0.009773254,
0.036712646,
0.0015420914,
-0.04345703,
-0.029937744,
0.011802673,
0.040252686,
0.0074539185,
-0.006290436,
0.008590698,
-0.023956299,
-0.013343811,
0.030456543,
-0.017547607,
-0.011016846,
0.0076446533,
0.008384705,
0.03918457,
0.021316528,
0.068237305,
0.017868042,
0.08270264,
-0.012382507,
0.0002259016,
0.10076904,
-0.0066184998,
0.01448822,
-0.0087509155,
0.023040771,
-0.04067993,
0.014945984,
-0.01083374,
0.014175415,
-0.05102539,
0.019683838,
-0.01675415,
0.0027637482,
0.016204834,
0.011550903,
0.027557373,
0.007396698,
0.0058250427,
0.007896423,
0.005756378,
0.0011634827,
0.011360168,
-0.018981934,
0.01751709,
-0.027374268,
-0.05014038,
-0.012489319,
0.018417358,
0.022323608,
0.00025725365,
0.037200928,
0.02178955,
-0.012901306,
0.02545166,
-0.029418945,
0.041534424,
0.0067749023,
0.020965576,
-0.004383087,
-0.0129470825,
-0.006542206,
0.07232666,
0.07373047,
-0.034179688,
0.034301758,
-0.012916565,
0.030288696,
0.022460938,
-0.054138184,
0.004184723,
0.050048828,
-0.002243042,
0.0259552,
-0.03164673,
-0.03930664,
-0.018707275,
0.028305054,
-0.015914917,
-0.052947998,
0.0040740967,
-0.04937744,
-0.0048103333,
-0.022827148,
-0.021453857,
0.0019187927,
0.017196655,
-0.014945984,
-0.07611084,
-0.023834229,
0.0005040169,
-0.022216797,
-0.009063721,
-0.04888916,
-0.044281006,
0.007888794,
0.06665039,
0.01512146,
0.02909851,
-0.047698975,
-0.0032539368,
-0.037597656,
-0.009361267,
0.017120361,
-0.027191162,
0.031707764,
0.052124023,
-0.021530151,
0.036834717,
-0.030151367,
0.0023460388,
-0.039093018,
0.0007839203,
0.053009033,
-0.00024044514,
-0.019012451,
0.023605347,
-0.030838013,
-0.042755127,
0.040405273,
0.076660156,
-0.040039062,
-0.009277344,
0.018325806,
0.07476807,
-0.04876709,
-0.003921509,
0.0033035278,
-0.04095459,
-0.04446411,
-0.003993988,
-0.014465332,
0.009841919,
-0.009735107,
-0.011268616,
0.06524658,
-0.019424438,
-0.028152466,
0.008430481,
0.007297516,
-0.022567749,
0.012680054,
0.009674072,
-0.04815674,
-0.018814087,
-1.7642975e-05,
-0.017822266,
0.023117065,
0.0012245178,
-4.351139e-06,
0.055511475,
0.002943039,
-0.026473999,
-0.0074501038,
0.055664062,
0.0076560974,
-0.020141602,
-0.011505127,
-0.032196045,
0.020446777,
-0.0071983337,
0.022338867,
0.0029754639,
-0.028381348,
-0.12237549,
-0.041412354,
0.033050537,
0.013214111,
-0.017074585,
-0.020187378,
-0.053710938,
0.03366089,
0.009017944,
-0.011352539,
0.04852295,
0.06210327,
-0.02079773,
0.07006836,
-0.015037537,
-8.517504e-05,
-0.006713867,
0.015174866,
-0.055786133,
0.034576416,
-0.012107849,
-0.0009713173,
-0.009376526,
-0.008987427,
-0.025939941,
0.027999878,
0.00077581406,
0.012870789,
0.014297485,
0.058135986,
0.0011892319,
-0.03125,
-0.02017212,
-0.02532959,
-0.040161133,
-0.0002529621,
-0.026535034,
-0.019042969,
-0.033325195,
0.019592285,
-0.016860962,
-0.014633179,
-7.7307224e-05,
-0.02784729,
0.0039100647,
-0.017608643,
0.025482178,
0.0025234222,
0.023529053,
0.027313232,
-0.07019043,
-0.008880615,
-0.023010254,
0.014953613,
-0.01890564,
0.03366089,
-0.003692627,
0.048339844,
0.011009216,
-0.019210815,
0.030929565,
0.023849487,
-0.0034637451,
0.01386261,
-0.054382324,
-0.012420654,
0.017196655,
0.007545471,
0.034820557,
0.0012159348,
-0.020050049,
0.022033691,
-0.024490356,
0.03881836,
0.02684021,
-0.0038280487,
0.041381836,
0.0647583,
-0.04537964,
-0.021499634,
-0.07122803,
0.030227661,
0.054748535,
-0.015464783,
0.021026611,
-0.04852295,
-0.03314209,
0.01260376,
-0.12261963,
-0.016571045,
-0.028305054,
-0.030914307,
-0.08746338,
-0.016921997,
0.022720337,
-0.059753418,
-0.043884277,
0.01927185,
-0.010215759,
-0.062805176,
0.0011644363,
-0.02607727,
-0.092163086,
0.023422241,
0.022079468,
-0.010032654,
0.02067566,
-0.009880066,
-0.03086853,
0.00381279,
0.048614502,
-0.0028858185,
0.01852417,
-0.03149414,
0.026870728,
0.0113220215,
-0.03363037,
0.008125305,
0.026504517,
0.017456055,
-0.020401001,
-0.011642456,
0.01108551,
0.0140686035,
0.03491211,
-0.007709503,
0.00554657,
0.01965332,
0.0011415482,
0.0031032562,
-0.015640259,
0.01133728,
0.018737793,
-0.008956909,
0.03567505,
0.0039253235,
0.02748108,
0.042236328,
-0.031433105,
0.014762878,
0.040130615,
-0.03302002,
-0.023666382,
-0.034576416,
-0.0035209656,
0.009254456,
-0.031677246,
-0.0068511963,
-0.016494751,
0.0062179565,
-0.045684814,
-0.012954712,
0.010917664,
0.0025482178,
-0.010978699,
0.035827637,
0.005683899,
-0.0395813,
-0.040771484,
0.002532959,
-0.006160736,
-0.002571106,
0.041748047,
-0.032836914,
0.01637268,
-0.022476196,
0.024673462,
-0.022262573,
0.014167786,
-0.018630981,
0.015022278,
-0.04269409,
0.020370483,
-0.025009155,
0.010856628,
-0.047668457,
-0.03817749,
0.006160736,
0.03189087,
-0.014625549,
-0.022644043,
0.017227173,
0.05456543,
0.07574463,
-0.043914795,
0.048797607,
-0.020889282,
-0.011482239,
0.034210205,
-0.038909912,
-0.0095825195,
-0.022094727,
0.028564453,
-0.040618896,
0.009567261,
-0.0287323,
0.05419922,
0.0027618408,
0.07824707,
-0.0064086914,
0.018066406,
0.01373291,
-0.0038394928,
-0.009391785,
0.001376152,
-0.020431519,
-0.04788208,
0.03942871,
0.03353882,
0.024749756,
-0.029891968,
7.075071e-05,
0.013206482,
-0.015220642,
0.01436615,
-0.0007843971,
0.010482788,
-0.011756897,
0.020904541,
0.033966064,
-0.05291748,
-0.020309448,
-0.034088135,
-0.002986908,
0.023834229,
-0.051239014,
0.016281128,
-0.020385742,
0.007888794,
-0.009223938,
-0.050842285,
0.0032978058,
-0.053649902,
0.027175903,
-0.04840088,
-0.04058838,
-0.0036449432,
0.0758667,
-0.06695557,
-0.020019531,
-0.008163452,
0.05355835,
-0.011497498,
0.032562256,
0.023376465,
0.02406311,
-0.0001347065,
-0.07342529,
-0.0016431808,
0.02758789,
-0.034301758,
0.016189575,
-0.023590088,
0.044891357,
0.012863159,
0.0055160522,
0.045928955,
0.0033550262,
0.00025177002,
0.009719849,
-0.02166748,
-0.06274414,
-0.022766113,
0.023544312,
-0.017089844,
0.0044937134,
-0.020614624,
0.01411438,
0.01979065,
0.07086182,
-0.034851074,
0.04244995,
-0.0063972473,
-0.02293396,
-0.0524292,
-0.03262329,
-0.018722534,
0.0015068054,
0.01687622,
0.027069092,
-0.021957397,
-0.027999878,
0.008392334,
-0.028152466,
0.011672974,
0.025756836,
-0.037078857,
-0.011100769,
-0.011924744,
-0.006855011,
0.009925842,
-0.014968872,
-0.030715942,
-0.0019273758,
-0.009468079,
-0.05606079,
0.0002861023,
0.019454956,
-0.022216797,
-0.054901123,
0.0053482056,
-0.009635925,
0.016403198,
-0.0209198,
0.019012451,
-0.038116455,
0.03253174,
0.008544922,
-0.0070991516,
-0.024734497,
-0.027511597,
0.010932922,
0.037200928,
0.05291748,
-0.0052833557,
-0.013504028,
-0.015235901,
-0.06359863,
-0.010223389,
-0.027893066,
-0.021820068,
-0.032562256,
-0.0082473755,
-0.031585693,
0.025527954,
0.0057144165,
0.0340271,
-0.017501831,
-0.036468506,
0.017944336,
0.02015686,
0.0036945343,
0.027572632,
0.01676941,
0.0058403015,
-0.010177612,
0.01612854,
-0.038360596,
0.011314392,
0.033050537,
-0.022094727,
-0.024642944,
-0.07519531,
0.00061035156,
0.01878357,
0.0023899078,
-0.0035076141,
0.029769897,
0.00054359436,
0.003692627,
0.0022525787,
0.02796936,
0.015899658,
0.0021247864,
-0.010498047,
0.028717041,
-0.0004696846,
0.010543823,
0.0390625,
-0.022247314,
-0.043701172,
-0.02696228,
-0.014663696,
-0.019515991,
-0.02458191,
-0.0038776398,
0.029846191,
0.03970337,
-0.0146484375,
-0.013397217,
0.025054932,
-0.014190674,
0.041137695,
0.030136108,
0.013542175,
-0.01713562,
-0.034210205,
0.0072631836,
0.009552002,
-0.027008057,
-0.01247406,
-0.012374878,
0.005722046,
0.017410278,
-0.030456543,
0.0075531006,
-0.002691269,
-0.009925842,
0.0725708,
-0.022735596,
-0.007232666,
0.023803711,
-0.036071777,
0.07525635,
0.032592773,
-0.0032787323,
0.041809082,
0.008399963,
0.034423828,
0.005672455,
0.06500244,
-0.012451172,
0.02949524,
-0.020446777,
0.005050659,
-0.022842407,
-0.036071777,
0.0021247864,
-0.053710938,
0.045013428,
0.008773804,
0.0041046143,
0.023422241,
-0.009674072,
-0.062194824,
0.06210327,
-0.011688232,
0.07336426,
0.019210815,
-0.0049972534,
-0.026016235,
-0.036193848,
-0.00856781,
0.04827881,
0.020523071,
-0.021636963,
-0.004421234,
0.039855957,
0.010444641,
-0.0340271,
0.016525269,
-0.0013847351,
0.006603241,
-0.012550354,
0.006351471,
0.0044784546,
0.040039062,
0.011253357,
0.04043579,
-0.028259277,
-0.025741577,
0.0138168335,
-0.0076904297,
-0.026687622,
-0.02798462,
0.02142334,
-0.08380127,
0.006839752,
-0.0032138824,
0.014266968,
0.031158447,
0.006149292,
0.03439331,
-0.0066604614,
-0.07067871,
-0.023788452,
0.04397583,
0.019927979,
0.0435791,
-0.040008545,
0.001613617,
-0.0022888184,
0.029724121,
0.0031337738,
0.007347107,
0.009056091,
0.03805542,
-0.038604736,
-0.011405945,
-0.00096321106,
-0.0037212372,
-0.010505676,
0.029037476,
-0.02017212,
-0.0039100647,
-0.028915405,
-0.047546387,
0.062438965,
-0.023330688,
-0.04067993,
0.03225708,
0.0063095093,
-0.0075798035,
0.0118255615,
0.03201294,
-0.0058250427,
-0.0034599304,
-0.06744385,
-0.021713257,
0.022720337,
0.070495605,
-0.0184021,
0.08679199,
-0.05670166,
-0.039978027,
0.06890869,
-0.070251465,
0.066589355,
-0.047668457,
0.0060920715,
0.022766113,
-0.008110046,
0.016784668,
-0.022521973,
-0.010276794,
-0.012863159,
0.013885498,
-0.023834229,
0.016098022,
-0.010757446,
-0.002008438,
-0.012191772,
0.06518555,
0.027694702,
-0.024124146,
-0.03982544,
-0.018554688,
-0.029785156,
-0.0625,
-0.037109375,
-0.0039634705,
-0.05441284,
-0.06463623,
-0.00415802,
0.0024547577,
-0.014694214,
0.0059432983,
0.008239746,
-0.0087509155,
-0.025146484,
-0.0013866425,
0.005634308,
0.020629883,
-0.006652832,
0.0027256012,
-0.05883789,
0.03463745,
-0.027023315,
0.030654907,
-0.0056533813,
-0.032562256,
0.025131226,
0.009689331,
-0.011421204,
0.018920898,
0.025253296,
-0.012718201,
0.02609253,
-0.0038604736,
-0.023269653,
-0.034057617,
-0.009338379,
0.036376953,
-0.018920898,
-0.05807495,
-0.0018091202,
0.048431396,
0.033447266,
-0.07672119,
0.016906738,
0.0029792786,
0.041656494,
0.011108398,
0.029663086,
0.009124756,
-0.0015134811,
-0.0077934265,
0.05621338,
-0.0074310303,
-0.026611328,
-0.042816162,
-0.024902344,
0.04434204,
0.011238098,
0.002494812,
-0.00598526,
0.026382446,
-0.02420044,
-0.004787445,
0.018951416,
-0.02519226,
0.020004272,
-0.0003745556,
0.021820068,
0.0076560974,
0.002861023,
-0.024414062,
0.017837524,
-0.0032653809,
0.035614014,
0.006061554,
0.0027065277,
-0.012107849,
0.08666992,
-0.035461426,
-0.050354004,
0.0075187683,
0.007205963,
-0.024124146,
0.011100769,
-0.04446411,
-0.001789093,
...]]

Indexing and Retrievalโ€‹

Embedding models are often used in retrieval-augmented generation (RAG) flows, both as part of indexing data as well as later retrieving it. For more detailed instructions, please see our RAG tutorials under the working with external knowledge tutorials.

Below, see how to index and retrieve data using the embeddings object we initialized above. In this example, we will index and retrieve a sample document in the InMemoryVectorStore.

# Create a vector store with a sample text
from langchain_core.vectorstores import InMemoryVectorStore

text = "LangChain is the framework for building context-aware reasoning applications"

vectorstore = InMemoryVectorStore.from_texts(
[text],
embedding=embeddings,
)

# Use the vectorstore as a retriever
retriever = vectorstore.as_retriever()

# Retrieve the most similar text
retrieved_documents = retriever.invoke("What is LangChain?")

# show the retrieved document's content
retrieved_documents[0].page_content
API Reference:InMemoryVectorStore
'LangChain is the framework for building context-aware reasoning applications'

Direct Usageโ€‹

Under the hood, the vectorstore and retriever implementations are calling embeddings.embed_documents(...) and embeddings.embed_query(...) to create embeddings for the text(s) used in from_texts and retrieval invoke operations, respectively.

You can directly call these methods to get embeddings for your own use cases.

Embed single textsโ€‹

You can embed single texts or documents with embed_query:

single_vector = embeddings.embed_query(text)
print(str(single_vector)[:100]) # Show the first 100 characters of the vector
[-0.022979736, -0.030212402, -0.08886719, -0.08569336, 0.007030487, -0.0010671616, -0.033813477, 0.0

Embed multiple textsโ€‹

You can embed multiple texts with embed_documents:

text2 = (
"LangGraph is a library for building stateful, multi-actor applications with LLMs"
)
two_vectors = embeddings.embed_documents([text, text2])
for vector in two_vectors:
print(str(vector)[:100]) # Show the first 100 characters of the vector
[-0.028869629, -0.030410767, -0.099121094, -0.07116699, -0.012748718, -0.0059432983, -0.04360962, 0.
[-0.047332764, -0.049957275, -0.07458496, -0.034332275, -0.057922363, -0.0112838745, -0.06994629, 0.

API Referenceโ€‹

For detailed documentation on CohereEmbeddings features and configuration options, please refer to the API reference.


Was this page helpful?


You can also leave detailed feedback on GitHub.