Skip to content

How to create QG. #176

Open
Open
@fgheng

Description

@fgheng

Hello, I am using NGT-qg for vector recall, and I found that there are two ways to convert ONNG to QG:

Command line: qbg command [option] index [data]
C++ code: NGTQG::Index::quantize(indexPath, dimensionOfSubvector, maxNumberOfEdges, true); which from samples/qg-l2-float

However, I noticed that when using the qbg command line to perform QG on ONNG, it involves two steps:

  1. qbg create-qg
  2. qbg build-qg

When I checked the C++ source code corresponding to these two commands, I found that they perform the following operations:

// lib/NGT/NGTQ/QbgCli.cpp::createQG
void QBG::CLI::createQG(NGT::Args &args) {
  const std::string usage = "Usage: qbg create-qg [-Q dimension-of-subvector] index";

  QbgCliBuildParameters buildParameters(args);
  buildParameters.getCreationParameters();

  string indexPath;
  try {
    indexPath = args.get("#1");
  } catch (...) {
    std::stringstream msg;
    msg << "No index is specified." << std::endl;
    msg << usage << endl;
    NGTThrowException(msg);
  }
  std::cerr << "creating..." << std::endl;
  NGTQG::Index::create(indexPath, buildParameters);
  std::cerr << "appending..." << std::endl;
  NGTQG::Index::append(indexPath, buildParameters);
}
// lib/NGT/NGTQ/QbgCli.cpp::buildQG
void QBG::CLI::buildQG(NGT::Args &args) {
  const std::string usage = "Usage: qbg build-qg [-Q dimension-of-subvector] [-E max-number-of-edges] index";

  QbgCliBuildParameters buildParameters(args);
  buildParameters.getBuildParameters();

  string indexPath;
  try {
    indexPath = args.get("#1");
  } catch (...) {
    std::stringstream msg;
    msg << "No index is specified." << std::endl;
    msg << usage << std::endl;
    NGTThrowException(msg);
  }

  size_t phase         = args.getl("p", 0);
  size_t maxNumOfEdges = args.getl("E", 128);

  const std::string qgPath = indexPath + "/qg";

  if (phase == 0 || phase == 1) {
    QBG::Optimizer optimizer(buildParameters);
    optimizer.globalType = QBG::Optimizer::GlobalTypeZero;

#ifdef NGTQG_NO_ROTATION
    if (optimizer.rotation || optimizer.repositioning) {
      std::cerr << "build-qg: Warning! Although rotation or repositioning is specified, turn off rotation "
                   "and repositioning because of unavailable options."
                << std::endl;
      optimizer.rotation      = false;
      optimizer.repositioning = false;
    }
#endif

    std::cerr << "optimizing..." << std::endl;
    optimizer.optimize(qgPath);
  }
  auto verbose = buildParameters.optimization.verbose;
  if (phase == 0 || phase == 2) {
    std::cerr << "building the inverted index..." << std::endl;
    QBG::Index::buildNGTQ(qgPath, verbose);
  }
  if (phase == 0 || phase == 3) {
    std::cerr << "building the quantized graph... " << std::endl;
    NGTQG::Index::realign(indexPath, maxNumOfEdges, verbose);
  }
}

It seems that when using the command line to perform QG on ONNG, the operations involved are more extensive and mainly include:

  // createQG
  NGTQG::Index::create(indexPath, buildParameters);
  NGTQG::Index::append(indexPath, buildParameters);

  // buildQG
  NGTQG::Index::realign(indexPath, maxNumOfEdges, verbose);

This differs from the method implemented in samples/qg-l2-float. What is the difference here?

I would appreciate any help or insights you can provide on this issue.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions