Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-86808

Ability to create views using $vectorSearch

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Query Integration
    • ALL
    • Hide

      In order to reproduce this you need a mongoDB collection with vectors and vector search index. In this case I am referring to a collection where the embeddings are computed using https://huggingface.co/sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2.

      You should be able to reproduce it even with a "fake" vector search collection.

      This is the pipeline I used: 

      [
        {
          $vectorSearch:

      {       queryVector: [         0.36474791169166565, 0.2787139117717743,         0.037420038133859634,         -0.11489459872245789,         0.011614377610385418, 0.07989057898521423,         0.3743008077144623, 0.3031100928783417,         -0.053919192403554916,         -0.22758670151233673, 0.35668912529945374,         0.19494308531284332, 0.23027025163173676,         -0.13939541578292847,         -0.07496068626642227, 0.24313263595104218,         0.09207076579332352, 0.13547749817371368,         0.14529556035995483, -0.4175901710987091,         0.09342092275619507, -0.06883081793785095,         -0.015943696722388268,         -0.22336186468601227,         -0.36722221970558167, 0.16170752048492432,         -0.17376397550106049, 0.2820833921432495,         -0.21961534023284912,         -0.29807227849960327,         -0.22774584591388702,         -0.046463266015052795,         0.38292327523231506, 0.6705532073974609,         -0.0011250475654378533,         -0.4374222457408905,         0.0059357210993766785,         -0.2868773639202118, 0.33803629875183105,         -0.4322603940963745, -0.30203333497047424,         -0.3678397834300995, -0.12692205607891083,         0.11778966337442398, 0.6134411096572876,         0.6551673412322998, 0.47187840938568115,         0.37442174553871155, 0.3999262750148773,         -0.4226326048374176, 0.14736372232437134,         -0.1560497134923935, 0.13072918355464935,         -0.2526467740535736, -0.16088338196277618,         0.3141584098339081, 0.13775503635406494,         0.17941279709339142, -0.13140131533145905,         -0.13185681402683258,         -0.07393067330121994, -0.6376261115074158,         -0.45928457379341125, 0.067693330347538,         -0.21567519009113312, -0.1417739987373352,         -0.1069856509566307, -0.18399988114833832,         -0.5406956076622009, 0.3151346445083618,         0.023242900148034096,         -0.09086553007364273,         -0.42230209708213806, 0.05621721222996712,         -0.05549986660480499, -0.3468848168849945,         0.1656932234764099, 0.1304088830947876,         0.06834084540605545, -0.03741573914885521,         0.3652520477771759, 0.4791586399078369,         -0.1356734186410904, 0.05843939259648323,         -0.008839596062898636,         0.0025121767539530993,         -0.029064245522022247,         0.02611972950398922, -0.3300234377384186,         -0.10233840346336365,         -0.20794863998889923,         -0.32615503668785095, 0.2714393734931946,         -0.24329306185245514, 0.48699963092803955,         0.21156775951385498, 0.3397998511791229,         -0.2899411618709564, 0.4694659411907196,         2.1674516201019287, -0.014729741029441357,         0.20152194797992706, 0.04912057891488075,         -0.19334197044372559, -0.7080972790718079,         0.3939540386199951, -0.21570809185504913,         0.10330450534820557, -0.3879603445529938,         0.07139094918966293, -0.23778831958770752,         0.06459150463342667, -0.27946245670318604,         0.07051140815019608, -0.3872544765472412,         -0.3014083504676819, -0.399956613779068,         0.013877098448574543, 0.5826681852340698,         0.34517431259155273, -0.1834828406572342,         -0.35280051827430725, 0.12491321563720703,         0.06686646491289139, 0.2331588864326477,         -1.0208820104599, 0.28950178623199463,         0.11767742037773132, -0.36784467101097107,         -0.029691627249121666,         -0.22158682346343994, 0.16479890048503876,         -0.4032454788684845, 0.030647581443190575,         -0.24897867441177368, 0.2760976552963257,         0.0069608562625944614, 0.2261696308851242,         -0.22492997348308563,         -0.13751952350139618,         -0.45074212551116943,         -0.11661496013402939, 0.4477287530899048,         0.2602308988571167, -0.10681743174791336,         -0.15738092362880707, -0.4837998151779175,         -0.47391843795776367, 0.17142069339752197,         0.28242573142051697, 0.22503794729709625,         0.10606537014245987, 0.32878050208091736,         0.177709698677063, -0.013109195046126842,         0.20875544846057892, 0.09798264503479004,         -0.024944866076111794,         0.17168229818344116, 0.40376678109169006,         -0.13183848559856415, 0.15103381872177124,         0.2807656228542328, 0.1626197248697281,         -0.569209635257721, -0.27561700344085693,         -0.22273047268390656, -0.1620444506406784,         0.5481135845184326, 0.07493715733289719,         -0.3055245578289032, -0.11493942141532898,         -0.4005415141582489, 0.3516221046447754,         0.001104971976019442, 0.29277274012565613,         -0.03132781758904457, 0.4088630676269531,         -0.2395717352628708, -0.02484716661274433,         -0.17547065019607544, 0.07841280847787857,         -0.35929298400878906, 0.3080275058746338,         0.31517961621284485, 0.4422987997531891,         -0.5864879488945007, -0.11247244477272034,         -0.13510598242282867, 0.20173673331737518,         0.287324458360672, -0.17966224253177643,         0.16436469554901123, 0.11897820234298706,         -0.18053632974624634, 0.24727962911128998,         0.004848960787057877, 0.15392199158668518,         0.3449345529079437, -0.39414823055267334,         -0.0504436157643795, 0.07319531589746475,         0.018995964899659157,         -0.20706433057785034, 0.0451633520424366,         -0.18581955134868622,         -0.14927281439304352,         -0.14287926256656647,         -0.35970616340637207, 0.10649340599775314,         0.3452312648296356, -0.29978132247924805,         -0.00880768895149231,         -0.05983246490359306, 0.11350993067026138,         -0.1266799420118332, -0.5087553262710571,         -0.11541983485221863,         -0.09506464004516602, -0.1059935986995697,         -0.558569610118866, 0.38255396485328674,         0.1907070428133011, -0.31909143924713135,         0.4230027496814728, -0.3064248561859131,         0.10863954573869705, -0.0960787758231163,         -0.27500614523887634, 0.07020729035139084,         0.20927853882312775, -0.14338959753513336,         -0.21639172732830048,         -0.12554825842380524,         -0.24175357818603516, 0.08179832994937897,         -0.16124074161052704, 0.4514126479625702,         0.20622925460338593, -0.12437305599451065,         0.04747581109404564, -0.5012962818145752,         -0.2981705665588379, 0.4386816918849945,         0.07725215703248978, -0.3853871524333954,         0.5276380181312561, 0.4846917688846588,         -0.13037851452827454, 0.3629671037197113,         -0.6426520943641663, 0.13704168796539307,         0.2052515298128128, 0.18709444999694824,         0.32762411236763, -0.37993136048316956,         0.1613314002752304, 0.4016525447368622,         -0.2322521209716797, -0.2951606810092926,         0.30578890442848206, -0.3043256402015686,         -0.26232823729515076, -0.351860374212265,         0.0015954462578520179,         -0.29682740569114685, 0.10334502905607224,         0.33403798937797546, 0.5918578505516052,         -0.18169470131397247,         0.028950149193406105, -0.4217567443847656,         -0.04752599075436592,         -0.22976024448871613, 0.7127812504768372,         0.017976148054003716,         -0.06846339255571365, 0.38081005215644836,         0.31380245089530945, 0.3895174562931061,         0.1985236406326294, 0.3322540521621704,         0.06264692544937134, 0.3589940369129181,         0.27859488129615784, 0.06485169380903244,         0.11001624912023544, 0.17936944961547852,         -0.22582750022411346, -0.6238889694213867,         -0.00015390788030344993,         0.39561986923217773, 0.10702116042375565,         -0.29948338866233826,         -0.09464182704687119, 0.1609533280134201,         -0.02634664811193943, 0.12408185005187988,         -0.017234282568097115,         0.17203116416931152, 0.5197862982749939,         -0.19365406036376953,         -0.08530133962631226,         -0.15612848103046417,         -0.14185714721679688,         -0.15616102516651154, 0.21245241165161133,         0.18376199901103973, -0.45665398240089417,         -0.300804078578949, -0.430586576461792,         -0.21261286735534668, 0.22971074283123016,         0.6411426663398743, -0.05434419587254524,         0.31479933857917786, -0.34876549243927,         0.4017176628112793, -0.5813129544258118,         -0.49750468134880066,         -0.17097674310207367,         -0.12256259471178055, 0.06392170488834381,         0.08988501876592636, 0.05004364252090454,         -0.4497545063495636, -0.19323061406612396,         -0.10313475131988525, -0.4365713596343994,         -0.4656658470630646, -0.07010463625192642,         -0.49969103932380676,         0.027533993124961853,         0.028239769861102104,         -0.41880202293395996, 0.3090479373931885,         -0.14232100546360016, 0.11507043242454529,         0.06002219393849373, 0.04856320843100548,         0.5519489645957947, 0.14370043575763702,         0.023712044581770897, 0.22049255669116974,         0.3784972131252289, -0.15209025144577026,         -0.40510866045951843, -0.7321825623512268,         0.6972169280052185, -0.05589345097541809,         -0.13388867676258087, 0.08954618126153946,         0.21190105378627777, -0.0932144895195961,         -0.20360131561756134, 0.123643659055233,         -0.49161234498023987, 0.418592244386673,         0.3646015226840973, -0.2070634514093399,         0.6856706142425537, 0.37375155091285706,         -0.3772021532058716, -0.07735364884138107,         0.5386711359024048, 0.3823286294937134,         -0.3944620192050934, -0.5359563231468201,         -0.27180516719818115,         -0.28817519545555115,         -0.08616548776626587, -0.4644608199596405,         -0.34320950508117676, 0.587039053440094,         -0.10093363374471664, -0.1403954178094864,         -0.13168048858642578, 0.20421874523162842,         0.049011822789907455, 0.23097757995128632,         0.005599372088909149, 0.1044425442814827,         0.00997952651232481, 0.4473152458667755       ],       path: "vector",       numCandidates: 100,       index: "vector_search_index",       limit: 10     }

        },
        {
          $addFields: {
            score:

      {         $meta: "vectorSearchScore"       }

          }
        },
        {
          $match: {
            score:

      {         $gt: 0.7       }

          }
        }
      ]

      Attaching also a screenshot from compass showing the computed view.

       

      Show
      In order to reproduce this you need a mongoDB collection with vectors and vector search index. In this case I am referring to a collection where the embeddings are computed using https://huggingface.co/sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2. You should be able to reproduce it even with a "fake" vector search collection. This is the pipeline I used:  [   {     $vectorSearch: {       queryVector: [         0.36474791169166565, 0.2787139117717743,         0.037420038133859634,         -0.11489459872245789,         0.011614377610385418, 0.07989057898521423,         0.3743008077144623, 0.3031100928783417,         -0.053919192403554916,         -0.22758670151233673, 0.35668912529945374,         0.19494308531284332, 0.23027025163173676,         -0.13939541578292847,         -0.07496068626642227, 0.24313263595104218,         0.09207076579332352, 0.13547749817371368,         0.14529556035995483, -0.4175901710987091,         0.09342092275619507, -0.06883081793785095,         -0.015943696722388268,         -0.22336186468601227,         -0.36722221970558167, 0.16170752048492432,         -0.17376397550106049, 0.2820833921432495,         -0.21961534023284912,         -0.29807227849960327,         -0.22774584591388702,         -0.046463266015052795,         0.38292327523231506, 0.6705532073974609,         -0.0011250475654378533,         -0.4374222457408905,         0.0059357210993766785,         -0.2868773639202118, 0.33803629875183105,         -0.4322603940963745, -0.30203333497047424,         -0.3678397834300995, -0.12692205607891083,         0.11778966337442398, 0.6134411096572876,         0.6551673412322998, 0.47187840938568115,         0.37442174553871155, 0.3999262750148773,         -0.4226326048374176, 0.14736372232437134,         -0.1560497134923935, 0.13072918355464935,         -0.2526467740535736, -0.16088338196277618,         0.3141584098339081, 0.13775503635406494,         0.17941279709339142, -0.13140131533145905,         -0.13185681402683258,         -0.07393067330121994, -0.6376261115074158,         -0.45928457379341125, 0.067693330347538,         -0.21567519009113312, -0.1417739987373352,         -0.1069856509566307, -0.18399988114833832,         -0.5406956076622009, 0.3151346445083618,         0.023242900148034096,         -0.09086553007364273,         -0.42230209708213806, 0.05621721222996712,         -0.05549986660480499, -0.3468848168849945,         0.1656932234764099, 0.1304088830947876,         0.06834084540605545, -0.03741573914885521,         0.3652520477771759, 0.4791586399078369,         -0.1356734186410904, 0.05843939259648323,         -0.008839596062898636,         0.0025121767539530993,         -0.029064245522022247,         0.02611972950398922, -0.3300234377384186,         -0.10233840346336365,         -0.20794863998889923,         -0.32615503668785095, 0.2714393734931946,         -0.24329306185245514, 0.48699963092803955,         0.21156775951385498, 0.3397998511791229,         -0.2899411618709564, 0.4694659411907196,         2.1674516201019287, -0.014729741029441357,         0.20152194797992706, 0.04912057891488075,         -0.19334197044372559, -0.7080972790718079,         0.3939540386199951, -0.21570809185504913,         0.10330450534820557, -0.3879603445529938,         0.07139094918966293, -0.23778831958770752,         0.06459150463342667, -0.27946245670318604,         0.07051140815019608, -0.3872544765472412,         -0.3014083504676819, -0.399956613779068,         0.013877098448574543, 0.5826681852340698,         0.34517431259155273, -0.1834828406572342,         -0.35280051827430725, 0.12491321563720703,         0.06686646491289139, 0.2331588864326477,         -1.0208820104599, 0.28950178623199463,         0.11767742037773132, -0.36784467101097107,         -0.029691627249121666,         -0.22158682346343994, 0.16479890048503876,         -0.4032454788684845, 0.030647581443190575,         -0.24897867441177368, 0.2760976552963257,         0.0069608562625944614, 0.2261696308851242,         -0.22492997348308563,         -0.13751952350139618,         -0.45074212551116943,         -0.11661496013402939, 0.4477287530899048,         0.2602308988571167, -0.10681743174791336,         -0.15738092362880707, -0.4837998151779175,         -0.47391843795776367, 0.17142069339752197,         0.28242573142051697, 0.22503794729709625,         0.10606537014245987, 0.32878050208091736,         0.177709698677063, -0.013109195046126842,         0.20875544846057892, 0.09798264503479004,         -0.024944866076111794,         0.17168229818344116, 0.40376678109169006,         -0.13183848559856415, 0.15103381872177124,         0.2807656228542328, 0.1626197248697281,         -0.569209635257721, -0.27561700344085693,         -0.22273047268390656, -0.1620444506406784,         0.5481135845184326, 0.07493715733289719,         -0.3055245578289032, -0.11493942141532898,         -0.4005415141582489, 0.3516221046447754,         0.001104971976019442, 0.29277274012565613,         -0.03132781758904457, 0.4088630676269531,         -0.2395717352628708, -0.02484716661274433,         -0.17547065019607544, 0.07841280847787857,         -0.35929298400878906, 0.3080275058746338,         0.31517961621284485, 0.4422987997531891,         -0.5864879488945007, -0.11247244477272034,         -0.13510598242282867, 0.20173673331737518,         0.287324458360672, -0.17966224253177643,         0.16436469554901123, 0.11897820234298706,         -0.18053632974624634, 0.24727962911128998,         0.004848960787057877, 0.15392199158668518,         0.3449345529079437, -0.39414823055267334,         -0.0504436157643795, 0.07319531589746475,         0.018995964899659157,         -0.20706433057785034, 0.0451633520424366,         -0.18581955134868622,         -0.14927281439304352,         -0.14287926256656647,         -0.35970616340637207, 0.10649340599775314,         0.3452312648296356, -0.29978132247924805,         -0.00880768895149231,         -0.05983246490359306, 0.11350993067026138,         -0.1266799420118332, -0.5087553262710571,         -0.11541983485221863,         -0.09506464004516602, -0.1059935986995697,         -0.558569610118866, 0.38255396485328674,         0.1907070428133011, -0.31909143924713135,         0.4230027496814728, -0.3064248561859131,         0.10863954573869705, -0.0960787758231163,         -0.27500614523887634, 0.07020729035139084,         0.20927853882312775, -0.14338959753513336,         -0.21639172732830048,         -0.12554825842380524,         -0.24175357818603516, 0.08179832994937897,         -0.16124074161052704, 0.4514126479625702,         0.20622925460338593, -0.12437305599451065,         0.04747581109404564, -0.5012962818145752,         -0.2981705665588379, 0.4386816918849945,         0.07725215703248978, -0.3853871524333954,         0.5276380181312561, 0.4846917688846588,         -0.13037851452827454, 0.3629671037197113,         -0.6426520943641663, 0.13704168796539307,         0.2052515298128128, 0.18709444999694824,         0.32762411236763, -0.37993136048316956,         0.1613314002752304, 0.4016525447368622,         -0.2322521209716797, -0.2951606810092926,         0.30578890442848206, -0.3043256402015686,         -0.26232823729515076, -0.351860374212265,         0.0015954462578520179,         -0.29682740569114685, 0.10334502905607224,         0.33403798937797546, 0.5918578505516052,         -0.18169470131397247,         0.028950149193406105, -0.4217567443847656,         -0.04752599075436592,         -0.22976024448871613, 0.7127812504768372,         0.017976148054003716,         -0.06846339255571365, 0.38081005215644836,         0.31380245089530945, 0.3895174562931061,         0.1985236406326294, 0.3322540521621704,         0.06264692544937134, 0.3589940369129181,         0.27859488129615784, 0.06485169380903244,         0.11001624912023544, 0.17936944961547852,         -0.22582750022411346, -0.6238889694213867,         -0.00015390788030344993,         0.39561986923217773, 0.10702116042375565,         -0.29948338866233826,         -0.09464182704687119, 0.1609533280134201,         -0.02634664811193943, 0.12408185005187988,         -0.017234282568097115,         0.17203116416931152, 0.5197862982749939,         -0.19365406036376953,         -0.08530133962631226,         -0.15612848103046417,         -0.14185714721679688,         -0.15616102516651154, 0.21245241165161133,         0.18376199901103973, -0.45665398240089417,         -0.300804078578949, -0.430586576461792,         -0.21261286735534668, 0.22971074283123016,         0.6411426663398743, -0.05434419587254524,         0.31479933857917786, -0.34876549243927,         0.4017176628112793, -0.5813129544258118,         -0.49750468134880066,         -0.17097674310207367,         -0.12256259471178055, 0.06392170488834381,         0.08988501876592636, 0.05004364252090454,         -0.4497545063495636, -0.19323061406612396,         -0.10313475131988525, -0.4365713596343994,         -0.4656658470630646, -0.07010463625192642,         -0.49969103932380676,         0.027533993124961853,         0.028239769861102104,         -0.41880202293395996, 0.3090479373931885,         -0.14232100546360016, 0.11507043242454529,         0.06002219393849373, 0.04856320843100548,         0.5519489645957947, 0.14370043575763702,         0.023712044581770897, 0.22049255669116974,         0.3784972131252289, -0.15209025144577026,         -0.40510866045951843, -0.7321825623512268,         0.6972169280052185, -0.05589345097541809,         -0.13388867676258087, 0.08954618126153946,         0.21190105378627777, -0.0932144895195961,         -0.20360131561756134, 0.123643659055233,         -0.49161234498023987, 0.418592244386673,         0.3646015226840973, -0.2070634514093399,         0.6856706142425537, 0.37375155091285706,         -0.3772021532058716, -0.07735364884138107,         0.5386711359024048, 0.3823286294937134,         -0.3944620192050934, -0.5359563231468201,         -0.27180516719818115,         -0.28817519545555115,         -0.08616548776626587, -0.4644608199596405,         -0.34320950508117676, 0.587039053440094,         -0.10093363374471664, -0.1403954178094864,         -0.13168048858642578, 0.20421874523162842,         0.049011822789907455, 0.23097757995128632,         0.005599372088909149, 0.1044425442814827,         0.00997952651232481, 0.4473152458667755       ],       path: "vector",       numCandidates: 100,       index: "vector_search_index",       limit: 10     }   },   {     $addFields: {       score: {         $meta: "vectorSearchScore"       }     }   },   {     $match: {       score: {         $gt: 0.7       }     }   } ] Attaching also a screenshot from compass showing the computed view.  

      Hi team, in the Atlas doc page on $vectorSearch, in the limitations section we say:

      $vectorSearch can’t be used in view definition and the following pipeline stages:$lookup sub-pipeline […] 

      but if I try to create a view using $vectorSearch in the view definition I am able to create the view. 

      Original Slack thread: https://mongodb.slack.com/archives/C061L7P3FK4/p1708334467026529

            Assignee:
            Unassigned Unassigned
            Reporter:
            paolo.picello@mongodb.com Paolo Picello
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: