{"id":24556085,"url":"https://github.com/deepfates/hnsw","last_synced_at":"2025-04-06T09:07:26.836Z","repository":{"id":172814253,"uuid":"646290000","full_name":"deepfates/hnsw","owner":"deepfates","description":"Hierarchical Navigable Small Worlds in the browser","archived":false,"fork":false,"pushed_at":"2025-01-06T18:25:50.000Z","size":97,"stargazers_count":53,"open_issues_count":1,"forks_count":7,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-30T07:11:21.295Z","etag":null,"topics":["hnsw","nearest-neighbor-search","vector-search"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/hnsw","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/deepfates.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-27T22:43:36.000Z","updated_at":"2025-03-19T01:13:20.000Z","dependencies_parsed_at":null,"dependency_job_id":"e1082209-20d1-45b3-86ab-eb6941068cac","html_url":"https://github.com/deepfates/hnsw","commit_stats":null,"previous_names":["deepfates/hnsw"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deepfates%2Fhnsw","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deepfates%2Fhnsw/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deepfates%2Fhnsw/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deepfates%2Fhnsw/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/deepfates","download_url":"https://codeload.github.com/deepfates/hnsw/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247457800,"owners_count":20941906,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hnsw","nearest-neighbor-search","vector-search"],"created_at":"2025-01-23T04:38:19.136Z","updated_at":"2025-04-06T09:07:26.817Z","avatar_url":"https://github.com/deepfates.png","language":"TypeScript","readme":"# HNSW\n\nThis is a small Typescript package that implements the Hierarchical Navigable Small Worlds algorithm for approximate nearest neighbor search.\n\nI wrote this package because I wanted to do efficient vector search directly in the client browser. All the other implementations I found for TS were either bindings for libraries written in other languages, or dealt with WASM compilation complexity.\n\nThis is not the fastest, most fully featured, or most memory efficient implementation of HNSW. It is, however, a simple and easy to use implementation that is fast enough for many use cases.\n\nIncluded is a simple persistent storage layer that uses IndexedDB to store the graph.\n\n## Installation\n    \n```bash\nnpm install hnsw\n```\n\n## Usage\n\nEphemeral index in-memory:\n```typescript\nimport { HNSW } from '../src/hnsw';\n\n// Simple example\nconst hnsw = new HNSW(200, 16, 5, 'cosine');\n\n// Make some data\nconst data = [\n{id: 1, vector: [1, 2, 3, 4, 5]},\n{id: 2, vector: [2, 3, 4, 5, 6]},\n{id: 3, vector: [3, 4, 5, 6, 7]},\n{id: 4, vector: [4, 5, 6, 7, 8]},\n{id: 5, vector: [5, 6, 7, 8, 9]}\n]\n\n// Build the index\nawait hnsw.buildIndex(data);\n\n// Search for nearest neighbors\nconst results = hnsw.searchKNN([6, 7, 8, 9, 10], 2);\nconsole.log(results);\n```\n\nPersistent index using IndexedDB:\n```typescript\nimport { HNSWWithDB } from 'hnsw';\n\n// With persistence\nconst index = await HNSWWithDB.create(200, 16, 'my-index');\n\n// Make some data\nconst data = [\n{id: 1, vector: [1, 2, 3, 4, 5]},\n{id: 2, vector: [2, 3, 4, 5, 6]},\n{id: 3, vector: [3, 4, 5, 6, 7]},\n{id: 4, vector: [4, 5, 6, 7, 8]},\n{id: 5, vector: [5, 6, 7, 8, 9]}\n]\n\n// Build the index\nawait index.buildIndex(data);\nawait index.saveIndex();\n\n// Load the index\nconst index2 = await HNSWWithDB.create(200, 16, 'my-index-2');\nawait index2.loadIndex();\n\n// Search for nearest neighbors\nconst results2 = index2.searchKNN([6, 7, 8, 9, 10], 2);\nconsole.log(results2);\n\n// Delete the index\nawait index2.deleteIndex();\n```\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeepfates%2Fhnsw","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeepfates%2Fhnsw","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeepfates%2Fhnsw/lists"}