Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

API Reference

This chapter is a curated reference for VSAG’s public C++ API — the headers installed under include/vsag/. It documents the classes, structs, enums, and free functions an application links against, grouped by responsibility. The installed headers remain the authoritative source of truth; the pages here explain intent, ownership, and how the pieces fit together.

Looking for how to configure an index (the JSON index_param / search keys)? That is covered in Index Parameters and each index page. This chapter covers the code surface (types and methods), not the JSON schema.

Include and namespace

A single umbrella header pulls in the whole public API, and every symbol lives in the vsag namespace:

#include <vsag/vsag.h>   // includes factory.h, index.h, dataset.h, engine.h, ...

int main() {
    vsag::init();                       // one-time process initialization
    std::string ver = vsag::version();  // git-derived version string
}
Free functionHeaderDescription
bool vsag::init()vsag/vsag.hInitializes the library. Call once before other APIs. Always returns true.
std::string vsag::version()vsag/vsag.hReturns the build version derived from the git revision.

Error-handling model

Almost every fallible call returns tl::expected<T, Error> (a std::expected-style type shipped in vsag/expected.hpp) instead of throwing. A handful of legacy statistics accessors still throw std::runtime_error when unsupported; those are called out on the Index page.

auto result = vsag::Factory::CreateIndex("hgraph", params);
if (not result.has_value()) {
    const vsag::Error& err = result.error();
    std::cerr << "create failed: " << static_cast<int>(err.type) << " " << err.message << "\n";
    return;
}
std::shared_ptr<vsag::Index> index = result.value();

Error carries a machine-readable type and a human-readable message:

struct Error {
    ErrorType type;
    std::string message;
};

ErrorType

Defined in vsag/errors.h. Values start at 1 (0 is reserved).

CategoryValueMeaning
CommonUNKNOWN_ERRORUnknown error.
CommonINTERNAL_ERRORInternal algorithm error.
CommonINVALID_ARGUMENTAn argument was invalid.
BehaviorWRONG_STATUSIndex is in the wrong state for the call.
BehaviorBUILD_TWICEThe index was already built and cannot be built again.
BehaviorINDEX_NOT_EMPTYDeserializing onto a non-empty index.
BehaviorUNSUPPORTED_INDEXRequested an index type that does not exist.
BehaviorUNSUPPORTED_INDEX_OPERATIONThis index does not implement the called method.
BehaviorDIMENSION_NOT_EQUALRequest dimension differs from the index dimension.
BehaviorINDEX_EMPTYIndex is empty; cannot search or serialize.
RuntimeNO_ENOUGH_MEMORYMemory allocation failed.
RuntimeREAD_ERRORFailed to read from a binary.
RuntimeMISSING_FILEA required file is missing (e.g. DiskANN deserialization).
RuntimeINVALID_BINARYSerialized binary content is invalid.

Because most index methods are virtual with a default body that returns UNSUPPORTED_INDEX_OPERATION, an “unsupported” result is normal and expected: it means the concrete index does not implement that optional capability. Use Index::CheckFeature to probe support ahead of time.

Header map

HeaderPrimary symbolsReference page
factory.h, engine.h, vsag.hFactory, Engine, init, versionFactory & Engine
index.hIndex, IndexType, RemoveMode, MergeUnitIndex
dataset.hDataset, SparseVector, MultiVectorDataset
search_request.h, filter.h, bitset.h, search_param.h, iterator_context.hSearchRequest, Filter, BitsetSearch Request & Filters
binaryset.h, readerset.hBinarySet, Binary, Reader, ReaderSetSerialization Types
resource.h, allocator.h, thread_pool.h, options.h, logger.hResource, Allocator, ThreadPool, Options, LoggerResource Management
attribute.h, index_features.h, index_detail_info.h, utils.h, constants.hAttribute, IndexFeature, IndexDetailInfoAuxiliary Types

In this chapter

  • Factory & Engine — create indexes and readers; own resources with Engine.
  • Index — the core index interface: build, search, update, serialize, inspect.
  • Dataset — the builder-pattern container for vectors, ids, and metadata.
  • Search Request & FiltersSearchRequest, Filter, Bitset, iterator context.
  • Serialization TypesBinarySet / Binary and Reader / ReaderSet.
  • Resource Management — allocator, thread pool, engine resources, options, logger.
  • Auxiliary Types — attributes, feature flags, index detail info, and utility helpers.