Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions code/free_embedding_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"""

import datetime
import inspect
import itertools
import json
import os
Expand Down Expand Up @@ -516,8 +517,13 @@ def run_experiment_base(config_params: Dict[str, Any]) -> Dict[str, Any]:
}

opt_start = time.time()
params_for_opt = dict(config_params)
params_for_opt.pop("q", None)
optimize_param_names = set(inspect.signature(optimize_embeddings).parameters)
optimize_param_names.difference_update(("experiment_data", "q"))
params_for_opt = {
name: value
for name, value in config_params.items()
if name in optimize_param_names
}
opt_results = optimize_embeddings(
experiment_data=experiment_data, q=len(qrels), **params_for_opt
)
Expand Down
45 changes: 45 additions & 0 deletions code/free_embedding_experiment_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Tests for the free embedding experiment."""

import unittest

import free_embedding_experiment as experiment


class RunExperimentBaseTest(unittest.TestCase):

def test_cli_only_parameters_are_not_forwarded(self):
config = {
**experiment.DEFAULT_EXPERIMENT_PARAMS,
"n": 3,
"d": 2,
"k": 1,
"device": "cpu",
"num_iterations": 1,
"show_progress": False,
"log_interval": 1,
"results_output_path": "results.json",
"enable_critical_n_search": 3,
}

result = experiment.run_experiment_base(config)

self.assertNotIn("error", result["metrics"])
self.assertEqual(result["parameters"], config)


if __name__ == "__main__":
unittest.main()