Skip to content

Commit c55f35d

Browse files
committed
feat: bugs fixed
1 parent 3b21c27 commit c55f35d

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

src/memory/store/mongodb_store.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -112,24 +112,24 @@ func (ms *MongoStore) SearchMemory(ctx context.Context, sessionID string, queryE
112112
// Use $vectorSearch for efficient similarity search in MongoDB Atlas.
113113
pipeline := mongo.Pipeline{
114114
{
115-
{"$vectorSearch", bson.D{
116-
{"index", "vector_index"},
117-
{"path", "embedding"},
118-
{"queryVector", float64Embedding(queryEmbedding)},
119-
{"numCandidates", int64(limit * 10)}, // Oversample for better accuracy
120-
{"limit", int64(limit)},
115+
{Key: "$vectorSearch", Value: bson.D{
116+
{Key: "index", Value: "vector_index"},
117+
{Key: "path", Value: "embedding"},
118+
{Key: "queryVector", Value: float64Embedding(queryEmbedding)},
119+
{Key: "numCandidates", Value: int64(limit * 10)}, // Oversample for better accuracy
120+
{Key: "limit", Value: int64(limit)},
121121
}},
122122
},
123123
{
124-
{"$addFields", bson.D{
125-
{"score", bson.D{{"$meta", "vectorSearchScore"}}},
124+
{Key: "$addFields", Value: bson.D{
125+
{Key: "score", Value: bson.D{{Key: "$meta", Value: "vectorSearchScore"}}},
126126
}},
127127
},
128128
}
129129

130130
// Add a $match stage if sessionID is provided.
131131
if sessionID != "" {
132-
pipeline = append(pipeline, bson.D{{"$match", bson.D{{"session_id", sessionID}}}})
132+
pipeline = append(pipeline, bson.D{{Key: "$match", Value: bson.D{{Key: "session_id", Value: sessionID}}}})
133133
}
134134

135135
cursor, err := ms.collection.Aggregate(ctx, pipeline)
@@ -223,14 +223,14 @@ func (ms *MongoStore) CreateSchema(ctx context.Context, _ string) error {
223223
// Vector search index for Atlas
224224
{
225225
Keys: bson.D{
226-
{"embedding", "cosmos.vector"},
226+
{Key: "embedding", Value: "cosmos.vector"},
227227
},
228228
Options: options.Index().
229229
SetName("vector_index").
230230
SetWeights(bson.D{
231-
{"numDimensions", 768}, // Assuming 768, adjust as needed
232-
{"similarity", "cosine"},
233-
{"type", "ivf"},
231+
{Key: "numDimensions", Value: 768}, // Assuming 768, adjust as needed
232+
{Key: "similarity", Value: "cosine"},
233+
{Key: "type", Value: "ivf"},
234234
}),
235235
},
236236
}

src/memory/store/mongodb_store_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package store
22

33
import (
4+
"context"
45
"testing"
56
"time"
67

@@ -84,11 +85,11 @@ func TestMongoStoreCloseNilClient(t *testing.T) {
8485

8586
func TestMongoStoreCreateSchemaOnNilStore(t *testing.T) {
8687
var store *MongoStore
87-
if err := store.CreateSchema(nil, ""); err != nil {
88+
if err := store.CreateSchema(context.TODO(), ""); err != nil {
8889
t.Fatalf("expected nil error, got %v", err)
8990
}
9091
store = &MongoStore{}
91-
if err := store.CreateSchema(nil, ""); err != nil {
92+
if err := store.CreateSchema(context.TODO(), ""); err != nil {
9293
t.Fatalf("expected nil error when collection is nil, got %v", err)
9394
}
9495
}

0 commit comments

Comments
 (0)