Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Migrating from OpenNLP to LuceneLinguistics

TL;DR: migrating to Lucene Linguistics has a fast path

Context

The question which Vespa Linguistics implementation to use is not the first one in the Vespa adoption story. OpenNLP ships by default and works out of the box doing seemingly the right thing. But once you need some clever trickery with how the text is processed, you’ll learn pretty fast that OpenNLP linguistics provide almost no configuration options: no stopword lists, no synonyms, etc.

But the selection of the linguistics is highly consequential. There is only one Linguistics that is active in a container cluster. If you switch linguistics libraries on a live system you might have inconsistent matching: index if full of tokens.

Of course, you might try to make two separate linguistics work as similarly as possible, but I’d question the practicality of this approach.

The migration typically involves setting up a completely new Vespa deployment, feeding all the data into the new Vespa, doing dual writes for behavioral data and then gradually shifting the traffic.

There is a better way

What if I told you that for a particular linguistics migration there is a shortcut. Moving to Lucene Linguistics can be done in place in steps:

  1. For existing fields configure Lucene Linguistics to use a tokenizer that wraps your linguistics so that it produces byte identical tokens.

  2. For new fields create new profiles etc.

  3. Hydrate the new fields by reindexing data.

This is possible because you leverage the separation between the document structure that is fed to Vespa and synthetic fields that are used for matching and ranking? Don’t you?

Prototype

To make sure that Lucene linguistics produces identical tokens, setup Vespa this way:

Now you can feed data into the content cluster through both linguistics, check the indexed tokens. Once the tokens are identical, go and test query handling.

Once you are happy with the results, kill the OpenNLP container cluster and just use Lucene Linguistics as you please.

FAQ

Q: what if my project is not maven-based? A: You can just grab this jar, put it into the components/ directory and start tinkering.

Q: Any other way? A: Your custom linguistics can get the job done. You just need to invest a way to configure how tokens are produced under language/profile. Exactly what Lucene Linguistics already provides.

Q:

E.g., you need elementwise BM25 scores on some array of arrays of identifier that have some characters which OpenNLP splits on. You might try to replace those chars by some other chars with indexing script, but what to do with queries?