This tutorial demonstrates a hybrid search that is an aggregation of full-text and semantic search for the same query criteria. While full-text is effective in finding exact matches for query terms, semantic search provides the added benefit of identifying semantically similar documents even if the documents don't contain the exact query term. This ensures that synonymous and contextually similar matches are also included in the combined results of both methods of search.
Conversely, if you have tokens for proper nouns or specific keywords in your dataset that you don't expect to be considered in the training of an embedding model in the same context that they are used in your dataset, your vector search might benefit from being combined with a full-text search.
You can also set weights for each method of search per query. Based on whether full-text or semantic search results are most relevant and appropriate for a query, you can increase the weight for that search method per query.
About the Tutorial
This tutorial demonstrates how to run a hybrid search combining Atlas Vector Search
and Atlas Search queries on the sample_mflix.embedded_movies
collection,
which contains details about movies, for unified search results.
Specifically, this tutorial takes you through the following steps:
Create an Atlas Vector Search index on the
plot_embedding
field. This field contains vector embeddings that represent the summary of a movie's plot.Create an Atlas Search index on the
title
field in thesample_mflix.embedded_movies
collection. This field contains the movie's name as a text string.Run a query that uses reciprocal rank fusion to combine the results from a
$vectorSearch
query against theplot_embedding
field and a$search
query against thetitle
field.
Prerequisites
Before you begin, complete the common prerequisites. You must have the
Project Data Access Admin
access to the project to create
Atlas Vector Search and Atlas Search indexes.
Create the Atlas Vector Search and Atlas Search Indexes
This section demonstrates how to create the following indexes on the
fields in the sample_mflix.embedded_movies
collection:
An Atlas Vector Search index on the
plot_embedding
field for running vector queries against that field.An Atlas Search index on the
title
field for running full-text search against that field.
Procedure
Connect to the Atlas cluster using mongosh
.
To learn more, see Connect via mongosh
.
Define the Atlas Vector Search index.
Run the following command. This index definition indexes the plot_embedding
field as
the Atlas Vector Search field when querying the collection.
1 db.embedded_movies.createSearchIndex( 2 "hybrid-vector-search", 3 "vectorSearch", 4 { 5 "fields": [ 6 { 7 "type": "vector", 8 "path": "plot_embedding", 9 "numDimensions": 1536, 10 "similarity": "dotProduct" 11 } 12 ] 13 } 14 );
Run a Combined Semantic Search and Full-Text Search Query
This section demonstrates how to query the data in the
sample_mflix.embedded_movies
collection for star wars in the
plot_embedding
and title
fields by using the
$vectorSearch
and $search
pipeline stages inside
the $rankFusion
stage to re-sort the documents in the
results. The $rankFusion
stages ensures that documents appearing in
both searches appear at the top of the combined results.
Procedure
Set up the embeddings to use in the query.
Create a file named
query-embeddings.js
.Copy and paste the following embeddings in the file.
STAR_WARS_EMBEDDING=[-0.0031186682172119617, -0.01895737089216709, -0.02120436169207096, -0.031741973012685776, -0.02779036946594715, -0.008749059401452541, -0.02236659824848175, -0.015754763036966324, -0.0026860579382628202, -0.030089015141129494, 0.023709626868367195, 0.0021065538749098778, 0.009756330400705338, 0.003000830300152302, 0.012067890726029873, 0.031741973012685776, 0.026369858533143997, -0.02230202965438366, 0.022560304030776024, -0.030373116955161095, 0.0007251872448250651, 0.012274510227143764, 0.00821313913911581, -0.018634527921676636, 0.012435931712388992, -0.010563439689576626, 0.003832152346149087, -0.03352406993508339, 0.00016797950956970453, -0.024445710703730583, 0.026085754856467247, -0.030528081580996513, -0.020519932731986046, -0.02178548090159893, -0.011538427323102951, -0.012435931712388992, 0.008774886839091778, -0.013443203642964363, 0.01686534471809864, 0.003086383920162916, 0.016813689842820168, 0.018699096515774727, -0.01968054100871086, -0.015367351472377777, -0.02838440053164959, 0.002442311029881239, 0.02252156287431717, -0.02410995401442051, -0.005352745298296213, 0.010518241673707962, -0.002795824781060219, 0.04096238315105438, -0.03582271561026573, -0.013766047544777393, -0.008916937746107578, 0.008529525250196457, -0.007515796925872564, -0.007567451801151037, 0.02903008833527565, -0.01678786240518093, 0.008484327234327793, 0.013778961263597012, -0.023864591494202614, 0.014605440199375153, -0.032749246805906296, 0.0030766986310482025, -0.0002836987259797752, -0.00857472326606512, 0.009782158769667149, 0.0016787862405180931, 0.04147893562912941, 0.01678786240518093, 0.0060081179253757, 0.0076384772546589375, -0.0068313684314489365, -0.010001691989600658, 0.010556982830166817, 0.014140545390546322, -0.006495611276477575, 0.009762787260115147, 0.016968654468655586, -0.01168693508952856, -0.007929036393761635, 0.008723231963813305, 0.021333498880267143, -0.0067151449620723724, -0.013191386125981808, 0.003220363985747099, -0.031664490699768066, 0.004745799582451582, 0.0010879826731979847, -0.002786139491945505, 0.009439944289624691, 0.023438438773155212, -0.020946087315678596, 0.019964642822742462, -0.009013790637254715, 0.03329162299633026, 0.005213922820985317, -0.03520285710692406, 0.0029572464991360903, 0.005326917860656977, -0.01487662922590971, -0.02368379943072796, -0.009530340321362019, 0.009427030570805073, 0.016852430999279022, 0.007922579534351826, 0.018298769369721413, -0.004077513702213764, -0.011428659781813622, 0.021617600694298744, 0.0052558924071490765, -0.03925777226686478, -0.016813689842820168, -0.022056668996810913, -0.0005129176424816251, -0.009581995196640491, 0.007554538082331419, -0.02910757064819336, 0.02670561522245407, 0.016981568187475204, 0.016452105715870857, -0.0121582867577672, 0.028771813958883286, 0.021966272965073586, -0.01579350419342518, 0.0008252687403000891, -0.01977093704044819, -0.01716236025094986, 0.03561609610915184, 0.012649009004235268, 0.02396790124475956, -0.002277660882100463, -0.029985705390572548, 0.022211633622646332, 0.005846695974469185, 0.01658124290406704, -0.01615508832037449, -0.010724861174821854, 0.0043390169739723206, 0.025349672883749008, -0.007916122674942017, -0.001988715957850218, -0.006288991775363684, 0.009943580254912376, 0.0122293122112751, 0.030089015141129494, 0.010001691989600658, -0.020661983639001846, 0.01766599714756012, -0.02310268208384514, 0.021553032100200653, 0.004639261402189732, 0.007786985486745834, 0.005795041099190712, -0.004678002558648586, -0.0054140854626894, -0.0014455318450927734, -0.0068765669129788876, -0.005443141330033541, 0.004881393630057573, 0.010853998363018036, -0.017833875492215157, 0.021746737882494926, 0.021604686975479126, 0.017627255991101265, 0.01169339194893837, -0.018298769369721413, -0.0026715300045907497, -0.015264040790498257, 0.03055390901863575, -0.018156718462705612, 0.028539367020130157, 0.00013508982374332845, 0.024342400953173637, 0.009853184223175049, 0.019796764478087425, -0.032904211431741714, -0.02742878533899784, -0.023722540587186813, 0.011900011450052261, 0.021191447973251343, 0.02794533409178257, -0.0039128633216023445, 0.0071025569923222065, 0.006124341394752264, 0.012971851974725723, 0.017859702929854393, -0.011958123184740543, 0.00025544993695802987, 0.023503007367253304, 0.01067320629954338, 0.0024003414437174797, -0.6789528131484985, -0.026163237169384956, 0.01940935105085373, -0.00869094766676426, 0.00973695982247591, 0.01730441115796566, 0.022689441218972206, 0.017317326739430428, -0.0060920570977032185, -0.01371439266949892, -0.014385906979441643, 0.00580795481801033, 0.011280152015388012, -0.012054977007210255, -0.011015420779585838, -0.007715960033237934, 0.01838916540145874, -0.012100175023078918, 0.008342276327311993, -0.0008732916903682053, -0.026292376220226288, 0.02330930158495903, 0.003954832907766104, -0.015160731039941311, 0.023490093648433685, 0.013481944799423218, 0.0002556517138145864, -0.009071902371942997, -0.028177781030535698, 0.026292376220226288, -0.020545760169625282, 0.0201325211673975, 0.004497210029512644, 0.0043906718492507935, 0.044474922120571136, 0.002279275096952915, -0.031096287071704865, 0.037165746092796326, 0.024716898798942566, 0.020610328763723373, -0.0121582867577672, -0.0034059989266097546, 0.006030716933310032, 0.008129199966788292, -0.015457747504115105, 0.017898444086313248, 0.027093026787042618, -0.003816010197624564, -0.014127631671726704, -0.0016949283890426159, 0.0030589422676712275, -0.002372899791225791, 0.005575507413595915, 0.0029427185654640198, 0.010163113474845886, 0.007386659272015095, 0.025724170729517937, -0.011712762527167797, 0.0024035698734223843, 0.018414992839097977, 0.00019925498054362833, 0.015728935599327087, -0.005420542322099209, -0.0011162314331158996, -0.006566637195646763, 0.037165746092796326, -0.016090519726276398, 0.016594156622886658, 0.000506460783071816, -0.018866974860429764, 0.013036420568823814, 0.010808800347149372, -0.002661844715476036, -0.0037127004470676184, 0.01176441740244627, 0.03809553384780884, 0.020649069920182228, -6.841507911303779e-06, -0.0067345155403018, 0.024342400953173637, 0.008555352687835693, 0.0005334988818503916, -0.02439405582845211, 0.008400388062000275, 0.023787109181284904, 0.0026715300045907497, -0.02851353958249092, 0.014463389292359352, 0.012668379582464695, 0.004371301271021366, 0.01563853956758976, 0.0034834814723581076, -0.013623995706439018, -0.007870924659073353, 0.009724046103656292, -0.011409289203584194, -0.033988963812589645, 0.001977416453883052, 0.01584515906870365, -0.030321462079882622, -0.0025068798568099737, 0.0136110819876194, -0.004849109333008528, -0.0025230220053344965, 0.006669946946203709, 0.0022938030306249857, 0.008871739730238914, 0.020029211416840553, 0.03396313637495041, -0.042666997760534286, 0.007231694646179676, -0.010124372318387032, -0.022986458614468575, -0.012216398492455482, 0.008452042937278748, -0.021979186683893204, 0.036235954612493515, 0.0005258313613012433, 0.012610267847776413, -0.02462650276720524, 0.023257646709680557, -0.003803096478804946, 0.004232478328049183, -0.007560994941741228, 0.002114624949172139, 0.002708656946197152, 0.004061371553689241, -0.027532095089554787, -0.003919320181012154, -0.005485111381858587, -0.002684443723410368, 0.020532846450805664, 0.015974296256899834, -0.008180854842066765, 0.007089643273502588, -0.0016691009514033794, -0.004122711718082428, -0.008445586077868938, 0.0040968842804431915, -0.030683046206831932, -0.02338678389787674, 0.006895937491208315, -0.006799084134399891, 0.01209371816366911, 0.0041549960151314735, -0.02585330791771412, -0.0015867758775129914, -0.005820868536829948, -0.009853184223175049, 0.0002175158151658252, -0.011086446233093739, -0.001430196687579155, -0.017898444086313248, 0.005246207118034363, 0.005717558320611715, -0.0032235924154520035, -0.022689441218972206, -0.00850369781255722, -0.00048426527064293623, -0.01868618279695511, 0.005088013596832752, 0.0007679639966227114, -0.002142066601663828, -0.008949222043156624, 0.017911357805132866, -0.020661983639001846, 0.0014818516792729497, 0.011163928546011448, -0.026176150888204575, -0.016619984060525894, 0.02851353958249092, -0.0038547515869140625, -0.004277676343917847, 0.02851353958249092, -0.024742726236581802, 0.026679787784814835, -0.023696713149547577, -0.023774195462465286, 0.007696589455008507, 0.001584354555234313, 0.0005024251877330244, 0.0038063249085098505, -0.013100989162921906, 0.01379187498241663, 0.01947391964495182, 0.007709503173828125, 0.012106631882488728, 0.009465771727263927, 0.004313189070671797, 0.0025230220053344965, -0.01840207912027836, 0.015470661222934723, -0.014295510947704315, 0.0035835630260407925, -0.006318047642707825, -0.01614217460155487, -0.007870924659073353, 0.009439944289624691, 0.023205991834402084, 0.020959001034498215, 0.03476379066705704, -0.013443203642964363, 0.0202745720744133, -0.029133398085832596, 0.008968592621386051, -0.04801328480243683, 0.003344658762216568, -0.020649069920182228, 0.016684552654623985, -8.43428642838262e-05, 0.01962888613343239, 0.013456117361783981, 0.007335004396736622, -0.015987209975719452, 0.021320585161447525, 0.03494458273053169, -0.005404400173574686, 0.0004991967580281198, -0.021695083007216454, 0.00789675209671259, -0.003451197175309062, -0.014579612761735916, 0.009084816090762615, 0.0014463389525189996, -0.024264918640255928, 0.007909665815532207, 0.019887160509824753, 0.016981568187475204, 0.016981568187475204, -0.02035205438733101, -0.00836164690554142, -0.012119545601308346, -0.005837010685354471, 0.026176150888204575, -0.015251127071678638, 0.015406092628836632, 0.010899197310209274, -0.027816196903586388, 0.03104463219642639, -0.002690900582820177, -0.006556951440870762, 0.002949175424873829, 0.03902532160282135, 0.01285562850534916, -0.0005778899067081511, 0.006999247241765261, 0.042744480073451996, -0.008916937746107578, -0.010615094564855099, -0.0029637033585458994, -0.010330991819500923, -0.016710380092263222, -0.0048652514815330505, 0.01487662922590971, 0.005459283944219351, -0.031896937638521194, 0.015509402379393578, 0.0024390826001763344, 0.03946439176797867, 0.02005503885447979, 0.014566699042916298, 0.013778961263597012, 0.009142927825450897, -0.013572340831160545, -0.006046859081834555, 0.013288239017128944, 0.0016513445880264044, 0.025904962792992592, 0.0030169726815074682, 0.007380202412605286, 0.00019542120571713895, -8.499863906763494e-05, 0.008135656826198101, -0.015832245349884033, -0.0011622366728261113, -0.01270712073892355, 0.009149384684860706, 0.0021323813125491142, 0.0012477901764214039, 0.013443203642964363, 0.011047705076634884, -0.031457871198654175, 0.01020831149071455, 0.011796701699495316, -0.010040433146059513, -0.022702354937791824, -0.019383523613214493, -0.02237951196730137, 0.0027651546988636255, 0.028565194457769394, -0.021953359246253967, 0.021101051941514015, 0.013404462486505508, -0.004849109333008528, -0.03801805153489113, 0.006747429259121418, 0.01331406645476818, -0.015870986506342888, 0.02259904518723488, 0.01100896392017603, -0.0021275386679917574, 0.012416561134159565, -0.014347165822982788, -0.0205586738884449, 0.009872554801404476, -0.00984672736376524, 0.005475426092743874, -0.02425200492143631, 0.014915370382368565, -0.018156718462705612, -0.005940320435911417, -0.006702231243252754, -0.030786357820034027, -0.004022629931569099, 0.0027651546988636255, 0.0026231035590171814, -0.017756393179297447, -0.006159854121506214, 0.04819408059120178, 0.010156656615436077, 0.009485142305493355, -0.014902456663548946, -0.00390963489189744, 0.0020581274293363094, 0.07474473118782043, 0.0007171161705628037, 0.012590897269546986, 0.011448030360043049, 0.002130767097696662, -0.009962950833141804, -0.024523193016648293, -0.0022066354285925627, -0.01423094142228365, -0.017188187688589096, -0.0016473090508952737, -0.007083186414092779, 0.01948683336377144, 0.010356820188462734, -0.0013228512834757566, 0.012423017993569374, 0.018260028213262558, -0.005259120836853981, 0.012720034457743168, 0.0010468200780451298, -0.016736207529902458, -0.011867727153003216, 0.019383523613214493, -0.0053721158765256405, 0.028565194457769394, -0.030321462079882622, 0.010892740450799465, 0.011125187389552593, -0.009491599164903164, -0.03703660890460014, -0.023980814963579178, -0.00635033193975687, -0.0205586738884449, 0.013946839608252048, 0.011738589964807034, -0.006182453129440546, 0.004736114293336868, 0.015354436822235584, 0.01629714109003544, -0.021410981193184853, 0.0013293081428855658, 0.020184176042675972, -0.0009967793012037873, -0.013520685955882072, 0.004510123748332262, -0.008103372529149055, -0.01184189971536398, 0.027480440214276314, -0.005552908405661583, -0.03380817174911499, 0.01851830445230007, -0.011557797901332378, -0.01299122255295515, -0.00025161614757962525, -0.00035351363476365805, 0.011480315588414669, -0.0049911607056856155, -0.012726491317152977, -0.01948683336377144, -0.005743386223912239, -0.011131644248962402, -0.030243979766964912, 0.01853121817111969, 0.007380202412605286, -0.007380202412605286, -0.013100989162921906, -0.015444833785295486, -0.023038113489747047, -0.00796132069081068, -0.0011041248217225075, -0.008387474343180656, 0.005617476999759674, 0.001272003399208188, 0.006947592366486788, 0.01912524923682213, -0.020403709262609482, 0.014114717952907085, 0.005452827084809542, 0.013817702420055866, 0.02093317359685898, -0.011770874261856079, 0.0008531139465048909, -0.008729688823223114, -0.018776578828692436, 0.011525513604283333, 0.0004927398986183107, 0.026886407285928726, -0.004658631980419159, 0.002468138700351119, 0.0025343215093016624, 0.019964642822742462, -0.0016529588028788567, 0.003661045338958502, -0.0004991967580281198, 0.015509402379393578, 0.0050718714483082294, 0.007903208956122398, -0.000564976129680872, 0.017201101407408714, 0.00665703322738409, -0.004729657433927059, -0.01570310816168785, 0.01129306573420763, 0.0057401577942073345, -0.0024939661379903555, -0.0038353807758539915, 0.0092333247885108, 0.014088890515267849, -0.014889542944729328, -0.010046890005469322, -0.007948406971991062, -0.02895260602235794, 0.004839424043893814, -0.009575538337230682, 0.004800682887434959, 0.033420760184526443, -0.0008345504757016897, 0.006453641690313816, 0.0024229404516518116, -0.022495735436677933, 0.004058143123984337, -0.040265042334795, -0.006582779344171286, 0.023657971993088722, -0.005623933859169483, 0.0007853168062865734, 0.011751503683626652, -0.0193189550191164, -0.0030298864003270864, 0.003221978200599551, -0.02462650276720524, 0.013688565231859684, 0.009433487430214882, 0.019590144976973534, -0.040265042334795, -0.007212324067950249, -0.01766599714756012, 0.016736207529902458, -0.004626347683370113, 0.005288176704198122, -0.03672667592763901, -0.013339893892407417, 0.018079236149787903, -0.024639416486024857, 0.0034059989266097546, -0.026473168283700943, -0.010447216220200062, -0.0023051027674227953, -0.007509340066462755, 0.00514289690181613, -0.022921890020370483, 0.008807171136140823, -0.0011347949039191008, -0.021979186683893204, -0.004435869865119457, -0.043674271553754807, -0.012177657335996628, -0.03602933511137962, 0.02686057984828949, 0.020093780010938644, 0.036080989986658096, -0.00761910667642951, 0.02418743632733822, -0.014708749949932098, -0.004051686264574528, 0.010963765904307365, 0.00803880300372839, 0.016400450840592384, 0.0017191417282447219, 0.03422141075134277, 0.029443327337503433, -0.0008563424344174564, 0.0093753756955266, 0.006343875080347061, 0.02851353958249092, 0.018079236149787903, 0.0015044508036226034, 0.008329362608492374, -0.008251880295574665, -0.0037062435876578093, -0.005530309397727251, 0.013856443576514721, -0.008820084854960442, -0.0058273253962397575, -0.013985580764710903, -0.007302720099687576, 0.00897504948079586, 0.013766047544777393, 0.0007780528394505382, 0.006347103510051966, 0.03662336617708206, -0.02258613146841526, 0.018699096515774727, -0.015909727662801743, 0.021462636068463326, -0.01628422737121582, 0.00016021108604036272, -0.009478685446083546, 0.009142927825450897, -0.006253478582948446, 0.018053408712148666, -0.017498118802905083, -0.027996988967061043, 0.017252756282687187, -0.002154980320483446, 0.03600350767374039, -0.011189755983650684, 0.0019031624542549253, 0.0002861200482584536, -0.022482821717858315, -0.006582779344171286, -0.019577231258153915, -0.011848356574773788, -0.0447331964969635, -0.016852430999279022, 0.0002580730360932648, -0.0042357067577540874, 0.023800022900104523, -0.01840207912027836, -0.015083248727023602, 0.013804788701236248, 0.006198595277965069, 0.025892049074172974, 0.002644088352099061, 0.03742402046918869, 0.007380202412605286, -0.010686120018362999, -0.0040290867909789085, -0.005485111381858587, -0.02179839462041855, 0.0029136626981198788, 0.007134841755032539, 0.015264040790498257, -0.025349672883749008, -0.003138038795441389, 0.004174366593360901, -0.016736207529902458, -0.03907697647809982, -0.02810029871761799, 0.007173582911491394, 0.0005157425184734166, 0.029443327337503433, -0.027971161529421806, -0.022831492125988007, -0.03293003886938095, 0.007696589455008507, -0.01656832918524742, 0.0025633773766458035, -0.024884777143597603, -0.039774321019649506, -0.01585807278752327, -0.007502883207052946, -0.009962950833141804, 0.019938815385103226, -0.010983136482536793, -0.025788739323616028, 0.010427845641970634, -0.010105001740157604, 0.007070272695273161, -0.016594156622886658, -0.030579736456274986, 0.02316725067794323, -0.0027812968473881483, 0.0005447984440252185, 0.01868618279695511, 0.008458499796688557, -0.022134151309728622, -0.0006844282615929842, 0.016193829476833344, 0.022973544895648956, -0.014760404825210571, -0.016477933153510094, -0.0030815412756055593, 0.0050492724403738976, 0.0199904702603817, -0.0029992160852998495, -0.011964580044150352, -0.017678910866379738, -0.012474672868847847, -0.0035997051745653152, 0.006611835211515427, -0.000777245732024312, -0.021707996726036072, -0.020816950127482414, -0.005459283944219351, -0.020816950127482414, -0.01643919199705124, -0.0058273253962397575, 0.008716775104403496, -0.031380388885736465, -0.006799084134399891, -0.0038902643136680126, -0.030967149883508682, 0.006014574784785509, -0.0005460091051645577, -0.010053346864879131, 0.006966962944716215, 0.04003259539604187, -0.02758374996483326, -0.010163113474845886, -0.018298769369721413, 0.013572340831160545, -0.032620109617710114, 0.0018240658100694418, -0.005530309397727251, -0.023580489680171013, 0.02533675916492939, -0.020507019013166428, -0.019241472706198692, 0.0006154204602353275, 0.016452105715870857, 0.0006081564351916313, 0.012403647415339947, 0.008936308324337006, 0.024587761610746384, 0.023761281743645668, -0.010105001740157604, -0.02519470825791359, -0.01495411153882742, 0.011790244840085506, -0.0015230142744258046, -0.0005605370388366282, 0.010841084644198418, -0.030605563893914223, 0.0175110325217247, -0.004920135252177715, 0.011047705076634884, -0.005714329890906811, -0.02910757064819336, -0.010240595787763596, -0.019732195883989334, 0.04227958619594574, -0.015535229817032814, -0.011331806890666485, -0.032181039452552795, 0.0034544256050139666, -0.0073156338185071945, 0.03497041016817093, -0.002472981344908476, -0.00851015467196703, 0.0033478871919214725, 0.03349824249744415, 0.01897028461098671, 0.0007421365007758141, 0.005665903445333242, 0.003396313637495041, 0.009601365774869919, -0.018505390733480453, -0.0120872613042593, -0.0049330489709973335, 0.001736898091621697, 0.023038113489747047, 0.0058563812635838985, -0.016258399933576584, -0.0067797135561704636, 0.009175212122499943, -0.01939643733203411, -0.0008163905004039407, -0.003887035883963108, 0.013339893892407417, 0.005627162288874388, -0.0009903224417939782, 9.322106052422896e-05, 0.017756393179297447, -0.010040433146059513, -0.010040433146059513, -0.0036997864954173565, 0.01556105725467205, 0.023541748523712158, -0.010033976286649704, 0.0107571454718709, 0.00712838489562273, -0.02266361378133297, 0.002879764186218381, 0.017201101407408714, 0.006188909988850355, 0.013817702420055866, -0.007496426347643137, 0.00487170834094286, -0.010473043657839298, -0.01918981783092022, -0.003796639619395137, -0.005698187742382288, 0.017640169709920883, 0.014321338385343552, -0.027325473725795746, 0.0012671607546508312, 0.0009628807893022895, 0.004306732211261988, -0.01643919199705124, -0.002137223957106471, 0.019577231258153915, -0.02142389491200447, 0.0013381863245740533, 0.006082371808588505, -0.02179839462041855, -0.014566699042916298, -0.02946915477514267, 0.010105001740157604, 0.007761158049106598, -0.012054977007210255, 0.02112687937915325, 0.013088075444102287, -0.0036061620339751244, -0.01082171406596899, -0.01292019709944725, 0.0039128633216023445, -0.013740220107138157, -0.00183697952888906, -0.01873783767223358, 0.007935493253171444, -0.013049334287643433, 0.004232478328049183, -0.04589543491601944, 0.03187111020088196, -0.019306041300296783, 0.00821959599852562, -0.02634403109550476, 0.014179286547005177, 0.00425184890627861, -0.005872523412108421, 0.011628823354840279, 0.009058988653123379, 0.014992852695286274, -0.013494858518242836, 0.00022074424487072974, -0.0007494004676118493, -0.0025246362201869488, 0.009078359231352806, 0.020649069920182228, -0.006185681559145451, -0.012054977007210255, 0.0017401265213266015, 0.002737713046371937, -0.004603748209774494, 0.0369332991540432, 0.22542224824428558, -0.011422202922403812, 0.0031412672251462936, 0.04540470987558365, -0.00017544526781421155, 0.036313436925411224, 0.01651667430996895, 0.0033059176057577133, -0.025375500321388245, 0.009510969743132591, -0.026963889598846436, 0.012371363118290901, 0.0136110819876194, 0.0003603740769904107, 0.0025391641538590193, -0.028539367020130157, -0.01636170968413353, -0.017343154177069664, -0.037320710718631744, -0.019732195883989334, -0.001901548239402473, -0.0023922703694552183, -0.016129260882735252, -0.019241472706198692, 0.006818454712629318, -0.011809615418314934, -0.002891063690185547, -0.00868449080735445, 0.01895737089216709, 0.02779036946594715, -0.008516611531376839, -0.0021049396600574255, 0.00421633617952466, -0.005449598655104637, -0.016619984060525894, 0.008568266406655312, -0.004855566192418337, -0.001212277333252132, 0.0036061620339751244, 0.0060081179253757, -0.01955140382051468, 0.01053115539252758, -0.006205052137374878, 0.030243979766964912, -0.012616724707186222, 0.024923518300056458, -0.009459314867854118, 0.01270066387951374, 0.015070335008203983, 0.01477331854403019, -0.027893679216504097, -0.0205586738884449, 0.033911481499671936, 0.06141774728894234, -0.01562562584877014, 0.010214768350124359, -0.003774040611460805, 0.0035415932070463896, -0.007367288693785667, 0.0003297039365861565, -0.004071056842803955, 0.015483574941754341, -0.02549172379076481, 0.017717652022838593, -0.012145373038947582, 0.009724046103656292, -0.03858625516295433, 0.019925901666283607, 0.016839517280459404, -0.013585254549980164, 0.004613433964550495, -0.03055390901863575, -0.015987209975719452, -0.016852430999279022, -0.032981693744659424, -0.016452105715870857, 0.029004260897636414, 0.0039128633216023445, -0.010402018204331398, 0.01714944653213024, 0.011396375484764576, -0.0366491936147213, -0.01006626058369875, -0.021088138222694397, -0.025091396644711494, -0.04698018729686737, 0.016025951132178307, -0.002561763161793351, -0.009801529347896576, 0.02395498752593994, -0.01324949786067009, -0.006947592366486788, -0.015083248727023602, -0.020080866292119026, 0.01752394624054432, -0.01136409118771553, 0.009336634539067745, 0.007218780927360058, -0.02657647803425789, -0.007922579534351826, -0.024355314671993256, -0.01401140820235014, 0.009601365774869919, 0.005791812669485807, -0.01621965877711773, 0.020222917199134827, 0.0011033177142962813, 0.01270066387951374, -0.012358449399471283, 0.0050492724403738976, 0.012061433866620064, -0.019422264769673347, 0.010718404315412045, 0.0071412986144423485, -0.019964642822742462, 0.01845373585820198, 0.00273287040181458, 0.00789029523730278, 0.02706719934940338, -0.03187111020088196, 0.0015916185220703483, 0.01129306573420763, 0.012332621961832047, -0.005724015180021524, 0.0046166623942554, -0.024729812517762184, -0.00754808122292161, 0.009401203133165836, 0.002666687360033393, -0.029882395640015602, -0.007786985486745834, -0.017110705375671387, 0.018221287056803703, -0.011047705076634884, -0.00693467864766717, 0.008025889284908772, 3.1606505217496306e-06, 0.005126754753291607, -0.00434547383338213, 0.01636170968413353, -0.011157471686601639, 0.004868479911237955, -0.005930635146796703, 0.020816950127482414, 0.02250864915549755, -0.015354436822235584, 0.008845912292599678, 0.009078359231352806, 0.0031945365481078625, -0.013727306388318539, -0.010156656615436077, -0.015431920066475868, 0.007625563535839319, -0.026318203657865524, 0.012803973630070686, -0.02634403109550476, -0.03680415824055672, -0.028074471279978752, -0.01642627827823162, 0.02939167246222496, -0.0308380126953125, 0.010427845641970634, 0.025168880820274353, 0.0026925147976726294, -0.024355314671993256, -0.03063139133155346, -0.16612236201763153, 0.03207772970199585, 0.02324473299086094, -0.004665088839828968, 0.01838916540145874, 0.0037320710252970457, 0.011725676245987415, 0.0017191417282447219, 0.020093780010938644, 0.0014745877124369144, 0.021669255569577217, 0.002995987655594945, -0.03489292785525322, 0.009749873541295528, 0.02642151340842247, 0.01423094142228365, 0.0018095378763973713, 0.013094532303512096, 0.0018402079585939646, 0.008258337154984474, 0.024006642401218414, -0.020829863846302032, -0.005833782255649567, -0.01169339194893837, -0.0030637849122285843, -0.012061433866620064, 0.007496426347643137, 0.02258613146841526, -0.0023535292129963636, 0.005446370225399733, -0.017795134335756302, -0.009620736353099346, 0.03300752118229866, 0.0050492724403738976, 0.01093148160725832, 0.01299122255295515, -0.01636170968413353, -0.02208249643445015, 0.0004903185763396323, 0.029081743210554123, 0.0215142909437418, 0.007870924659073353, 0.029856568202376366, -0.0015149432001635432, 0.004787769168615341, 0.02026165835559368, 0.005717558320611715, 0.0007998447981663048, 0.013830616138875484, -0.01593555510044098, -0.006366474088281393, -0.019809678196907043, -0.008987963199615479, -0.010879825800657272, 0.009504512883722782, 0.02381293661892414, 0.014579612761735916, 0.0069863335229456425, -0.0016658725216984749, -0.022986458614468575, -0.008542438969016075, -0.018414992839097977, 0.005278491415083408, -0.017911357805132866, -0.01607760600745678, -0.02048119157552719, -0.000788948847912252, -0.007218780927360058, -0.010356820188462734, 0.012791059911251068, 0.0002893485070671886, -0.00037712158518843353, -0.0018030810169875622, 0.0028297232929617167, 0.016684552654623985, 0.00010724458115873858, -0.013843529857695103, 0.030373116955161095, -0.01277814619243145, -0.005594877991825342, -0.022185806185007095, 0.03305917605757713, 0.011099359951913357, -0.0009564238716848195, 0.007070272695273161, 0.01146740186959505, -0.010544069111347198, -0.007703046314418316, -0.02324473299086094, -0.015406092628836632, 0.020545760169625282, -0.012048520147800446, -0.003622304182499647, -0.0015173645224422216, 0.01263609528541565, 0.02657647803425789, 0.003825695486739278, -0.009795072488486767, 0.007406030315905809, 0.004012944642454386, -0.001643273513764143, -0.007263978943228722, -0.0003640060604084283, 0.030863840132951736, 0.02128184400498867, 0.024381142109632492, 0.01692991331219673, 0.01115101482719183, 0.019138162955641747, 0.010176027193665504, -0.004113026428967714, -0.0005782934604212642, 0.014463389292359352, 0.017356067895889282, 0.004038772080093622, 0.02497517317533493, 0.005959691014140844, -0.011531970463693142, 0.033782344311475754, 0.0019693453796207905, 0.04886559396982193, -0.0007106592529453337, -0.021088138222694397, -0.0019289900083094835, -0.010098544880747795, -0.007360831834375858, -0.06916598975658417, -0.022043755277991295, 0.02316725067794323, -0.0001706026232568547, -0.014540871605277061, 0.012177657335996628, -0.00829062145203352, 0.005853152833878994, -0.014166372828185558, 0.009614279493689537, 0.000888626731466502, -0.04677356779575348, -0.0006751464679837227, -0.012171200476586819, 0.00891048088669777, -0.0060113463550806046, -0.010569896548986435, -0.001041977433487773, -0.008800714276731014, 0.015083248727023602, 0.0039709750562906265, 0.011854813434183598, 0.01136409118771553, 0.0065763224847614765, -0.011661107651889324, -0.0017885530833154917, -0.021591773256659508, 0.03517702966928482, 0.009472228586673737, 0.012209941633045673, 0.0012873384403064847, 0.010892740450799465, -0.0036126188933849335, -0.019228558987379074, -0.021604686975479126, 0.001825680024921894, -0.021320585161447525, -0.012597354128956795, 0.0034350550267845392, -0.0569237656891346, 0.008568266406655312, 0.025065569207072258, -0.013184929266571999, -0.03205190226435661, -0.014592526480555534, -0.009536797180771828, 0.010724861174821854, 0.011099359951913357, 0.016684552654623985, -0.022134151309728622, -0.0344538576900959, -0.023787109181284904, -0.014192200265824795, 0.0024116409476846457, 0.02409704029560089, -0.00658600777387619, 0.01678786240518093, -0.008167941123247147, -0.002761926269158721, -0.0005762756918556988, -0.0016166388522833586, 0.002079112222418189, -0.0033059176057577133, 0.017614342272281647, 0.0005762756918556988, 0.004619890823960304, -0.006440727971494198, -0.02142389491200447, 0.01053761225193739, -0.019202731549739838, -0.020080866292119026, 0.00340277049690485, -0.03497041016817093, -0.003609390463680029, -0.033549897372722626, -0.016116347163915634, -0.018130891025066376, -0.0136110819876194, 0.03698495402932167, -0.015186558477580547, -0.011777331121265888, -0.011654650792479515, 0.02337387017905712, -0.02359340339899063, 0.037888914346694946, 0.01983550563454628, -0.007612649817019701, 0.010615094564855099, 0.0005395521875470877, -0.005181638523936272, -0.02134641259908676, 0.01642627827823162, 0.015664367005228996, -0.02815195359289646, -0.008535982109606266, 0.015354436822235584, 0.006456870120018721, 0.02627946250140667, 0.015651453286409378, -0.0061211129650473595, -0.0014794303569942713, 0.012552155181765556, -0.056510526686906815, 0.016671638935804367, -0.0006678825011476874, -0.0004168716841377318, 0.015199472196400166, 0.0017788676777854562, 0.0025407783687114716, -0.001502029481343925, 0.013959753327071667, 0.005184866953641176, -0.020313313230872154, 0.001076683052815497, 0.005120297893881798, 0.008813627995550632, -0.032904211431741714, -0.007774071767926216, 0.00646332697942853, 0.018117977306246758, 0.00502990186214447, -0.005055729299783707, 0.002456839196383953, 0.016762034967541695, 0.007289806380867958, -0.0002102518337778747, -0.01895737089216709, -0.012655465863645077, -0.003922548610717058, 0.007399572990834713, -0.019667627289891243, -0.004455240443348885, 0.020106693729758263, -0.026912234723567963, -0.026473168283700943, 0.04251203313469887, -0.009530340321362019, -0.031664490699768066, 0.008342276327311993, 0.008723231963813305, 0.03202607482671738, 0.019009025767445564, -0.010905654169619083, -0.00897504948079586, 0.01183544285595417, -0.026473168283700943, -0.015264040790498257, 0.012687750160694122, -0.004713515285402536, 0.01709779165685177, 0.01379187498241663, -0.012080804444849491, -0.018892802298069, 0.024019557982683182, 0.005407628603279591, -0.015444833785295486, -0.009394746273756027, -0.03509954735636711, 0.03003736026585102, -0.01184189971536398, 0.008477870374917984, -0.008807171136140823, 0.03003736026585102, 0.014540871605277061, 0.021604686975479126, 0.001436653663404286, 0.014734577387571335, -0.016452105715870857, -0.007037988398224115, 0.008490784093737602, 0.011525513604283333, -0.05279137194156647, -0.016684552654623985, -0.0063632456585764885, 0.01299122255295515, 0.018983198329806328, -0.0048652514815330505, 0.010072717443108559, 0.003396313637495041, -0.0025214077904820442, -0.009349548257887363, 0.016245486214756966, 0.020429536700248718, -0.008116286247968674, -0.04091072827577591, 0.004190508741885424, 0.029649948701262474, 0.03047642670571804, 0.0010113072348758578, 0.0035351363476365805, 0.0004822475020773709, 0.01060218084603548, -0.01209371816366911, 0.008787800557911396, 0.004261534195393324, -0.0036836443468928337, -0.01895737089216709, 0.04011007770895958, -0.022056668996810913, -0.013301152735948563, 0.0017401265213266015, 0.016335882246494293, -0.010046890005469322, -0.006101742386817932, 0.00448752474039793, -0.030347289517521858, -0.023283474147319794, 0.016710380092263222, -0.029494982212781906, -0.019951729103922844, 0.0011735361767932773, 0.005188095383346081, 0.03706243634223938, 0.010970222763717175, -0.017795134335756302, 0.0058854371309280396, -0.009349548257887363, 0.017175273969769478, -0.010311621241271496, -0.023490093648433685, -0.027325473725795746, 0.01947391964495182, 0.01810506358742714, 0.022095410153269768, -0.000895083649083972, -0.03706243634223938, 0.010621551424264908, 0.0244586244225502, 0.026189064607024193, -0.014243856072425842, -0.006259935442358255, 0.011790244840085506, 0.008226052857935429, -0.011280152015388012, 0.008852369152009487, 0.0047490280121564865, 0.011286608874797821, 0.012126002460718155, -0.02395498752593994, 0.03220686689019203, -0.01702030934393406, 0.03897366672754288, 0.00974341668188572, -0.023051027208566666, 0.00890402402728796, -0.03610681742429733, 0.01013082917779684, 0.02134641259908676, -0.0042357067577540874, -0.011254324577748775, -0.015909727662801743, -0.013301152735948563, 5.8578439166012686e-06, 0.025814566761255264, 0.006682860665023327, -0.03517702966928482, -0.014360079541802406, -0.02923670783638954, 0.007780528627336025, -0.0023987272288650274, -0.02004212513566017, 0.015173644758760929, 0.001025028177537024, 0.030605563893914223, -0.009388289414346218, -0.00761910667642951, -0.0136110819876194, 0.030605563893914223, 0.021953359246253967, -0.0010088859125971794, -0.02882346883416176, -0.008794257417321205, -0.013352807611227036, -0.017678910866379738, -0.032258521765470505, 0.023567575961351395, 0.001000814838334918, 0.01549648866057396, -0.006792627274990082, 0.012358449399471283, 0.01593555510044098, 0.008561809547245502, 0.0058789802715182304, -0.020752381533384323, -0.03256845474243164, 0.020326226949691772, -0.0016150246374309063, -0.004316417500376701, 0.01270712073892355, -0.012190571054816246]; Save and close the file.
Connect to your cluster using mongosh
.
Open mongosh
in a terminal window and connect to your
cluster. For detailed instructions on connecting, see
Connect via mongosh
.
Use the sample_mflix
database.
Run the following command at mongosh
prompt:
use sample_mflix
switched to db sample_mflix
Load the embeddings to use in the query.
Run the following command to load the embeddings after replacing
<path-to-file>
with the absolute path to the embeddings.js
file:
load('<path-to-query>/embeddings.js');
To verify that the embeddings loaded successfully, run the following command:
STAR_WARS_EMBEDDING.length
1536
Run the following Atlas Search queries against the embedded_movies
collection.
1 db.embedded_movies.aggregate([ 2 { 3 $rankFusion: { 4 input: { 5 pipelines: { 6 vectorPipeline: [ 7 { 8 "$vectorSearch": { 9 "index": "hybrid-vector-search", 10 "path": "plot_embedding", 11 "queryVector": STAR_WARS_EMBEDDING, 12 "numCandidates": 100, 13 "limit": 20 14 } 15 } 16 ], 17 fullTextPipeline: [ 18 { 19 "$search": { 20 "index": "hybrid-full-text-search", 21 "phrase": { 22 "query": "star wars", 23 "path": "title" 24 } 25 } 26 }, 27 { "$limit": 20 } 28 ] 29 } 30 }, 31 combination: { 32 weights: { 33 vectorPipeline: 0.7, 34 fullTextPipeline: 0.3 35 } 36 }, 37 "scoreDetails": true 38 } 39 }, 40 { 41 "$project": { 42 _id: 1, 43 title: 1, 44 plot: 1, 45 scoreDetails: {"$meta": "scoreDetails"} 46 } 47 }, 48 { 49 "$limit": 20 50 } 51 ]);
[ { _id: ObjectId('573a1397f29313caabce68f6'), plot: "Luke Skywalker joins forces with a Jedi Knight, a cocky pilot, a wookiee and two droids to save the universe from the Empire's world-destroying battle-station, while also attempting to rescue Princess Leia from the evil Darth Vader.", title: 'Star Wars: Episode IV - A New Hope', scoreDetails: { value: 0.01626123744050767, description: 'value output by reciprocal rank fusion algorithm, computed as sum of (weight * (1 / (60 + rank))) across input pipelines from which this document is output, from:', details: [ { inputPipelineName: 'fullTextPipeline', rank: 2, weight: 0.5, value: 2.9629626274108887, details: [] }, { inputPipelineName: 'vectorPipeline', rank: 1, weight: 0.5, value: 0.9400461912155151, details: [] } ] } }, { _id: ObjectId('573a139af29313caabcf0f5f'), plot: 'Two Jedi Knights escape a hostile blockade to find allies and come across a young boy who may bring balance to the Force, but the long dormant Sith resurface to reclaim their old glory.', title: 'Star Wars: Episode I - The Phantom Menace', scoreDetails: { value: 0.016129032258064516, description: 'value output by reciprocal rank fusion algorithm, computed as sum of (weight * (1 / (60 + rank))) across input pipelines from which this document is output, from:', details: [ { inputPipelineName: 'fullTextPipeline', rank: 2, weight: 0.5, value: 2.9629626274108887, details: [] }, { inputPipelineName: 'vectorPipeline', rank: 2, weight: 0.5, value: 0.9308199286460876, details: [] } ] } }, { _id: ObjectId('573a13c0f29313caabd62f62'), plot: 'Anakin Skywalker and Ahsoka Tano must rescue the kidnapped son of Jabba the Hutt, but political intrigue complicates their mission.', title: 'Star Wars: The Clone Wars', scoreDetails: { value: 0.015889029003783105, description: 'value output by reciprocal rank fusion algorithm, computed as sum of (weight * (1 / (60 + rank))) across input pipelines from which this document is output, from:', details: [ { inputPipelineName: 'fullTextPipeline', rank: 1, weight: 0.5, value: 3.6164965629577637, details: [] }, { inputPipelineName: 'vectorPipeline', rank: 5, weight: 0.5, value: 0.9257078170776367, details: [] } ] } }, { _id: ObjectId('573a1397f29313caabce77d9'), plot: 'After the rebels have been brutally overpowered by the Empire on their newly established base, Luke Skywalker takes advanced Jedi training with Master Yoda, while his friends are pursued by Darth Vader as part of his plan to capture Luke.', title: 'Star Wars: Episode V - The Empire Strikes Back', scoreDetails: { value: 0.015749007936507936, description: 'value output by reciprocal rank fusion algorithm, computed as sum of (weight * (1 / (60 + rank))) across input pipelines from which this document is output, from:', details: [ { inputPipelineName: 'fullTextPipeline', rank: 4, weight: 0.5, value: 2.7174296379089355, details: [] }, { inputPipelineName: 'vectorPipeline', rank: 3, weight: 0.5, value: 0.9270252585411072, details: [] } ] } }, { _id: ObjectId('573a1397f29313caabce8cdb'), plot: 'After rescuing Han Solo from the palace of Jabba the Hutt, the rebels attempt to destroy the second Death Star, while Luke struggles to make Vader return from the dark side of the Force.', title: 'Star Wars: Episode VI - Return of the Jedi', scoreDetails: { value: 0.015625, description: 'value output by reciprocal rank fusion algorithm, computed as sum of (weight * (1 / (60 + rank))) across input pipelines from which this document is output, from:', details: [ { inputPipelineName: 'fullTextPipeline', rank: 4, weight: 0.5, value: 2.7174296379089355, details: [] }, { inputPipelineName: 'vectorPipeline', rank: 4, weight: 0.5, value: 0.9263832569122314, details: [] } ] } }, { _id: ObjectId('573a139af29313caabcf1258'), plot: 'Ten years after initially meeting, Anakin Skywalker shares a forbidden romance with Padmè, while Obi-Wan investigates an assassination attempt on the Senator and discovers a secret clone army crafted for the Jedi.', title: 'Star Wars: Episode II - Attack of the Clones', scoreDetails: { value: 0.015165441176470588, description: 'value output by reciprocal rank fusion algorithm, computed as sum of (weight * (1 / (60 + rank))) across input pipelines from which this document is output, from:', details: [ { inputPipelineName: 'fullTextPipeline', rank: 4, weight: 0.5, value: 2.7174296379089355, details: [] }, { inputPipelineName: 'vectorPipeline', rank: 8, weight: 0.5, value: 0.9229284524917603, details: [] } ] } }, { _id: ObjectId('573a139af29313caabcf124d'), plot: 'As the Clone Wars near an end, the Sith Lord Darth Sidious steps out of the shadows, at which time Anakin succumbs to his emotions, becoming Darth Vader and putting his relationships with Obi-Wan and Padme at risk.', title: 'Star Wars: Episode III - Revenge of the Sith', scoreDetails: { value: 0.014569256756756757, description: 'value output by reciprocal rank fusion algorithm, computed as sum of (weight * (1 / (60 + rank))) across input pipelines from which this document is output, from:', details: [ { inputPipelineName: 'fullTextPipeline', rank: 4, weight: 0.5, value: 2.7174296379089355, details: [] }, { inputPipelineName: 'vectorPipeline', rank: 14, weight: 0.5, value: 0.9172446727752686, details: [] } ] } }, { _id: ObjectId('573a1397f29313caabce6f53'), plot: 'In this Star Wars take-off, the peaceful planet of Jillucia has been nearly wiped out by the Gavanas, whose leader takes orders from his mother (played a comic actor in drag) rather than ...', title: 'Message from Space', scoreDetails: { value: 0.007575757575757576, description: 'value output by reciprocal rank fusion algorithm, computed as sum of (weight * (1 / (60 + rank))) across input pipelines from which this document is output, from:', details: [ { inputPipelineName: 'fullTextPipeline', rank: 0, weight: 0.5 }, { inputPipelineName: 'vectorPipeline', rank: 6, weight: 0.5, value: 0.9238690137863159, details: [] } ] } }, { _id: ObjectId('573a139df29313caabcfa90b'), plot: 'In this Star Wars take-off, the peaceful planet of Jillucia has been nearly wiped out by the Gavanas, whose leader takes orders from his mother (played a comic actor in drag) rather than ...', title: 'Message from Space', scoreDetails: { value: 0.007575757575757576, description: 'value output by reciprocal rank fusion algorithm, computed as sum of (weight * (1 / (60 + rank))) across input pipelines from which this document is output, from:', details: [ { inputPipelineName: 'fullTextPipeline', rank: 0, weight: 0.5 }, { inputPipelineName: 'vectorPipeline', rank: 6, weight: 0.5, value: 0.9238690137863159, details: [] } ] } }, { _id: ObjectId('573a13d9f29313caabda92ff'), plot: 'A group of intergalactic criminals are forced to work together to stop a fanatical warrior from taking control of the universe.', title: 'Guardians of the Galaxy', scoreDetails: { value: 0.007246376811594203, description: 'value output by reciprocal rank fusion algorithm, computed as sum of (weight * (1 / (60 + rank))) across input pipelines from which this document is output, from:', details: [ { inputPipelineName: 'fullTextPipeline', rank: 0, weight: 0.5 }, { inputPipelineName: 'vectorPipeline', rank: 9, weight: 0.5, value: 0.9183617234230042, details: [] } ] } }, { _id: ObjectId('573a13d5f29313caabd9c312'), plot: 'A group of intergalactic criminals are forced to work together to stop a fanatical warrior from taking control of the universe.', title: 'Guardians of the Galaxy', scoreDetails: { value: 0.007142857142857143, description: 'value output by reciprocal rank fusion algorithm, computed as sum of (weight * (1 / (60 + rank))) across input pipelines from which this document is output, from:', details: [ { inputPipelineName: 'fullTextPipeline', rank: 0, weight: 0.5 }, { inputPipelineName: 'vectorPipeline', rank: 10, weight: 0.5, value: 0.9183551073074341, details: [] } ] } }, { _id: ObjectId('573a13d4f29313caabd9887f'), plot: 'In this breathtaking science fiction spectacle, a strange mechanical device lands on a desolate world and uses the planet to undergo a startling transformation, that has profound implications for an entire galaxy.', title: 'Abiogenesis', scoreDetails: { value: 0.007042253521126761, description: 'value output by reciprocal rank fusion algorithm, computed as sum of (weight * (1 / (60 + rank))) across input pipelines from which this document is output, from:', details: [ { inputPipelineName: 'fullTextPipeline', rank: 0, weight: 0.5 }, { inputPipelineName: 'vectorPipeline', rank: 11, weight: 0.5, value: 0.918245792388916, details: [] } ] } }, { _id: ObjectId('573a1398f29313caabce9091'), plot: "A Duke's son leads desert warriors against the galactic emperor and his father's evil nemesis when they assassinate his father and free their desert world from the emperor's rule.", title: 'Dune', scoreDetails: { value: 0.006944444444444444, description: 'value output by reciprocal rank fusion algorithm, computed as sum of (weight * (1 / (60 + rank))) across input pipelines from which this document is output, from:', details: [ { inputPipelineName: 'fullTextPipeline', rank: 0, weight: 0.5 }, { inputPipelineName: 'vectorPipeline', rank: 12, weight: 0.5, value: 0.9180452823638916, details: [] } ] } }, { _id: ObjectId('573a1398f29313caabce90bd'), plot: 'Wicket the Ewok and his friends agree to help two shipwrecked human children on a quest to find their parents.', title: 'The Ewok Adventure', scoreDetails: { value: 0.00684931506849315, description: 'value output by reciprocal rank fusion algorithm, computed as sum of (weight * (1 / (60 + rank))) across input pipelines from which this document is output, from:', details: [ { inputPipelineName: 'fullTextPipeline', rank: 0, weight: 0.5 }, { inputPipelineName: 'vectorPipeline', rank: 13, weight: 0.5, value: 0.9176332354545593, details: [] } ] } }, { _id: ObjectId('573a1398f29313caabce8d67'), plot: 'A futuristic, sensitive tale of adventure and confrontation when a 10 year old boy is accidentally kidnapped by a spaceship filled with a motley crew of space pirates.', title: 'Space Raiders', scoreDetails: { value: 0.006666666666666667, description: 'value output by reciprocal rank fusion algorithm, computed as sum of (weight * (1 / (60 + rank))) across input pipelines from which this document is output, from:', details: [ { inputPipelineName: 'fullTextPipeline', rank: 0, weight: 0.5 }, { inputPipelineName: 'vectorPipeline', rank: 15, weight: 0.5, value: 0.916418731212616, details: [] } ] } }, { _id: ObjectId('573a13b0f29313caabd33d15'), plot: 'Two young brothers are drawn into an intergalactic adventure when their house is hurled through the depths of space by the magical board game they are playing.', title: 'Zathura: A Space Adventure', scoreDetails: { value: 0.006578947368421052, description: 'value output by reciprocal rank fusion algorithm, computed as sum of (weight * (1 / (60 + rank))) across input pipelines from which this document is output, from:', details: [ { inputPipelineName: 'fullTextPipeline', rank: 0, weight: 0.5 }, { inputPipelineName: 'vectorPipeline', rank: 16, weight: 0.5, value: 0.9160659909248352, details: [] } ] } }, { _id: ObjectId('573a1397f29313caabce7509'), plot: 'An outlaw smuggler and her alien companion are recruited by the Emperor of the Galaxy to rescue his son and destroy a secret weapon by the evil Count Zarth Arn.', title: 'Starcrash', scoreDetails: { value: 0.006493506493506494, description: 'value output by reciprocal rank fusion algorithm, computed as sum of (weight * (1 / (60 + rank))) across input pipelines from which this document is output, from:', details: [ { inputPipelineName: 'fullTextPipeline', rank: 0, weight: 0.5 }, { inputPipelineName: 'vectorPipeline', rank: 17, weight: 0.5, value: 0.915353000164032, details: [] } ] } }, { _id: ObjectId('573a139bf29313caabcf3d4b'), plot: 'An Air Force astronaut crash lands on a mysterious planet where evolved, talking apes dominate a race of primitive humans.', title: 'Planet of the Apes', scoreDetails: { value: 0.00641025641025641, description: 'value output by reciprocal rank fusion algorithm, computed as sum of (weight * (1 / (60 + rank))) across input pipelines from which this document is output, from:', details: [ { inputPipelineName: 'fullTextPipeline', rank: 0, weight: 0.5 }, { inputPipelineName: 'vectorPipeline', rank: 18, weight: 0.5, value: 0.9140176773071289, details: [] } ] } }, { _id: ObjectId('573a13a3f29313caabd0ec59'), plot: 'An Air Force astronaut crash lands on a mysterious planet where evolved, talking apes dominate a race of primitive humans.', title: 'Planet of the Apes', scoreDetails: { value: 0.00641025641025641, description: 'value output by reciprocal rank fusion algorithm, computed as sum of (weight * (1 / (60 + rank))) across input pipelines from which this document is output, from:', details: [ { inputPipelineName: 'fullTextPipeline', rank: 0, weight: 0.5 }, { inputPipelineName: 'vectorPipeline', rank: 18, weight: 0.5, value: 0.9140176773071289, details: [] } ] } }, { _id: ObjectId('573a13b0f29313caabd34a3e'), plot: 'A spaceship arrives in Arizona, 1873, to take over the Earth, starting with the Wild West region. A posse of cowboys and natives are all that stand in their way.', title: 'Cowboys & Aliens', scoreDetails: { value: 0.00625, description: 'value output by reciprocal rank fusion algorithm, computed as sum of (weight * (1 / (60 + rank))) across input pipelines from which this document is output, from:', details: [ { inputPipelineName: 'fullTextPipeline', rank: 0, weight: 0.5 }, { inputPipelineName: 'vectorPipeline', rank: 20, weight: 0.5, value: 0.9139271974563599, details: [] } ] } } ]
About the Query
The sample query retrieves the sorted search results from the semantic search and the full-text search, and assigns a reciprocal rank score to the documents in the results based on their position in the results array. The reciprocal rank score is calculated by using the following formula:
1.0/{document position in the results + constant value}
The query then adds the scores from both the searches for each document,
ranks the documents based on the combined score, and sorts the documents
to return a single result. The value for constant is always 60
.
Query Weights
The sample query defines the following weights to the pipelines to influence that pipeline's rank contribution to the final score:
vectorPipeline
= 0.5fullTextPipeline
= 0.5
You can adjust the weights to give more importance to one method of search. Note that a lower number provides higher weight.
The weighted reciprocal rank score is calculated by using the following formula:
weight x reciprocal rank
The scoreDetails.value
shows the raw score from that pipeline
before it is weighted and combined by using reciprocal rank fusion. The
scoreDetails.details.value
shows the weighted reciprocal rank score.
Query Stages
The sample query uses the $rankFusion
stage to execute the
semantic and full text queries independently and then de-duplicate and
combine the input query results into a final ranked results set. It
returns a ranked set of documents based on the ranks that appear in
their input pipelines and the pipeline weights. Specifically, this stage
takes the following input pipelines:
| This pipeline contains the |
|
The sample query uses the following stages to combine the results of the semantic and text search and return a single ranked list of documents in the results: