A fast way to look up the nearest hashes with hamming distance
Go to file
2024-03-22 21:45:51 -04:00
.github/workflows Fix build step. 2023-02-10 22:07:02 -05:00
bkapi Update versions. 2024-03-22 21:45:51 -04:00
bkapi-client Update versions. 2024-03-22 21:45:51 -04:00
.gitignore Move client nats behind feature. 2023-02-11 00:01:45 -05:00
Cargo.lock Update versions. 2024-03-22 21:45:51 -04:00
Cargo.toml Update versions, some cleanup. 2023-02-10 22:00:42 -05:00
README.md Better docs and other NATS fixes. 2023-08-15 15:01:35 -04:00

bkapi

A fast way to look up hamming distance hashes.

Querying

There are two interfaces for querying, both of which can be used simultaneously.

HTTP

It provides a single API endpoint, /search which takes in a hash and distance query parameter to search for matches. The response looks like this:

{
    "hash": 8525958787074004077, // Searched hash
    "distance": 3, // Maximum search distance
    "hashes": [ // Results
        {"hash": 8525958787073873005, "distance": 1}
    ]
}

NATS

It listens on $NATS_PREFIX.bkapi.search for a payload like:

[
    {"hash": 12345, "distance": 3}
]

Each input will have a corresponding entry in the response:

[
    [ // Results for first input
        {"hash": 8525958787073873005, "distance": 1}
    ]
]

Initial Load

The initial entries are populated through the databaes query $DATABASE_QUERY.

Listening

It can be configured to listen to PostgreSQL notifications OR with NATS messages.

PostgreSQL

It subscribes to $DATABASE_SUBSCRIBE, expecting events to be a JSON object containing the hash.

NATS

It subscribes to $NATS_PREFIX.bkapi.add, expecting events to be a JSON object containing the hash.

JetStream is used to ensure no hashes are lost without having to reload the entire tree on a connection error.