Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question - Is the test case correct? #7

Open
absolutelightning opened this issue Jan 5, 2025 · 1 comment
Open

Question - Is the test case correct? #7

absolutelightning opened this issue Jan 5, 2025 · 1 comment
Labels
question Further information is requested

Comments

@absolutelightning
Copy link

Hey Team,
Is the following test case correct?

func TestGraph_AddSearch(t *testing.T) {
	t.Parallel()

	g := newTestGraph[int]()

	for i := 0; i < 128; i++ {
		g.Add(
			Node[int]{
				Key:   i,
				Value: Vector{float32(i)},
			},
		)
	}

	al := Analyzer[int]{Graph: g}

	// Layers should be approximately log2(128) = 7
	// Look for an approximate doubling of the number of nodes in each layer.
	require.Equal(t, []int{
		128,
		67,
		28,
		12,
		6,
		2,
		1,
		1,
	}, al.Topography())

	nearest := g.Search(
		[]float32{64.5},
		4,
	)

	require.Len(t, nearest, 4)
	require.EqualValues(
		t,
		[]Node[int]{
			{64, Vector{64}},
			{65, Vector{65}},
			{62, Vector{62}},
			{63, Vector{63}},
		},
		nearest,
	)
}

I think 66 is closer to 64.5 as compared to 62. Or am I missing something here?

@coder-labeler coder-labeler bot added the question Further information is requested label Jan 5, 2025
@ammario
Copy link
Member

ammario commented Jan 6, 2025

The responses from Search are not guaranteed to be sorted by distance. I figure that overhead is best left to the caller as the library intends on being a low-level implementation.

Also, the results are not guaranteed to the closest N matches—the structure makes some accuracy tradeoffs in the interest of performance. I have not looked at the code in a while and there may be an elegant way to improve the guarantees. It's not top of mind for me but I welcome any contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants