Skip to content

Commit

Permalink
Test inserting 100 items 3 layer with m=3
Browse files Browse the repository at this point in the history
Signed-off-by: Jay Wang <[email protected]>
  • Loading branch information
xiaohk committed Jan 30, 2024
1 parent f8601f2 commit acd8fe9
Show file tree
Hide file tree
Showing 3 changed files with 523 additions and 8 deletions.
8 changes: 5 additions & 3 deletions src/mememo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,17 +186,19 @@ export class HNSW<T = string> {
* Insert a new element to the index.
* @param key Key of the new element.
* @param value The embedding of the new element to insert.
* @param maxLevel The max layer to insert this element. You don't need to set
* this value in most cases. We add this parameter for testing purpose.
*/
insert(key: T, value: number[]) {
insert(key: T, value: number[], maxLevel?: number | undefined) {
// If the key already exists, update the node
if (this.nodes.has(key)) {
// TODO: Update the node
return;
}

// Randomly determine the max level of this node
const level = this._getRandomLevel();
// console.log('random level:', level);
const level = maxLevel === undefined ? this._getRandomLevel() : maxLevel;
console.log('random level:', level);

// Add this node to the node index first
this.nodes.set(key, new Node(key, value));
Expand Down
Loading

0 comments on commit acd8fe9

Please sign in to comment.