Hi Pratham,

Thank you for sharing. You must have $search as the first stage in the pipeline, even if executed within a subpipeline. The fix I would suggest for you is to have a first $search stage, then execute a $unionWith which executes the second $search stage as a subpipeline:

const documents = await collection
          .aggregate([
            {
              $search: {
                index: "default",
                knnBeta: {
                  vector: embedding,
                  path: "city_embedding",
                  k: 150,
                },
              },
            },
            {
              $limit: 50,
            },
            {
              $unionWith: {
                coll: "SearchLeads",
                pipeline: [
                  {
                    $search: {
                      index: "default",
                      knnBeta: {
                        vector: embedding,
                        path: "industry_embedding",
                        k: 150,
                      },
                    },
                  },
                  {
                    $limit: 50,
                  },
                ],
              },
            },
          ]).toArray();

Hope this helps and sorry for the delay in response!