Skip to content

Commit

Permalink
wip collection vectors idea
Browse files Browse the repository at this point in the history
  • Loading branch information
Southclaws committed Jul 4, 2024
1 parent 95d3509 commit 61db73f
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
39 changes: 39 additions & 0 deletions app/services/collection/collection_read/reader.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package collection_read

import (
"context"

"go.uber.org/fx"
"go.uber.org/zap"

"github.com/Southclaws/fault"
"github.com/Southclaws/fault/fctx"
"github.com/Southclaws/storyden/app/resources/collection"
"github.com/Southclaws/storyden/app/services/semdex"
)

type CollectionReader struct {
fx.In

Logger *zap.Logger
Repo collection.Repository
Semdex semdex.Retriever
}

func (r *CollectionReader) IndexCollection(ctx context.Context, id collection.CollectionID) (*collection.Collection, error) {
col, err := r.Repo.Get(ctx, id)
if err != nil {
return nil, fault.Wrap(err, fctx.With(ctx))
}

// ids := dt.Map(col.Items, func(i *collection.CollectionItem) xid.ID { return i.Item.GetID() })

// vector, err := r.Semdex.GetVectorFor(ctx, ids...)
// if err != nil {
// r.Logger.Warn("failed to get vector for collection items", zap.Error(err))
// }

// TODO: dispatch indexing request for this vector

return col, nil
}
6 changes: 6 additions & 0 deletions app/services/semdex/semdex.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"

"github.com/Southclaws/storyden/app/resources/datagraph"
"github.com/rs/xid"
)

type Indexer interface {
Expand All @@ -21,6 +22,7 @@ type Recommender interface {

type Retriever interface {
GetAll(ctx context.Context) (datagraph.NodeReferenceList, error)
GetVectorFor(ctx context.Context, idx ...xid.ID) ([]float64, error)
}

type Semdexer interface {
Expand Down Expand Up @@ -50,6 +52,10 @@ func (o *OnlySearcher) GetAll(ctx context.Context) (datagraph.NodeReferenceList,
return nil, nil
}

func (o *OnlySearcher) GetVectorFor(ctx context.Context, idx ...xid.ID) ([]float64, error) {
return nil, nil
}

type Empty struct{}

func (n Empty) Index(ctx context.Context, object datagraph.Indexable) error {
Expand Down
12 changes: 12 additions & 0 deletions app/services/semdex/weaviate/average.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package weaviate

import (
"context"

"github.com/rs/xid"
)

func (s *weaviateSemdexer) GetVectorFor(ctx context.Context, idx ...xid.ID) ([]float64, error) {
// TODO: pull vectors for all items, compute average and return?
return nil, nil
}

0 comments on commit 61db73f

Please sign in to comment.