Socket
Socket
Sign inDemoInstall

nboost

Package Overview
Dependencies
Maintainers
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nboost

Nboost is a scalable, search-api-boosting platform for developing and deploying automated SOTA models more relevant search results.


Maintainers
2

🧪 We're looking for beta testers for our virtual assistant widget. Contact us if you're interested in using it on your website.

Nboost

PyPI Documentation Status PyPI - License

HighlightsOverviewBenchmarksInstallGetting StartedKubernetesDocumentationTutorialsContributingRelease NotesBlog

What is it

NBoost is a scalable, search-engine-boosting platform for developing and deploying state-of-the-art models to improve the relevance of search results.

Nboost leverages finetuned models to produce domain-specific neural search engines. The platform can also improve other downstream tasks requiring ranked input, such as question answering.

Contact us to request domain-specific models or leave feedback

Overview

The workflow of NBoost is relatively simple. Take the graphic above, and imagine that the server in this case is Elasticsearch.

In a conventional search request, the user sends a query to Elasticsearch and gets back the results.

In an NBoost search request, the user sends a query to the model. Then, the model asks for results from Elasticsearch and picks the best ones to return to the user.

Benchmarks

🔬 Note that we are evaluating models on differently constructed sets than they were trained on (MS Marco vs TREC-CAR), suggesting the generalizability of these models to many other real world search problems.

Fine-tuned ModelsDependencyEval SetSearch Boost[1]Speed on GPU
nboost/pt-tinybert-msmarco (default)PyTorchbing queries+45% (0.26 vs 0.18)~50ms/query
nboost/pt-bert-base-uncased-msmarcoPyTorchbing queries+62% (0.29 vs 0.18)~300 ms/query
nboost/pt-bert-large-msmarcoPyTorchbing queries+77% (0.32 vs 0.18)-
nboost/pt-biobert-base-msmarcoPyTorchbiomed+66% (0.17 vs 0.10)~300 ms/query

Instructions for reproducing here.

[1] MRR compared to BM25, the default for Elasticsearch. Reranking top 50.
[2] https://github.com/nyu-dl/dl4marco-bert

To use one of these fine-tuned models with nboost, run nboost --model_dir bert-base-uncased-msmarco for example, and it will download and cache automatically.

Using pre-trained language understanding models, you can boost search relevance metrics by nearly 2x compared to just text search, with little to no extra configuration. While assessing performance, there is often a tradeoff between model accuracy and speed, so we benchmark both of these factors above. This leaderboard is a work in progress, and we intend on releasing more cutting edge models!

Install NBoost

There are two ways to get NBoost, either as a Docker image or as a PyPi package. For cloud users, we highly recommend using NBoost via Docker.

🚸 Depending on your model, you should install the respective Tensorflow or Pytorch dependencies. We package them below.

For installing NBoost, follow the table below.

Dependency🐳 Docker📦 Pypi🐙 Kubernetes
Pytorch (recommended)koursaros/nboost:latest-ptpip install nboost[pt]helm install nboost/nboost --set image.tag=latest-pt
Tensorflowkoursaros/nboost:latest-tfpip install nboost[tf]helm install nboost/nboost --set image.tag=latest-tf
Allkoursaros/nboost:latest-allpip install nboost[all]helm install nboost/nboost --set image.tag=latest-all
- (for testing)koursaros/nboost:latest-alpinepip install nboosthelm install nboost/nboost --set image.tag=latest-alpine

Any way you install it, if you end up reading the following message after $ nboost --help or $ docker run koursaros/nboost --help, then you are ready to go!

success installation of NBoost

Getting Started

📡The Proxy

component overview

The Proxy is the core of NBoost. The proxy is essentially a wrapper to enable serving the model. It is able to understand incoming messages from specific search apis (i.e. Elasticsearch). When the proxy receives a message, it increases the amount of results the client is asking for so that the model can rerank a larger set and return the (hopefully) better results.

For instance, if a client asks for 10 results to do with the query "brown dogs" from Elasticsearch, then the proxy may increase the results request to 100 and filter down the best ten results for the client.

Setting up a Neural Proxy for Elasticsearch in 3 minutes

In this example we will set up a proxy to sit in between the client and Elasticsearch and boost the results!

Installing NBoost with tensorflow

If you want to run the example on a GPU, make sure you have Tensorflow 1.14-1.15, Pytorch or ONNX Runtime with CUDA to support the modeling functionality. However, if you want to just run it on a CPU, don't worry about it. For both cases, just run:

pip install nboost[pt]
Setting up an Elasticsearch Server

🔔 If you already have an Elasticsearch server, you can skip this step!

If you don't have Elasticsearch, not to worry! We recommend setting up a local Elasticsearch cluster using docker (providing you have Docker installed). First, get the ES image by running:

docker pull elasticsearch:7.4.2

Once you have the image, you can run an Elasticsearch server via:

docker run -d -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch:7.4.2
Deploying the proxy

Now we're ready to deploy our Neural Proxy! It is very simple to do this, run:

nboost                                  \
    --uhost localhost                   \
    --uport 9200                        \
    --search_route "/<index>/_search"   \
    --query_path url.query.q            \
    --topk_path url.query.size          \
    --default_topk 10                   \
    --choices_path body.hits.hits       \
    --cvalues_path _source.passage

📢 The --uhost and --uport should be the same as the Elasticsearch server above! Uhost and uport are short for upstream-host and upstream-port (referring to the upstream server).

If you get this message: Listening: <host>:<port>, then we're good to go!

Indexing some data

NBoost has a handy indexing tool built in (nboost-index). For demonstration purposes, will be indexing a set of passages about traveling and hotels through NBoost. You can add the index to your Elasticsearch server by running:

travel.csv comes with NBoost

nboost-index --file travel.csv --index_name travel --delim , --id_col

Now let's test it out! Hit the Elasticsearch with:

curl "http://localhost:8000/travel/_search?pretty&q=passage:vegas&size=2"

If the Elasticsearch result has the nboost tag in it, congratulations it's working!

success installation of NBoost

What just happened?

Let's check out the NBoost frontend. Go to your browser and visit localhost:8000/nboost.

If you don't have access to a browser, you can curl http://localhost:8000/nboost/status for the same information.

The frontend recorded everything that happened:

  1. NBoost got a request for 2 search results. (average_topk)
  2. NBoost connected to the server at localhost:9200.
  3. NBoost sent a request for 50 search results to the server. (topn)
  4. NBoost received 50 search results from the server. (average_choices)
  5. The model picked the best 2 search results and returned them to the client.
Elastic made easy

To increase the number of parallel proxies, simply increase --workers. For a more robust deployment approach, you can distribute the proxy via Kubernetes (see below).

Kubernetes

See also

For in-depth query DSL and other search API solutions (such as the Bing API), see the docs.

Deploying NBoost via Kubernetes

We can easily deploy NBoost in a Kubernetes cluster using Helm.

Add the NBoost Helm Repo

First we need to register the repo with your Kubernetes cluster.

helm repo add nboost https://raw.githubusercontent.com/koursaros-ai/nboost/master/charts/
helm repo update
Deploy some NBoost replicas

Let's try deploying four replicas:

helm install --name nboost --set replicaCount=4 nboost/nboost

All possible --set (values.yaml) options are listed below:

ParameterDescriptionDefault
replicaCountNumber of replicas to deploy3
image.repositoryNBoost Image namekoursaros/nboost
image.tagNBoost Image taglatest-pt
args.modelName of the model classnil
args.model_dirName or directory of the finetuned modelpt-bert-base-uncased-msmarco
args.qaWhether to use the qa pluginFalse
args.qa_model_dirName or directory of the qa modeldistilbert-base-uncased-distilled-squad
args.modelName of the model classnil
args.hostHostname of the proxy0.0.0.0
args.portPort for the proxy to listen on8000
args.uhostHostname of the upstream search api serverelasticsearch-master
args.uportPort of the upstream server9200
args.data_dirDirectory to cache model binarynil
args.max_seq_lenMax combined token length64
args.bufsizeSize of the http buffer in bytes2048
args.batch_sizeBatch size for running through rerank model4
args.multiplierFactor to increase results by5
args.workersNumber of threads serving the proxy10
args.query_pathJsonpath in the request to find the querynil
args.topk_pathJsonpath to find the number of requested resultsnil
args.choices_pathJsonpath to find the array of choices to reordernil
args.cvalues_pathJsonpath to find the str values of the choicesnil
args.cids_pathJsonpath to find the ids of the choicesnil
args.search_pathThe url path to tag for reranking via nboostnil
service.typeKubernetes Service typeLoadBalancer
resourcesresource needs and limits to apply to the pod{}
nodeSelectorNode labels for pod assignment{}
affinityAffinity settings for pod assignment{}
tolerationsToleration labels for pod assignment[]
image.pullPolicyImage pull policyIfNotPresent
imagePullSecretsDocker registry secret names as an array[] (does not add image pull secrets to deployed pods)
nameOverrideString to override Chart.namenil
fullnameOverrideString to override Chart.fullnamenil
serviceAccount.createSpecifies whether a service account is creatednil
serviceAccount.nameThe name of the service account to use. If not set and create is true, a name is generated using the fullname templatenil
serviceAccount.createSpecifies whether a service account is creatednil
podSecurityContext.fsGroupGroup ID for the containernil
securityContext.runAsUserUser ID for the container1001
ingress.enabledEnable ingress resourcefalse
ingress.hostNameHostname to your installationnil
ingress.pathPath within the url structure[]
ingress.tlsenable ingress with tls[]
ingress.tls.secretNametls type secret to be usedchart-example-tls

Documentation

ReadTheDoc

The official NBoost documentation is hosted on nboost.readthedocs.io. It is automatically built, updated and archived on every new release.

Contributing

Contributions are greatly appreciated! You can make corrections or updates and commit them to NBoost. Here are the steps:

  1. Create a new branch, say fix-nboost-typo-1
  2. Fix/improve the codebase
  3. Commit the changes. Note the commit message must follow the naming style, say Fix/model-bert: improve the readability and move sections
  4. Make a pull request. Note the pull request must follow the naming style. It can simply be one of your commit messages, just copy paste it, e.g. Fix/model-bert: improve the readability and move sections
  5. Submit your pull request and wait for all checks passed (usually 10 minutes)
    • Coding style
    • Commit and PR styles check
    • All unit tests
  6. Request reviews from one of the developers from our core team.
  7. Merge!

More details can be found in the contributor guidelines.

Citing NBoost

If you use NBoost in an academic paper, we would love to be cited. Here are the two ways of citing NBoost:

  1. \footnote{https://github.com/koursaros-ai/nboost}
    
  2. @misc{koursaros2019NBoost,
      title={NBoost: Neural Boosting Search Results},
      author={Thienes, Cole and Pertschuk, Jack},
      howpublished={\url{https://github.com/koursaros-ai/nboost}},
      year={2019}
    }
    

License

If you have downloaded a copy of the NBoost binary or source code, please note that the NBoost binary and source code are both licensed under the Apache License, Version 2.0.

Koursaros AI is excited to bring this open source software to the community.
Copyright (C) 2019. All rights reserved.

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc