Skip to content

Commit

Permalink
Update search index lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
prestonvasquez committed Nov 8, 2024
1 parent fb5770a commit 0fd1352
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions examples/mongovector-vectorstore-example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ For more information on getting started with MongoDB Atlas, visit the [MongoDB A
export MONGODB_URI=<your_mongodb_uri>
export OPENAI_API_KEY=<your_openai_api_key>

2. If you want to run this using docker-compose.yml, `MONGODB_URI` should be `localhost:27017`: `docker-compose up -d`
2. If you want to run this using docker-compose.yml, `MONGODB_URI` should be `mongodb://localhost:27017/?directConnection=true`: `docker-compose up -d`

3. Run the program: `go run main.go`
3. Run the program: `go run mongovector_vectorstore_example.go`
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,20 @@ func main() {
Similarity: similarityAlgorithm,
})

// Create the vectorstore collection
err = client.Database(databaseName).CreateCollection(context.Background(), collectionName)
if err != nil {
log.Fatalf("failed to create vector store collection: %w", err)
}

_, err = createVectorSearchIndex(context.Background(), coll, indexDP1536, fields...)
if err != nil {
log.Fatalf("faield to create index: %v", err)
}
}

return

// Create an embeddings client using the OpenAI API. Requires environment
// variable OPENAI_API_KEY to be set.
llm, err := openai.New(openai.WithEmbeddingModel(openAIEmbeddingModel))
Expand Down Expand Up @@ -235,6 +243,10 @@ func searchIndexExists(ctx context.Context, coll *mongo.Collection, idx string)
return false, fmt.Errorf("failed to list search indexes: %w", err)
}

if cursor == nil || cursor.Current == nil {
return false, nil
}

name := cursor.Current.Lookup("name").StringValue()
queryable := cursor.Current.Lookup("queryable").Boolean()

Expand Down

0 comments on commit 0fd1352

Please sign in to comment.