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

Commit

Permalink
add: retrieval timin
Browse files Browse the repository at this point in the history
  • Loading branch information
iwilltry42 committed Oct 23, 2024
1 parent 6559819 commit 7aab5e5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
5 changes: 5 additions & 0 deletions pkg/datastore/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,13 @@ type Response struct {
ResultDocuments []vs.Document `json:"resultDocuments"`
}

type Stats struct {
RetrievalTimeSeconds float64 `json:"retrievalTimeSeconds,omitempty"`
}

type RetrievalResponse struct {
Query string `json:"originalQuery"`
Datasets []string `json:"queriedDatasets"`
Responses []Response `json:"subqueryResults"`
Stats Stats `json:"stats,omitempty"`
}
7 changes: 7 additions & 0 deletions pkg/flows/flows.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"log/slog"
"slices"
"time"

"github.com/acorn-io/z"
"github.com/google/uuid"
Expand Down Expand Up @@ -172,6 +173,8 @@ type RetrievalFlowOpts struct {
}

func (f *RetrievalFlow) Run(ctx context.Context, store store.Store, query string, datasetIDs []string, opts *RetrievalFlowOpts) (*dstypes.RetrievalResponse, error) {
retrievalFlowStartTime := time.Now()

if opts == nil {
opts = &RetrievalFlowOpts{}
}
Expand Down Expand Up @@ -213,5 +216,9 @@ func (f *RetrievalFlow) Run(ctx context.Context, store store.Store, query string
}
slog.Debug("Postprocessed RetrievalResponse", "num_responses", len(response.Responses), "original_query", query)

response.Stats = dstypes.Stats{
RetrievalTimeSeconds: time.Since(retrievalFlowStartTime).Seconds(),
}

return response, nil
}
7 changes: 4 additions & 3 deletions pkg/vectorstore/vectorstores.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package vectorstore
import (
"context"
"fmt"
"log/slog"
"strings"

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

s := strings.Split(dsn, "://")
dialect := s[0]
dsn = s[1]
dialect := strings.Split(dsn, "://")[0]

slog.Debug("vectordb", "dialect", dialect, "dsn", dsn)

switch dialect {
case "chromem":
Expand Down

0 comments on commit 7aab5e5

Please sign in to comment.