Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/syfaro/bkapi
A fast way to look up the nearest hashes with hamming distance
https://github.com/syfaro/bkapi
hacktoberfest
Last synced: about 1 month ago
JSON representation
A fast way to look up the nearest hashes with hamming distance
- Host: GitHub
- URL: https://github.com/syfaro/bkapi
- Owner: Syfaro
- Created: 2021-07-28T19:58:28.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-06-20T02:29:11.000Z (5 months ago)
- Last Synced: 2024-06-20T14:41:38.841Z (5 months ago)
- Topics: hacktoberfest
- Language: Rust
- Homepage:
- Size: 245 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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:```jsonc
{
"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:
```json
[
{"hash": 12345, "distance": 3}
]
```Each input will have a corresponding entry in the response:
```jsonc
[
[ // Results for first input
{"hash": 8525958787073873005, "distance": 1}
]
]
```## Initial Load
The initial entries are populated through the database 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.