MCPcopy
hub / github.com/weaviate/weaviate / TestClientRank

Function TestClientRank

modules/reranker-contextualai/clients/ranker_test.go:37–87  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

35)
36
37func TestClientRank(t *testing.T) {
38 testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
39 assert.Equal(t, http.MethodPost, r.Method)
40 assert.Equal(t, rerankPath, r.URL.Path)
41 assert.Equal(t, applicationJSON, r.Header.Get(contentTypeHeader))
42 assert.Contains(t, r.Header.Get("Authorization"), "Bearer")
43
44 var req RankInput
45 err := json.NewDecoder(r.Body).Decode(&req)
46 require.NoError(t, err)
47
48 assert.Equal(t, testQuery, req.Query)
49 assert.Equal(t, []string{"doc1", "doc2", "doc3"}, req.Documents)
50 assert.Equal(t, testModel, req.Model)
51
52 response := RankResponse{
53 Results: []RerankedResult{
54 {Index: 0, RelevanceScore: 0.9},
55 {Index: 2, RelevanceScore: 0.8},
56 {Index: 1, RelevanceScore: 0.7},
57 },
58 }
59
60 w.Header().Set(contentTypeHeader, applicationJSON)
61 json.NewEncoder(w).Encode(response)
62 }))
63 defer testServer.Close()
64
65 client := &client{
66 apiKey: testAPIKey,
67 httpClient: &http.Client{Timeout: 30 * time.Second},
68 host: testServer.URL,
69 path: rerankPath,
70 maxDocuments: 1000,
71 logger: logrus.New(),
72 }
73
74 fakeConfig := fakeClassConfig{
75 classConfig: map[string]any{
76 "model": testModel,
77 },
78 }
79
80 result, err := client.Rank(context.Background(), testQuery, []string{"doc1", "doc2", "doc3"}, fakeConfig)
81
82 require.NoError(t, err)
83 assert.Equal(t, testQuery, result.Query)
84 assert.Len(t, result.DocumentScores, 3)
85 assert.Equal(t, "doc1", result.DocumentScores[0].Document)
86 assert.Equal(t, 0.9, result.DocumentScores[0].Score)
87}
88
89func TestClientMetaInfo(t *testing.T) {
90 client := &client{}

Callers

nothing calls this directly

Calls 11

CloseMethod · 0.95
RankMethod · 0.95
EqualMethod · 0.80
GetMethod · 0.65
ContainsMethod · 0.65
DecodeMethod · 0.65
HeaderMethod · 0.65
EncodeMethod · 0.65
NewMethod · 0.65
LenMethod · 0.65
SetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…