{"id":38212590,"url":"https://github.com/curiosity-ai/hnsw-sharp","last_synced_at":"2026-01-17T00:44:36.456Z","repository":{"id":65775004,"uuid":"194617274","full_name":"curiosity-ai/hnsw-sharp","owner":"curiosity-ai","description":"C# library for approximate nearest neighbors search using Hierarchical Navigable Small World graphs","archived":false,"fork":false,"pushed_at":"2025-12-09T22:47:57.000Z","size":278,"stargazers_count":94,"open_issues_count":9,"forks_count":12,"subscribers_count":4,"default_branch":"master","last_synced_at":"2026-01-14T05:54:01.742Z","etag":null,"topics":["ann","approximate-nearest-neighbor-search","csharp","dotnet","embeddings","netcore","word2vec"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/curiosity-ai.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2019-07-01T06:59:14.000Z","updated_at":"2025-12-09T22:48:00.000Z","dependencies_parsed_at":null,"dependency_job_id":"13c769ab-093c-41e1-8670-71930cae5d25","html_url":"https://github.com/curiosity-ai/hnsw-sharp","commit_stats":{"total_commits":75,"total_committers":9,"mean_commits":8.333333333333334,"dds":0.5466666666666666,"last_synced_commit":"b12688d0d0a08b7856f66760bfc1cb883d9fa77f"},"previous_names":["curiosity-ai/hnsw.net"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/curiosity-ai/hnsw-sharp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/curiosity-ai%2Fhnsw-sharp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/curiosity-ai%2Fhnsw-sharp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/curiosity-ai%2Fhnsw-sharp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/curiosity-ai%2Fhnsw-sharp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/curiosity-ai","download_url":"https://codeload.github.com/curiosity-ai/hnsw-sharp/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/curiosity-ai%2Fhnsw-sharp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28490523,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-16T23:55:29.509Z","status":"ssl_error","status_checked_at":"2026-01-16T23:55:29.108Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["ann","approximate-nearest-neighbor-search","csharp","dotnet","embeddings","netcore","word2vec"],"created_at":"2026-01-17T00:44:35.872Z","updated_at":"2026-01-17T00:44:36.440Z","avatar_url":"https://github.com/curiosity-ai.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://dev.azure.com/curiosity-ai/mosaik/_apis/build/status/hnsw-sharp?branchName=master)](https://dev.azure.com/curiosity-ai/mosaik/_build/latest?definitionId=7\u0026branchName=master)\n\n\u003ca href=\"https://curiosity.ai\"\u003e\u003cimg src=\"https://curiosity.ai/media/cat.color.square.svg\" width=\"100\" height=\"100\" align=\"right\" /\u003e\u003c/a\u003e\n\n\n# HNSW.Net\n.Net library for fast approximate nearest neighbours search.\n\nExact _k_ nearest neighbours search algorithms tend to perform poorly in high-dimensional spaces. To overcome curse of dimensionality the ANN algorithms come in place. This library implements one of such algorithms described in the [\"Efficient and robust approximate nearest neighbor search using Hierarchical Navigable Small World graphs\"](https://arxiv.org/ftp/arxiv/papers/1603/1603.09320.pdf) article. It provides simple API for building nearest neighbours graphs, (de)serializing them and running k-NN search queries.\n\n## Usage\nCheck out the following code snippets once you've added the library reference to your project.\n##### How to build a graph?\n```c#\nvar parameters = new SmallWorld\u003cfloat[], float\u003e.Parameters()\n{\n  M = 15,\n  LevelLambda = 1 / Math.Log(15),\n};\n\nfloat[] vectors = GetFloatVectors();\nvar graph = new SmallWorld\u003cfloat[], float\u003e(CosineDistance.NonOptimized);\ngraph.BuildGraph(vectors, new Random(42), parameters);\n```\n##### How to run k-NN search?\n```c#\nSmallWorld\u003cfloat[], float\u003e graph = GetGraph();\n\nfloat[] query = Enumerable.Repeat(1f, 100).ToArray();\nvar best20 = graph.KNNSearch(query, 20);\nvar best1 = best20.OrderBy(r =\u003e r.Distance).First();\n```\n##### How to (de)serialize the graph?\n```c#\nSmallWorld\u003cfloat[], float\u003e graph = GetGraph();\nbyte[] buffer = graph.SerializeGraph(); // buffer stores information about parameters and graph edges\n\n// distance function must be the same as the one which was used for building the original graph\nvar copy = new SmallWorld\u003cfloat[], float\u003e(CosineDistance.NonOptimized);\ncopy.DeserializeGraph(vectors, buffer); // the original vectors to attach to the \"copy\" vertices\n```\n##### Distance functions\nThe only one distance function supplied by the library is the cosine distance. But there are 4 versions to address universality/performance tradeoff.\n```c#\nCosineDistance.NonOptimized // most generic version works for all cases\nCosineDistance.ForUnits     // gives correct result only when arguments are \"unit\" vectors\nCosineDistance.SIMD         // uses SIMD instructions to optimize calculations\nCosineDistance.SIMDForUnits // uses SIMD and requires arguments to be \"units\"\n```\nBut the API allows to inject any custom distance function tailored specifically for your needs.\n\n## Contributing\nYour contributions and suggestions are very welcome! \nPlease note that this project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.\n\nThe contributions to this project are [released](https://help.github.com/articles/github-terms-of-service/#6-contributions-under-repository-license) to the public under the [project's open source license](LICENSE). Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.\n\n### How to contribute\nIf you've found a bug or have a feature request then please open an issue with detailed description.\nWe will be glad to see your pull requests as well.\n\n1. Prepare workspace.\n```\ngit clone https://github.com/Microsoft/HNSW.Net.git\ncd HNSW.Net\ngit checkout -b [username]/[feature]\n```\n2. Update the library and add tests if needed.\n3. Build and test the changes.\n```\ncd Src\ndotnet build\ndotnet test\n```\n4. Send the pull request from `[username]/[feature]` to `master` branch.\n5. Get approve and merge the changes.\n\nWhen you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repositories using our CLA.\n\n### Releasing\nThe library is distributed as a bundle of sources.\nWe are working on enabling CI and creating Nuget package for the project.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcuriosity-ai%2Fhnsw-sharp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcuriosity-ai%2Fhnsw-sharp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcuriosity-ai%2Fhnsw-sharp/lists"}