### Question:
MeanDVSearch extends Searcher { public List<Passage> query(Question question) { float[] query_vector = DenseVectors.mean( question.memo(Phrase.simpleTokens) .stream().map(DenseVectors::vectorFor) .filter(v -> v.isPresent()) .map(v -> v.get()) .collect(Collectors.toList())); byte[][] winners = new byte[LEN][]; double[] sims = new double[LEN]; try (Transaction tx = wiki_vectors_env.createReadTransaction(); Database doc_vectors = wiki_vectors_env.openDatabase(tx, "wiki-vectors", 0)) { for (Entry e : doc_vectors.iterate(tx).iterable()) { double this_sim = DenseVectors.sim(query_vector, KV.asVector(e.getValue())); if (Double.isFinite(this_sim)) bubble(sims, winners, this_sim, e.getKey(), K); } } List<Passage> passages = new ArrayList<>(); for (int i=0; i<K; i++) { if (winners[i] != null) { String id = string(winners[i]); passages.add(new Passage("meandv", "", "", id)); System.out.println("value is : " + id + " sim: " + sims[i]); } } return fillFromSources(passages); } MeanDVSearch(Environment env); static void bubble(double[] sims, byte[][] names, double this_sim, byte[] name, int K); List<Passage> query(Question question); static final int K; static final int N; static final int LEN; }### Answer:
@Test public void test() { mds = new MeanDVSearch(new Environment()); List<Passage> frogstuff = mds.query("frog"); assertTrue(frogstuff.size() > 0); assertTrue(frogstuff.get(0).title.contains("frog")); }