def test_hybrid_search_structured_with_custom_vector_query(self):
        """
        Tests that using a custom vector query sends the correct arguments to vespa
        Structured. Uses searchable attributes.
        """
        sample_vector = [0.5 for _ in range(16)]

        original_query = self.config.vespa_client.query
        def pass_through_query(*arg, **kwargs):
            return original_query(*arg, **kwargs)

        mock_vespa_client_query = unittest.mock.MagicMock()
        mock_vespa_client_query.side_effect = pass_through_query

        with self.subTest("Custom vector query, with content, no context"):
            @unittest.mock.patch("marqo.vespa.vespa_client.VespaClient.query", mock_vespa_client_query)
            def run():
                res = tensor_search.search(
                    config=self.config,
                    index_name=self.structured_index_with_no_model.name,
                    text=CustomVectorQuery(
                        customVector=CustomVectorQuery.CustomVector(
                            content= "sample",
                            vector=sample_vector
                        )
                    ),
                    search_method="HYBRID",
                    hybrid_parameters=HybridParameters(
                        searchableAttributesLexical=["text_field_1"],
                        searchableAttributesTensor=["text_field_1"]
                    ),
                    result_count=3
                )
                return res

            res = run()

            call_args = mock_vespa_client_query.call_args_list

            vespa_query_kwargs = call_args[-1][1]
            self.assertIn("{targetHits:3, approximate:True, hnsw.exploreAdditionalHits:1997}"
                          "nearestNeighbor(marqo__embeddings_text_field_1, marqo__query_embedding)",
                          vespa_query_kwargs["marqo__yql.tensor"])
            # Lexical yql has content text, but Tensor uses the sample vector
            self.assertIn("marqo__lexical_text_field_1 contains \"sample\"", vespa_query_kwargs["marqo__yql.lexical"])
            self.assertEqual(vespa_query_kwargs["query_features"]["marqo__query_embedding"],
                             sample_vector)
            self.assertIn("hits", res)

            # Result should be JSON serializable
            try:
                ORJSONResponse(res)
            except TypeError as e:
                self.fail(f"Result is not JSON serializable: {e}")

        with self.subTest("Custom vector query, with context, with content"):
            @unittest.mock.patch("marqo.vespa.vespa_client.VespaClient.query", mock_vespa_client_query)
            def run():
                res = tensor_search.search(
                    config=self.config,
                    index_name=self.structured_index_with_no_model.name,
                    text=CustomVectorQuery(
                        customVector=CustomVectorQuery.CustomVector(
                            content= "sample",
                            vector=sample_vector
                        )
                    ),
                    search_method="HYBRID",
                    hybrid_parameters=HybridParameters(
                        searchableAttributesLexical=["text_field_1"],
                        searchableAttributesTensor=["text_field_1"]
                    ),
                    context=SearchContext(**{"tensor": [{"vector": [i*2 for i in sample_vector],     # Double the sample vector
                                                                      "weight": 1}], })
                )
                return res

            res = run()

            call_args = mock_vespa_client_query.call_args_list

            vespa_query_kwargs = call_args[-1][1]
            self.assertIn("{targetHits:3, approximate:True, hnsw.exploreAdditionalHits:1997}"
                          "nearestNeighbor(marqo__embeddings_text_field_1, marqo__query_embedding)",
                          vespa_query_kwargs["marqo__yql.tensor"])
            # Lexical yql has content text, but Tensor uses the sample vector with context
            self.assertIn("marqo__lexical_text_field_1 contains \"sample\"",
                          vespa_query_kwargs["marqo__yql.lexical"])
            self.assertEqual(vespa_query_kwargs["query_features"]["marqo__query_embedding"],
                             [i*1.5 for i in sample_vector])    # Should average the query & context vectors
            self.assertIn("hits", res)

            # Result should be JSON serializable
            try:
                ORJSONResponse(res)
            except TypeError as e:
                self.fail(f"Result is not JSON serializable: {e}")

        with self.subTest("Custom vector query, no content, no context, tensor/tensor"):
            @unittest.mock.patch("marqo.vespa.vespa_client.VespaClient.query", mock_vespa_client_query)
            def run():
                res = tensor_search.search(
                    config=self.config,
                    index_name=self.structured_index_with_no_model.name,
                    text=CustomVectorQuery(
                        customVector=CustomVectorQuery.CustomVector(
                            content=None,
                            vector=sample_vector
                        )
                    ),
                    search_method="HYBRID",
                    hybrid_parameters=HybridParameters(
                        retrievalMethod="tensor",
                        rankingMethod="tensor",
                        searchableAttributesTensor=["text_field_1"]
                    ),
                    result_count=3
                )
                return res

            res = run()

            call_args = mock_vespa_client_query.call_args_list

            vespa_query_kwargs = call_args[-1][1]
            self.assertIn("{targetHits:3, approximate:True, hnsw.exploreAdditionalHits:1997}"
                          "nearestNeighbor(marqo__embeddings_text_field_1, marqo__query_embedding)",
                          vespa_query_kwargs["marqo__yql.tensor"])
            self.assertEqual(vespa_query_kwargs["query_features"]["marqo__query_embedding"],
                             sample_vector)
            self.assertIn("hits", res)

            # Result should be JSON serializable
            try:
                ORJSONResponse(res)
            except TypeError as e:
                self.fail(f"Result is not JSON serializable: {e}")

        Tests that using a custom vector query sends the correct arguments to vespa
        Structured. Uses searchable attributes.
        
tests/integ_tests/tensor_search/integ_tests/test_hybrid_search.py