Skip to content
This repository was archived by the owner on Oct 30, 2024. It is now read-only.

Commit 7aab5e5

Browse files
committed
add: retrieval timin
1 parent 6559819 commit 7aab5e5

3 files changed

Lines changed: 16 additions & 3 deletions

File tree

pkg/datastore/types/types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,13 @@ type Response struct {
3232
ResultDocuments []vs.Document `json:"resultDocuments"`
3333
}
3434

35+
type Stats struct {
36+
RetrievalTimeSeconds float64 `json:"retrievalTimeSeconds,omitempty"`
37+
}
38+
3539
type RetrievalResponse struct {
3640
Query string `json:"originalQuery"`
3741
Datasets []string `json:"queriedDatasets"`
3842
Responses []Response `json:"subqueryResults"`
43+
Stats Stats `json:"stats,omitempty"`
3944
}

pkg/flows/flows.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"io"
77
"log/slog"
88
"slices"
9+
"time"
910

1011
"github.com/acorn-io/z"
1112
"github.com/google/uuid"
@@ -172,6 +173,8 @@ type RetrievalFlowOpts struct {
172173
}
173174

174175
func (f *RetrievalFlow) Run(ctx context.Context, store store.Store, query string, datasetIDs []string, opts *RetrievalFlowOpts) (*dstypes.RetrievalResponse, error) {
176+
retrievalFlowStartTime := time.Now()
177+
175178
if opts == nil {
176179
opts = &RetrievalFlowOpts{}
177180
}
@@ -213,5 +216,9 @@ func (f *RetrievalFlow) Run(ctx context.Context, store store.Store, query string
213216
}
214217
slog.Debug("Postprocessed RetrievalResponse", "num_responses", len(response.Responses), "original_query", query)
215218

219+
response.Stats = dstypes.Stats{
220+
RetrievalTimeSeconds: time.Since(retrievalFlowStartTime).Seconds(),
221+
}
222+
216223
return response, nil
217224
}

pkg/vectorstore/vectorstores.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package vectorstore
33
import (
44
"context"
55
"fmt"
6+
"log/slog"
67
"strings"
78

89
etypes "github.com/gptscript-ai/knowledge/pkg/datastore/embeddings/types"
@@ -31,9 +32,9 @@ func New(ctx context.Context, dsn string, embeddingProvider etypes.EmbeddingMode
3132
return nil, fmt.Errorf("failed to create embedding function: %w", err)
3233
}
3334

34-
s := strings.Split(dsn, "://")
35-
dialect := s[0]
36-
dsn = s[1]
35+
dialect := strings.Split(dsn, "://")[0]
36+
37+
slog.Debug("vectordb", "dialect", dialect, "dsn", dsn)
3738

3839
switch dialect {
3940
case "chromem":

0 commit comments

Comments
 (0)