Skip to main content

Python bindings for Unum's Universal Key-Value store.

Project description

Universal Keys & Values

Binary Interface Standard for Database Management
Backed by Open-Source and Proprietary Implementations

built on: RocksDBLevelDB • UDisk • UMem
to store: Blobs • Documents • Graphs • Vectors • Texts
accessible from: C • C++ • Python • Java • GoLang • Apache Arrow
available through: CMakePyPIDocker Hub

UKV is an open standard for a NoSQL binary database interface, focusing on "Create, Read, Update, Delete" operations, or CRUD for short. It is defined as a few isolated C headers, and comes with numerous backend engines, supporting various data modalities, and an ecosystem of frontends to access the data.

UKV: Small Map

It can easily be expanded to support alternative underlying Key-Value Stores (KVS), embedded, standalone, or sharded, such as Redis. In the same way, you can add SDKs for other high-level languages or support for data types specific to your application that we haven't considered. This gives you the flexibility to iterate on different parts of this modular data lake without changing the business logic of your application, decoupling it from the underlying storage technology.

Documents Processing Performance Chart for UKV and MongoDB

Flexibility is essential, but so is performance. We prefer to avoid dynamic memory allocations across all modalities and prefer libraries that share that mindset. For instance, the reference implementation of Document collections uses simdjson to read and yyjson to update docs, storing them in RocksDB and serving them through Apache Arrow Flight RPC. Even such a surprisingly obvious combination often outperforms commercial DBMS products. The upcoming UDisk-based version obliterates them.

Binary Processing Performance Chart for UKV and MongoDB

Modern persistent IO on high-end servers can exceed 120 GB/s per socket when built on user-space drivers like SPDK. This is close to the real-world throughput of eight-channel DDR4 memory. Making evan a single copy of data on the hot path would slash that performance. Processing hundreds of terabytes per node, we couldn't have used LevelDB, RocksDB, or even their interfaces for our purposes to avoid dynamic polymorphism and any constraints on memory allocation strategies. That is how UKV began, but hopefully, it can grow further, advancing the storage ecosystem the same way the standardization of BLAS has pushed the frontiers of numerical compute and, later, AI.



           

Basic Use Cases

  1. Getting a Python, GoLang, or Java wrapper for vanilla RocksDB or LevelDB.
  2. Serving them via Apache Arrow Flight RPC to Spark, Kafka, or PyTorch.
  3. Embedded Document and Graph DB that will avoid networking overheads.
  4. Tiering DBMS between in-memory and persistent backends under one API.

Already excited? Give it a try. It is as easy as using dict in Python.

$ pip install ukv
$ python

>>> import ukv.umem as embedded
>>> db = embedded.DataBase()
>>> db.main[42] = 'Hi'

Features

A Key Value Store is generally an associative container with sub-linear search time. Every DBMS uses such abstractions for primary keys in each collection and indexes. But UKV has more to offer. Especially to Machine Learning practitioners.

  • ACID Transactions across collections
  • Persistent Snapshots 🔜
  • Operation-level WATCH-es
  • BSON, JSON, MessagePack support
  • JSON Patches & Merge-Patches
  • JSON Pointers Addressing
  • Native Apache Arrow format support
  • Arrow Flight RPC server implementation
  • Bulk Scans, Random Sampling
  • Pandas Tabular interface
  • NetworkX Graph interface
  • PyTorch & TensorFlow Data-Loaders 🔜

Available Backends

Any backend can be defined by three parameters. First, the Engine, being a Key-Value Store for the serialized representations. Second, implementations of Modalities, being various serialization and indexing approaches for structured data. Third, a Distribution form, such as the implementation of some web-protocol for communication with the outside world.

UKV: Backend

Engines

Following engines can be used almost interchangeably. Historically, LevelDB was the first one. RocksDB then improved on functionality and performance. Now it serves as the foundation for half of the DBMS startups.

LevelDB RocksDB UDisk UMem
Speed 1x 2x 10x 30x
Persistent
Transactional
Block Device Support
Encryption
Watches
Snapshots
Random Sampling
Bulk Enumeration
Named Collections
Open-Source
Compatibility Any Any Linux Any
Maintainer Google Facebook Unum Unum

UMem and UDisk are both designed and maintained by Unum. Both are feature-complete, but the most crucial feature our alternatives provide is performance. Being fast in memory is easy. The core logic of UMem can be found in the templated header-only consistent_set library.

Designing UDisk was a much more challenging 7-year long endeavour. It included inventing new tree-like structures, implementing partial kernel bypass with io_uring, complete bypass with SPDK, GPU acceleration, and even a custom internal filesystem. UDisk is the first engine to be designed from scratch with parallel architectures and kernel-bypass in mind.

Jump to Benchmarks.

Modalities

The same DBMS can contain multiple collections. Each collection can store BLOBs or any modality of structured data. Data of different modalities can't be stored in the same collection. ACID transactions across modalities are supported.

Documents Graphs Vectors
Values JSON-like Hierarchical Objects Labeled Directed Relations High-Dimensional Embeddings
Specialized Functionality JSON ⇔ BSON ⇔ MessagePack, Sub-Document Operations Gather Neighbors, Count Vertex Degrees Quantization, K-Approximate Nearest-Neighbors Search
Examples MongoDB, Postgres, MySQL Neo4J, TigerGraph Elastic Search, Pinecone

One of our core objectives was to select the minimal core set of functions for each modality. In that case, implementing them can be easy for any passionate developer. If the low-level interfaces are flexible, making the high-level interfaces rich is easy.

Available Frontends

UKV for Python and for C++ look very different. Our Python SDK mimics other Python libraries - Pandas and NetworkX. Similarly, C++ library provides the interface C++ developers expect.

UKV: Frontends

As we know, people use different languages for different purposes. Some C-level functionality isn't implemented for some languages. Either because there was no demand for it, or as we haven't gotten to it yet.

Name Transact Collections Batches Docs Graphs Copies
C Standard 0
C++ SDK 0
Python SDK 0-1
GoLang SDK 1
Java SDK 1
Arrow Flight API 0-2

Some frontends here have entire ecosystems around them! Apache Arrow Flight API, for instance, has its own bindings for C, C++, C#, Go, Java, JavaScript, Julia, MATLAB, Python, R, Ruby and Rust.

UKV: Frontends

Documentation

For guidance on installation, development, deployment, and administration, see our documentation.

Installation

The entire DBMS fits into a sub 100 MB Docker image. Run the following script to pull and run the container, exposing Apache Arrow Flight server on the port 38709. Client SDKs will also communicate through that same port, by default.

docker run --rm --name TestUKV -p 38709:38709 unum/ukv

For C/C++ clients and for the embedded distribution of UKV, CMake is the default form of installation. It may require installing Arrow separately, if you want client-server communication.

FetchContent_Declare(
    ukv
    GIT_REPOSITORY https://github.com/unum-cloud/UKV.git
    GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(ukv)
include_directories(${ukv_SOURCE_DIR}/include)

After that, you only need to choose linking target, such as ukv_embedded_rocksdb, ukv_embedded_umem, ukv_flight_client, or something else.

For Python users, it is the classical:

pip install ukv

Which will bring all the libraries packed into a single wheel: ukv.umem, ukv.rocksdb, ukv.leveldb, ukv.flight_client.

Read full installation guide in our docs here.

Getting Started

Testing

We split tests into 4 categories:

  1. Compilation: Validate meta-programming.
  2. API: Prevent passing incompatible function arguments.
  3. Unit: Short and cover most of the functionality.
  4. Stress: Very long and multithreaded.

All unit tests are packed into a single executable to simplify running it during development. Every backend produces one such executable. The in-memory embedded variant is generally used for debugging any non-engine level logic.

The stress tests, on the other hand, can run for days and simulate millions of concurrent transactions, ensuring the data remains intact. Any additions, especially to the stress tests, will be highly welcomed!

Read full testing guide in our docs here.

Benchmarks

It is always best to implement an application-specific benchmark, as every use case is different. Still, for the binary layer logic, we have built a dedicated project to evaluate persistent data structures - UCSB. It doesn't depend on UKV and uses native interfaces of all the engines to put everyone in the same shoes.

All engines were benchmarked for weeks using UCSB. We have already published the results for BLOB-layer abstractions for 10 TB, and, previously, 1 TB collections.

For more advanced modality-specific workloads, we have the following benchmarks provided in this repo:

  • Twitter. It takes the .ndjson dump of their GET statuses/sample API and imports it into the Documents collection. We then measure random-gathers' speed at document-level, field-level, and multi-field tabular exports. We also construct a graph from the same data in a separate collection. And evaluate Graph construction time and traversals from random starting points.
  • Tabular. Similar to the previous benchmark, but generalizes it to arbitrary datasets with some additional context. It supports Parquet and CSV input files. 🔜
  • Vector. Given a memory-mapped file with a big matrix, builds an Approximate Nearest Neighbors Search index from the rows of that matrix. Evaluates both construction and query time. 🔜

We are working hard to prepare a comprehensive overview of different parts of UKV compared to industry-standard tools. On both our hardware and most common instances across public clouds.

Read full benchmarking guide in our docs here.

Tooling

Tools are built on top of the UKV interface and aren't familiar with the underlying backend implementation. They are meant to simplify DevOps and DBMS management. Following tools are currently in the works.

  • Bulk dataset imports and exports for industry-standard Parquet, NDJSON and CSV files. 🔜
  • Rolling backups and replication. 🔜
  • Visualization tools and dashboards. 🔜

Read full tooling guide in our docs here.

Roadmap

Our development roadmap is public and is hosted within the GitHub repository. Upcoming tasks include:

  • Builds for Arm, MacOS, Windows.
  • Richer bindings for GoLang, Java, JavaScript.
  • Improved Vector Search.
  • Collection-level configuration.
  • Owning and non-owning C++ wrappers.
  • Document-schema validation.
  • Persistent Snapshots.
  • Continuous Replication.
  • Horizontal Scaling.

Read full roadmap in our docs here.

Contributing

UKV is an umbrella project for many FOSS libraries. So any work on libraries like simdjson, yyjson, RocksDB, or Apache Arrow, indirectly benefits UKV. To participate in the UKV directly, please check out the guide and implementation details. Thank you!

Read full development and contribution guide in our docs here.

Presets, Limitations and FAQ

  • Keys are 64-bit integers, by default. Why?
  • Values are binary strings under 4 GB long. Why?
  • Transactions are ACI(D) by-default. What does it mean?
  • Why not use LevelDB or RocksDB interface? Answered
  • Why not use SQL, MQL or Cypher? Answered

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

ukv-0.4.0.1672150491009260120-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (67.7 MB view details)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

File details

Details for the file ukv-0.4.0.1672150491009260120-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ukv-0.4.0.1672150491009260120-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2043faaab65ca839758adbc799d27f0577962b0993f4dd753602fcb191cb4599
MD5 6e3506d0dd58d7ada2b7acaca07f5a0a
BLAKE2b-256 22a208b4a3be4e0728e068ebe792501772504d04f7a7fe93d9fde8e6c3ff9ab6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page