# Vector Scoring

**URL:** <https://discuss.elastic.co/t/vector-scoring/85227>\
**Category:** Elasticsearch\
**Created:** [May 10, 2017, 10:23am UTC](https://discuss.elastic.co/t/vector-scoring/85227 "2017-05-10T10:23:56Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![lior-k](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lior-k/32/18100_2.png) [@lior-k](https://discuss.elastic.co/u/lior-k)\
**Post date:** [May 21, 2017, 6:14pm UTC](https://discuss.elastic.co/t/vector-scoring/85227/6 "2017-05-21T18:14:18Z")

</div>

Well Ryan - **You're a champ**!  
The binary approach is 7-8 times faster than my original approach.

I did it a little different:  
in my ScriptEngineService I injected the BinaryDocValues reader (for my binary field) to the plugin, see `setBinaryEmbeddingReader`:

```auto
public SearchScript search(CompiledScript compiledScript, final SearchLookup lookup, @Nullable final Map<String, Object> vars) {
        final NativeScriptFactory scriptFactory = (NativeScriptFactory) compiledScript.compiled();
        final VectorScoreScript script = (VectorScoreScript) scriptFactory.newScript(vars);
        return new SearchScript() {
            @Override
            public LeafSearchScript getLeafSearchScript(LeafReaderContext context) throws IOException {
                script.setBinaryEmbeddingReader(context.reader().getBinaryDocValues(VectorScoreScript.field));
                return script;
            }
            @Override
            public boolean needsScores() {
                return scriptFactory.needsScores();
            }
        };
    }

```

and inside the `run` method in my plugin I got the byte array as follows:  
`final byte[] bytes = binaryEmbeddingReader.get(docId).bytes;`  
where `docid` is set at `setDocument` (my plugin implements `LeafSearchScript`)

Thanks for the help!

---

_[View the full topic](https://discuss.elastic.co/t/vector-scoring/85227)._
