Vector Search is not working on Vector Type

Aggregation query is not working when assigning vector type in vector search.
Error : BSON field ‘$vectorSearch.queryVector.0’ is the wrong type ‘array’, expected type ‘double’, full error: {‘ok’: 0.0, ‘errmsg’: “BSON field ‘$vectorSearch.queryVector.0’ is the wrong type ‘array’, expected type ‘double’”

embedding =[0.014278386, 0.0075417166, -0.044294905, -0.019767128, -0.02309833, 0.00091970415, 0.070761956, 0.05008969, 0.0041110516, 0.024706092, 0.04609209, -0.05229452, 0.0690272, 0.040811297, -0.0755878, 0.006145637, -0.0680656, 0.015207415, -0.037261624, 0.060224675, -0.046326384, 0.012747517, -0.033865206, -0.045163088, 0.063808426, 0.06577738, -0.0060202433, -0.0009039882, -0.015446796, -0.0903043, -0.053782284, 0.036593817, 0.028617138, 0.008146116, -0.009073227, -0.00827111, -0.07293156, -0.0015446541, -0.0048709577, -0.006017563, -0.022863876, 0.015402334, 0.0131715555, -0.020165898, 0.0020754563, -0.0030080907, 0.030510513, 0.0021528027, 0.034054022, 0.07910542, 0.033335287, -0.024916044, -0.0569326, 0.11824868, 0.033701193, -0.09406432, -0.015403466, -0.028235713, -0.07795807, 0.0008334506, 0.042349767, 0.09207516, 0.026971921, 0.018725256, 0.10303649, -0.02598631, 0.039820876, 0.16823435, -0.13451369, 0.028840331, -0.0013199158, -0.05761193, -0.031641364, -0.040137324, 0.01246647, 0.050856736, 0.05054336, -0.0056410227, 0.017035613, -0.08095594, 0.0037973404, 0.021608885, -0.06540942, -0.0143331485, 0.014983711, 0.0021922074, -0.0075309123, 0.013113344, 0.070909455, -0.01617268, 0.0012039293, -0.028609376, 0.09479178, -0.06315476, -0.039366554, -0.00023512529, -0.013063307, -0.07308118, 0.034919135, 0.07230722, 0.016531631, -0.03627836, 0.049489867, -0.06811563, 0.0016461551, -0.014993437, 0.1292995, 0.035873592, -0.035726324, -0.020664066, 0.06434987, 0.010202672, 0.04358271, -0.060653295, 0.046522368, 0.029942568, -0.006514805, 0.00999576, 0.07899055, -0.12080558, 0.09854054, 0.061791, 0.017153163, 0.052935988, -0.092609495, -0.045934748, -0.018660713, -8.786519e-34, -0.0011554797, -0.08464825, 0.040416103, -0.00079257926, 0.03341349, 0.0078712795, 0.06880633, 0.055577375, 0.024036638, 0.055547938, -0.02160719, 0.022492297, -0.013934239, -0.045385677, 0.057485152, 0.04887187, -0.008177031, 0.06642902, 0.028565334, 0.015152638, 0.0010395893, -0.06800768, 0.09175921, -0.01661596, 0.08773696, -0.0019553339, 0.0011536679, -0.0010815489, -0.08955018, -0.028955102, 0.117379405, 0.07015154, -0.012612832, 0.0031074516, -0.015168903, 0.047044065, -0.04109906, 0.061768703, 0.008876829, 0.015287048, -0.027855972, -0.037348934, 0.0018761199, -0.054587882, -0.10176719, -0.0034989004, 0.025135553, 0.0497842, -0.010535417, 0.07664115, -0.09212419, -0.08482258, -0.06196826, -0.014722411, -0.0051697255, 0.03565485, -0.04846371, 0.0156136425, -0.058909487, 0.026443446, -0.035157267, -0.038516566, -0.004540944, -0.04516422, -0.022859037, 0.045886047, -0.013337829, 0.008096619, 0.08595001, -0.025213674, -0.08050843, -0.028874839, 0.11930241, -0.0034080665, -0.032934476, 0.025857309, -0.003113441, -0.058593128, 0.03242367, 0.04015776, -0.11434285, 0.0059491657, 0.05743923, 0.03250773, 0.030557401, 0.090697214, 0.049140625, -0.025057169, -0.013044876, 0.035258815, -0.030779207, -0.0347456, 0.05299582, 0.027986998, -0.01261401, -3.2747166e-35, -0.046028417, 0.14432348, -0.0453897, -0.017466499, -0.027511874, 0.0015290837, 0.027882956, 0.00146637, -0.07045574, 0.028141337, -0.086944126, 0.024540678, -0.031082602, 0.017576065, 0.069401585, 0.0568599, 0.05549853, -0.028909162, 0.026934402, -0.06653704, -0.09054517, 0.032198433, 0.03228923, -0.021261994, -0.033186138, 0.06302736, -0.060398336, -0.0637171, -0.020405822, 0.09866822, 0.083079554, -0.019284012, -0.06698303, 0.034306962, -0.037706163, -0.121063754, 0.01611517, -0.001191423, 0.0234532, -0.047472905, 0.0661378, -0.03557448, 0.008091291, 0.014266217, 0.014553856, -0.03928734, 0.0074660783, -0.05452471, 0.09357604, -0.04533352, 0.021344023, -0.032644298, -0.04833411, 0.033115856, -0.074141674, 0.053846285, 0.06544485, 0.006330873, 0.07006881, -0.07780103, -0.04251041, 0.018729743, 0.028900526, -0.0037782409, -0.07969743, 0.011539349, -0.050956234, -0.078963146, 0.029665211, -0.042651366, 0.020675214, 0.021874297, -0.0057123513, -0.12407369, 0.008399104, 0.067655526, 0.0029993537, -0.11054711, -0.004761983, -0.00041252724, -0.00050341286, -0.023730291, 0.0063801464, -0.004230106, -0.113830134, -0.047306355, 0.008343499, -0.015276432, 0.019884726, 0.05900094, -0.087686785, 0.08199176, 0.036229048, 0.023563577, -0.016080001, -1.4110201e-08, -0.023606535, 0.045919124, -0.058210034, 0.0024900052, 0.010863408, -0.09714688, -0.024228444, 0.113090314, 0.017896075, 0.103672355, -0.019636856, -0.075329565, 0.053665496, 0.030154344, -0.055447288, 0.05129389, -0.07964748, 0.057922862, -0.044572778, -0.024277158, 0.0354937, 0.00461311, -0.03432383, -0.04853489, -0.0012632485, -0.030461315, 0.04017049, 0.018854156, 0.051700495, -0.019949336, 0.008917956, 0.09720917, 0.033236917, -0.026974574, 0.034117024, -0.03355223, 0.04166314, 0.016105114, -0.01674517, 0.05903645, -0.054545216, -0.06642336, 0.092353165, 0.037606247, 0.056612737, -0.061343312, -0.08958045, -0.011107702, 0.0017920594, -0.096019305, -0.0021671443, -0.041051835, 0.0399153, -0.002150272, 0.024942065, -0.0036997148, 0.07311741, 0.01137766, -0.0154892, 0.01764495, -0.04503822, -0.07409766, 0.038644835, -0.11561487], #generate_embedding(label)
    result = collectionname.aggregate([
    {
        "$vectorSearch":
        {
            "queryVector":embedding,
            "path":"label_emb",
            "numCandidates":100,
            "limit":2,
            "index":"TagSearch"
        }
    }    
    ]);

Any help is really appreciated.

There’s a comma at the end of the embedding line.

nystateofhealtWrote@ashish_jain3,

The error you’re encountering indicates that the BSON field $vectorSearch.queryVector.0 is expected to be of type double, but it’s being provided as an array instead.

Looking at your code, it seems that embedding is indeed an array, which is causing the issue. The queryVector field expects a single vector, but you’re passing an array of vectors.

To fix this issue, you need to ensure that embedding contains a single vector, not an array of vectors. If you’re trying to perform a vector search using multiple vectors, you’ll need to modify your aggregation pipeline accordingly.

Here’s an example of how you might modify your code to perform a vector search with multiple query vectors.

# List of embeddings (query vectors)
embeddings = [
    [0.014278386, 0.0075417166, ...],  # First embedding
    [0.024540678, -0.031082602, ...],  # Second embedding
    # Add more embeddings as needed
]

# Perform vector search for each query vector
results = []
for embedding in embeddings:
    result = collectionname.aggregate([
        {
            "$vectorSearch": {
                "queryVector": embedding,
                "path": "label_emb",
                "numCandidates": 100,
                "limit": 2,
                "index": "TagSearch"
            }
        }
    ])
    results.append(result)

# Process results as needed

This code iterates over a list of embeddings and performs a vector search for each embedding. The results are collected in a list called results, which you can then process as needed. Adjust the code according to your specific requirements and the structure of your data.
I hope this will answer you.