Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package main

import (
"context"
"fmt"
"log"


"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)

func main() {
ctx := context.Background()
// Replace the placeholder with your Atlas connection string
const uri = "<connection-string>"

// Connect to your Atlas cluster
clientOptions := options.Client().ApplyURI(uri)
client, err := mongo.Connect(ctx, clientOptions)
if err != nil {
log.Fatalf("failed to connect to the server: %v", err)
}
defer func() { _ = client.Disconnect(ctx) }()

// Set the namespace
coll := client.Database("sample_mflix").Collection("embedded_movies")
indexName := "vector_index"

err = coll.SearchIndexes().DropOne(ctx, indexName)
if err != nil {
log.Fatalf("failed to delete the index: %v", err)
}

fmt.Println("Successfully deleted the Vector Search index")
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package main

import (
"context"
"fmt"
"log"

"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)

func main() {
ctx := context.Background()
// Replace the placeholder with your Atlas connection string
const uri = "<connection-string>"

// Connect to your Atlas cluster
clientOptions := options.Client().ApplyURI(uri)
client, err := mongo.Connect(ctx, clientOptions)
if err != nil {
log.Fatalf("failed to connect to the server: %v", err)
}
defer func() { _ = client.Disconnect(ctx) }()

// Set the namespace
coll := client.Database("sample_mflix").Collection("embedded_movies")
indexName := "vector_index"
type vectorDefinitionField struct {
Type string `bson:"type"`
Path string `bson:"path"`
NumDimensions int `bson:"numDimensions"`
Similarity string `bson:"similarity"`
}

type vectorDefinition struct {
Fields []vectorDefinitionField `bson:"fields"`
}

definition := vectorDefinition{
Fields: []vectorDefinitionField{{
Type: "vector",
Path: "plot_embedding",
NumDimensions: 1024,
Similarity: "euclidean"}},
}
err = coll.SearchIndexes().UpdateOne(ctx, indexName, definition)

if err != nil {
log.Fatalf("failed to update the index: %v", err)
}

fmt.Println("Successfully updated the search index")
}

64 changes: 64 additions & 0 deletions generated-usage-examples/go/driver-test/enn.snippet.example.go

Large diffs are not rendered by default.