{"id":13532127,"url":"https://github.com/kakao/n2","last_synced_at":"2025-05-16T09:03:58.462Z","repository":{"id":49615385,"uuid":"111753865","full_name":"kakao/n2","owner":"kakao","description":"TOROS N2 - lightweight approximate Nearest Neighbor library which runs fast even with large datasets","archived":false,"fork":false,"pushed_at":"2023-06-27T16:54:16.000Z","size":1340,"stargazers_count":576,"open_issues_count":14,"forks_count":69,"subscribers_count":38,"default_branch":"dev","last_synced_at":"2025-04-12T04:51:25.293Z","etag":null,"topics":["approximate","approximate-nearest-neighbor-search","go","k-nearest-neighbors","knn","machine-learning","ml","nearest-neighbor-search","python"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kakao.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":"CONTRIBUTING.md","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":"AUTHORS.md"}},"created_at":"2017-11-23T02:27:59.000Z","updated_at":"2025-04-01T23:30:06.000Z","dependencies_parsed_at":"2024-01-14T01:17:38.159Z","dependency_job_id":"d559f894-a8ce-43e4-bb0d-7b74f3ca86e9","html_url":"https://github.com/kakao/n2","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kakao%2Fn2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kakao%2Fn2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kakao%2Fn2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kakao%2Fn2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kakao","download_url":"https://codeload.github.com/kakao/n2/tar.gz/refs/heads/dev","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254501556,"owners_count":22081528,"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":["approximate","approximate-nearest-neighbor-search","go","k-nearest-neighbors","knn","machine-learning","ml","nearest-neighbor-search","python"],"created_at":"2024-08-01T07:01:08.403Z","updated_at":"2025-05-16T09:03:58.442Z","avatar_url":"https://github.com/kakao.png","language":"Jupyter Notebook","readme":"N2\n==============================================================================\n\n|pypi| |docs| |travis| |license|\n\n.. begin_badges\n\n.. |docs| image:: https://readthedocs.org/projects/n2/badge/?version=latest\n   :target: https://n2.readthedocs.io/en/latest/?badge=latest\n   :alt: Documentation Status\n\n.. |pypi| image:: https://img.shields.io/pypi/v/n2.svg?style=flat\n   :target: https://pypi.python.org/pypi/n2\n   :alt: Latest Version\n\n.. |travis| image:: https://travis-ci.org/kakao/n2.svg?branch=master\n   :target: https://travis-ci.org/kakao/n2\n   :alt: Build Status\n\n.. |license| image:: https://img.shields.io/github/license/kakao/n2\n   :target: https://github.com/kakao/n2/blob/master/LICENSE\n   :alt: Apache-License 2.0\n\n.. end_badges\n\n.. begin_intro\n\nLightweight approximate **N**\\ earest **N**\\ eighbor algorithm library written\nin C++ (with Python/Go bindings).\n\nN2 stands for two N's, which comes from \\'Approximate ``N``\\ earest \n``N``\\ eighbor Algorithm\\'.\n\n.. end_intro\n\n.. begin_background\n\nWhy N2 Was Made\n------------------------------------------------------------------------------\n\nBefore N2, there has been other great approximate nearest neighbor\nlibraries such as `Annoy`_ and `NMSLIB`_. However, each of them had\ndifferent strengths and weaknesses regarding usability, performance,\nand etc. So, N2 has been developed aiming to bring the strengths of\nexisting aKNN libraries and supplement their weaknesses.\n\n.. end_background\n\n.. begin_features\n\nFeatures\n------------------------------------------------------------------------------\n\n- Lightweight library which runs fast with large datasets.\n- Good performance in terms of index build time, search speed,\n  and memory usage.\n- Supports multi-core CPUs for index building.\n- Supports a mmap feature by default to efficiently process large\n  index files.\n- Supports Python/Go bindings.\n\n.. end_features\n\nSupported Distance Metrics\n------------------------------------------------------------------------------\n\n.. Please manually sync the table below with that of docs/index.rst.\n\n+-----------+-------------+--------------------------------------------------------------------+\n| Metric    | Definition  | d(**p**, **q**)                                                    |\n+-----------+-------------+--------------------------------------------------------------------+\n| \"angular\" | 1 - cosθ    | 1 - {sum(p :sub:`i` · q :sub:`i`) /                                |\n|           |             | sqrt(sum(p :sub:`i` · p :sub:`i`) · sum(q :sub:`i` · q :sub:`i`))} |\n+-----------+-------------+--------------------------------------------------------------------+\n| \"L2\"      | squared L2  | sum{(p :sub:`i` - q :sub:`i`) :sup:`2`}                            |\n+-----------+-------------+--------------------------------------------------------------------+\n| \"dot\"     | dot product | sum(p :sub:`i` · q :sub:`i`)                                       |\n+-----------+-------------+--------------------------------------------------------------------+\n\n.. begin_metric_detail\n\nN2 supports three distance metrics.\nFor \"angular\" and \"L2\", **d** (distance) is defined such that the closer the vectors are,\nthe smaller **d** is. However for \"dot\", **d** is defined such that the closer\nthe vectors are, the larger **d** is. You may be wondering why we defined\nand implemented \"dot\" metric as *plain dot product* and not as *(1 - dot product)*.\nThe rationale for this decision was to allow users to directly interpret the **d** value\nreturned from Hnsw search function as a dot product value.\n\n.. end_metric_detail\n\nQuickstart\n------------------------------------------------------------------------------\n\n1. Install N2 with pip.\n\n.. code:: bash\n\n   $ pip install n2\n\n2. Here is a python code snippet demonstrating how to use N2.\n\n.. code:: python\n\n    import numpy as np\n\n    from n2 import HnswIndex\n\n    N, dim = 10240, 20\n    samples = np.arange(N * dim).reshape(N, dim)\n\n    index = HnswIndex(dim)\n    for sample in samples:\n        index.add_data(sample)\n    index.build(m=5, n_threads=4)\n    print(index.search_by_id(0, 10))\n    # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n\nFull Documentation\n------------------------------------------------------------------------------\n\nVisit `n2.readthedocs.io`_ for full documentation.\nThe documentation site explains the following contents in detail.\n\n-  `Installation Guide`_\n\n   - how to build from source, etc.\n\n-  User Guide with Basic Examples\n\n   - `Python Interface`_\n   - `C++ Interface`_\n   - `Go Interface`_\n\n-  `Benchmark`_\n\n   - detailed explanation of how we performed benchmark experiemnts.\n\n\nPerformance\n------------------------------------------------------------------------------\n\n- Here are the results of our benchmark experiments.\n- You can also see benchmarks of various ANN libraries in Python at `ann-benchmarks.com`_.\n  Note that N2 version 0.1.6 is used in `ann-benchmarks.com`_ (last checked on October 8th, 2020)\n  and we are continuing our efforts to improve N2 performance.\n\n\nIndex Build Time\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n|image0|\n\nSearch Speed\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n|image1|\n\nMemory Usage\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n|image2|\n\n\n.. begin_footnote\n\nReferences\n------------------------------------------------------------------------------\n\n- Y\\. A. Malkov and D. A. Yashunin, \"Efficient and robust approximate \n  nearest neighbor search using hierarchical navigable small world \n  graphs,\" CoRR, vol. abs/1603.09320, 2016. [Online]. \n  Available: http://arxiv.org/abs/1603.09320\n-  NMSLIB: https://github.com/nmslib/nmslib\n-  Annoy: https://github.com/spotify/annoy\n\nLicense\n------------------------------------------------------------------------------\n\nThis software is licensed under the `Apache 2 license`_, quoted below.\n\nCopyright 2017 Kakao Corp. http://www.kakaocorp.com\n\nLicensed under the Apache License, Version 2.0 (the “License”); you may\nnot use this project except in compliance with the License. You may\nobtain a copy of the License at\nhttp://www.apache.org/licenses/LICENSE-2.0.\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an “AS IS” BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n\n.. _Apache 2 license: https://github.com/kakao/n2/blob/master/LICENSE\n.. _Annoy: https://github.com/spotify/annoy\n.. _NMSLIB: https://github.com/nmslib/nmslib\n.. _Installation Guide: https://n2.readthedocs.io/en/latest/install.html\n.. _Python Interface: https://n2.readthedocs.io/en/latest/python_api.html\n.. _C++ Interface: https://n2.readthedocs.io/en/latest/cpp_api.html\n.. _Go Interface: https://n2.readthedocs.io/en/latest/go_api.html\n.. _Benchmark: https://n2.readthedocs.io/en/latest/benchmark.html\n.. _n2.readthedocs.io: https://n2.readthedocs.io/en/latest/\n.. _ann-benchmarks.com: http://ann-benchmarks.com/\n\n.. |image0| image:: docs/imgs/build_time/build_time_threads.png\n.. |image1| image:: docs/imgs/search_time/search_time.png\n.. |image2| image:: docs/imgs/mem/memory_usage.png\n\n.. end_footnote\n","funding_links":[],"categories":["Jupyter Notebook","向量相似度搜索（ANN）","Feature Extraction","Awesome Vector Search Engine"],"sub_categories":["General Feature Extraction","Library"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkakao%2Fn2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkakao%2Fn2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkakao%2Fn2/lists"}