MCPcopy
hub / github.com/weaviate/weaviate / TestRank

Function TestRank

modules/reranker-voyageai/clients/ranker_test.go:35–161  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

33}
34
35func TestRank(t *testing.T) {
36 t.Run("when the server has a successful response", func(t *testing.T) {
37 handler := &testRankHandler{
38 t: t,
39 response: RankResponse{
40 Data: []Data{
41 {
42 Index: 0,
43 RelevanceScore: 0.9,
44 },
45 },
46 },
47 }
48 server := httptest.NewServer(handler)
49 defer server.Close()
50
51 c := New("apiKey", 0, nullLogger())
52 c.host = server.URL
53
54 expected := &ent.RankResult{
55 DocumentScores: []ent.DocumentScore{
56 {
57 Document: "I work at Apple",
58 Score: 0.9,
59 },
60 },
61 Query: "Where do I work?",
62 }
63
64 res, err := c.Rank(context.Background(), "Where do I work?", []string{"I work at Apple"}, nil)
65
66 assert.Nil(t, err)
67 assert.Equal(t, expected, res)
68 })
69
70 t.Run("when the server has an error", func(t *testing.T) {
71 handler := &testRankHandler{
72 t: t,
73 response: RankResponse{
74 Data: []Data{},
75 },
76 errorMessage: "some error from the server",
77 }
78 server := httptest.NewServer(handler)
79 defer server.Close()
80
81 c := New("apiKey", 0, nullLogger())
82 c.host = server.URL
83
84 _, err := c.Rank(context.Background(), "I work at Apple", []string{"Where do I work?"}, nil)
85
86 require.NotNil(t, err)
87 assert.Contains(t, err.Error(), "some error from the server")
88 })
89
90 t.Run("when we send requests in batches", func(t *testing.T) {
91 handler := &testRankHandler{
92 t: t,

Callers

nothing calls this directly

Calls 8

CloseMethod · 0.95
EqualMethod · 0.80
NewFunction · 0.70
nullLoggerFunction · 0.70
RankMethod · 0.65
ContainsMethod · 0.65
RunMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…