[CSHARP-4893] Unable to create Vector search index via MongoDB driver Created: 26/Dec/23  Updated: 31/Jan/24  Resolved: 31/Jan/24

Status: Closed
Project: C# Driver
Component/s: Index Management
Affects Version/s: 2.23.1
Fix Version/s: None

Type: Bug Priority: Blocker - P1
Reporter: VenkateshSrini N/A Assignee: Boris Dogadov
Resolution: Gone away Votes: 0
Labels: Bug
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Text File CandiesRepo.cs     Text File Candy.cs     Text File ICandiesRepo.cs    

 Description   

Summary

I use the following code to create my collection and search index on the fly.

public CandiesRepo(IMongoClient mongoClient, MongoUrl mongoUrl,
    ILogger<CandiesRepo> logger)
{
    _logger = logger;
    var db = mongoClient.GetDatabase(mongoUrl?.DatabaseName);
    var collectionName = "Candies";
    _aiIdxName = "gen-ai-idx";
    _candiesCollection = db.GetCollection<Candy>(collectionName);
    CreateIndex(_aiIdxName);
    _logger = logger;
}
private void CreateIndex(string indexName)
{
    var indexDef = new BsonDocument
    {
        { "mappings", new BsonDocument
            {
                {"name",indexName },
                {"dynamic", true },
                {"fields", new BsonDocument
                    {
                        {"embeddings", new BsonDocument
                            {
                                {"type","knnVector" },
                                {"dimensions",1},
                                {"similarity","cosine" }
                            }
                        }
                    }
                }
            }
        }
    };
    var searchIndexModel = new CreateSearchIndexModel(indexName, indexDef);
    _candiesCollection.SearchIndexes.CreateOne(searchIndexModel);
}
public async Task<List<Candy>> SeedCandiesAsync(List<Candy> candies)
{
    await _candiesCollection.InsertManyAsync(candies);
    return candies;
}

When I run the code I get the below exception. I'm also attaching the code file for your reference CandiesRepo.cs. Please help me to resolve the same

MongoDB.Driver.MongoCommandException
  HResult=0x80131500
  Message=Command createSearchIndexes failed: no such command: 'createSearchIndexes'.
  Source=MongoDB.Driver.Core
  StackTrace:
   at MongoDB.Driver.Core.WireProtocol.CommandUsingCommandMessageWireProtocol`1.ProcessResponse(ConnectionId connectionId, CommandMessage responseMessage)
   at MongoDB.Driver.Core.WireProtocol.CommandUsingCommandMessageWireProtocol`1.Execute(IConnection connection, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.WireProtocol.CommandWireProtocol`1.Execute(IConnection connection, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Servers.Server.ServerChannel.ExecuteProtocol[TResult](IWireProtocol`1 protocol, ICoreSession session, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Servers.Server.ServerChannel.Command[TResult](ICoreSession session, ReadPreference readPreference, DatabaseNamespace databaseNamespace, BsonDocument command, IEnumerable`1 commandPayloads, IElementNameValidator commandValidator, BsonDocument additionalOptions, Action`1 postWriteAction, CommandResponseHandling responseHandling, IBsonSerializer`1 resultSerializer, MessageEncoderSettings messageEncoderSettings, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Operations.CommandOperationBase`1.ExecuteProtocol(IChannelHandle channel, ICoreSessionHandle session, ReadPreference readPreference, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Operations.CommandOperationBase`1.ExecuteProtocol(IChannelSource channelSource, ICoreSessionHandle session, ReadPreference readPreference, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Operations.WriteCommandOperation`1.Execute(IWriteBinding binding, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Operations.CreateSearchIndexesOperation.Execute(IWriteBinding binding, CancellationToken cancellationToken)
   at MongoDB.Driver.OperationExecutor.ExecuteWriteOperation[TResult](IWriteBinding binding, IWriteOperation`1 operation, CancellationToken cancellationToken)
   at MongoDB.Driver.MongoCollectionImpl`1.ExecuteWriteOperation[TResult](IClientSessionHandle session, IWriteOperation`1 operation, CancellationToken cancellationToken)
   at MongoDB.Driver.MongoCollectionImpl`1.MongoSearchIndexManager.<>cDisplayClass2_0.<CreateMany>b0(IClientSessionHandle session)
   at MongoDB.Driver.MongoCollectionImpl`1.UsingImplicitSession[TResult](Func`2 func, CancellationToken cancellationToken)
   at MongoDB.Driver.MongoCollectionImpl`1.MongoSearchIndexManager.CreateMany(IEnumerable`1 models, CancellationToken cancellationToken)
   at MongoDB.Driver.MongoCollectionImpl`1.MongoSearchIndexManager.CreateOne(CreateSearchIndexModel model, CancellationToken cancellationToken)
   at candy_shop_ai.Repository.CandiesRepo.CreateIndex(String indexName) in C:\CarryCase\Venkatesh\ASPNETCore\8\candy-shop-ai\Repository\CandiesRepo.cs:line 47
   at candy_shop_ai.Repository.CandiesRepo..ctor(IMongoClient mongoClient, MongoUrl mongoUrl, ILogger`1 logger) in C:\CarryCase\Venkatesh\ASPNETCore\8\candy-shop-ai\Repository\CandiesRepo.cs:line 21

 

Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).

MongoDB Driver version: 2.23.1

MongoDB server version: 6.0.3

MongoDB Topolgy : standalone (installed in Kubernetes on Docker Desktop)

How to Reproduce

 

1) Install Mongo DB from https://charts.bitnami.com/bitnami on your Kubernetes cluster

2) Port-forward the same and check the access from Mongo Shell or Mongo Compass

3) On success of above step, Take the attached code and create appropriate mongo URL and mongo client and invoke the same with attached code. Alternatively use the provided code in console app and try

Additional Background

Please provide any additional background information that may be helpful in diagnosing the bug.



 Comments   
Comment by PM Bot [ 31/Jan/24 ]

There hasn't been any recent activity on this ticket, so we're resolving it. Thanks for reaching out! Please feel free to reopen this ticket if you're still experiencing the issue, and add a comment if you're able to provide more information.

Comment by PM Bot [ 23/Jan/24 ]

Hi venkateshsrini3@gmail.com! CSHARP-4893 is awaiting your response.

If this is still an issue for you, please open Jira to review the latest status and provide your feedback. Thanks!

Comment by Boris Dogadov [ 15/Jan/24 ]

Hi, here are some support resources:

  • Our MongoDB support portal, located at support.mongodb.com
  • Our MongoDB community portal, located here
  • If you are an Atlas customer, you can also: Click the in-app chat icon in the lower right corner to chat with a MongoDB Support representative OR Click Support in the left-hand navigation to view Developer Resources.

Thank you!

Comment by VenkateshSrini N/A [ 14/Jan/24 ]

I tried the Atlas installation on local as awell as docker using WSL . I get this error 

Creating your cluster local1320 [this might take several minutes]
1/3: Starting your local environment...
2/3: Downloading the MongoDB binaries to your local environment...
3/3: Creating your deployment local1320...
Error: network ip range was not found

I understand that C# driver team, cannot help me with this. Can you please point me to a place where I can raise this issue so that some one can help

Comment by VenkateshSrini N/A [ 11/Jan/24 ]

Give me a few more days. I will try to see if the Atlas cloud deployment supports this feature. If this is supported and still a C# driver issue then we can continue on this thread. Is there way you can put this in hibernation mode. 

Comment by Boris Dogadov [ 10/Jan/24 ]

Hi venkateshsrini3@gmail.com ,

We as a C# driver team will not be able to help with server deployments.
In addition to online documentation I can recommend our MongoDB Developer Community blog for more information in this area.

I'll be closing this ticket as C# Driver seems to work as expected here.
Please reopen or submit a new ticket if you encounter an issue or a bug within C# driver.

Thanks.

Comment by VenkateshSrini N/A [ 10/Jan/24 ]

Is there an Atlas local deployment that I can do on Kubernetes. I use windows Laptop with Docker Desktop. I can easily get it working. When I try to install atlas local deployment I get an error message Local deployments are not supported on this OS, to see local deployments requirements visit https://www.mongodb.com/docs/atlas/cli/stable/atlas-cli-deploy-local/.

Comment by Boris Dogadov [ 09/Jan/24 ]

Hi venkateshsrini3@gmail.com 

This server-side error indicates that Atlas search functionality not available on your current setup.
Please see the previous response for resources on how to install Atlas Search locally and/or use Atlas.

If there still is a suspicion that this is purely a C# Driver issue, providing createSearchIndexes command that works in MongoDB Shell, and the Atlas cluster version will allow us to investigate further.

Comment by VenkateshSrini N/A [ 09/Jan/24 ]

I have tried it after creating a database in cluster. I get this error message

MongoDB.Driver.MongoCommandException
  HResult=0x80131500
  Message=Command createSearchIndexes failed: command not found.
  Source=MongoDB.Driver.Core
  StackTrace:
   at MongoDB.Driver.Core.WireProtocol.CommandUsingCommandMessageWireProtocol`1.ProcessResponse(ConnectionId connectionId, CommandMessage responseMessage)
   at MongoDB.Driver.Core.WireProtocol.CommandUsingCommandMessageWireProtocol`1.Execute(IConnection connection, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.WireProtocol.CommandWireProtocol`1.Execute(IConnection connection, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Servers.Server.ServerChannel.ExecuteProtocol[TResult](IWireProtocol`1 protocol, ICoreSession session, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Servers.Server.ServerChannel.Command[TResult](ICoreSession session, ReadPreference readPreference, DatabaseNamespace databaseNamespace, BsonDocument command, IEnumerable`1 commandPayloads, IElementNameValidator commandValidator, BsonDocument additionalOptions, Action`1 postWriteAction, CommandResponseHandling responseHandling, IBsonSerializer`1 resultSerializer, MessageEncoderSettings messageEncoderSettings, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Operations.CommandOperationBase`1.ExecuteProtocol(IChannelHandle channel, ICoreSessionHandle session, ReadPreference readPreference, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Operations.CommandOperationBase`1.ExecuteProtocol(IChannelSource channelSource, ICoreSessionHandle session, ReadPreference readPreference, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Operations.WriteCommandOperation`1.Execute(IWriteBinding binding, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Operations.CreateSearchIndexesOperation.Execute(IWriteBinding binding, CancellationToken cancellationToken)
   at MongoDB.Driver.OperationExecutor.ExecuteWriteOperation[TResult](IWriteBinding binding, IWriteOperation`1 operation, CancellationToken cancellationToken)
   at MongoDB.Driver.MongoCollectionImpl`1.ExecuteWriteOperation[TResult](IClientSessionHandle session, IWriteOperation`1 operation, CancellationToken cancellationToken)
   at MongoDB.Driver.MongoCollectionImpl`1.MongoSearchIndexManager.<>c__DisplayClass2_0.<CreateMany>b__0(IClientSessionHandle session)
   at MongoDB.Driver.MongoCollectionImpl`1.UsingImplicitSession[TResult](Func`2 func, CancellationToken cancellationToken)
   at MongoDB.Driver.MongoCollectionImpl`1.MongoSearchIndexManager.CreateMany(IEnumerable`1 models, CancellationToken cancellationToken)
   at MongoDB.Driver.MongoCollectionImpl`1.MongoSearchIndexManager.CreateOne(CreateSearchIndexModel model, CancellationToken cancellationToken)
   at candy_shop_ai.Repository.CandiesRepo.CreateIndex(String indexName) in C:\CarryCase\Venkatesh\ASPNETCore\8\candy-shop-ai\Repository\CandiesRepo.cs:line 47
   at candy_shop_ai.Repository.CandiesRepo..ctor(IMongoClient mongoClient, MongoUrl mongoUrl, ILogger`1 logger) in C:\CarryCase\Venkatesh\ASPNETCore\8\candy-shop-ai\Repository\CandiesRepo.cs:line 21
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span`1 copyOfArgs, BindingFlags invokeAttr) in System.Reflection\MethodBaseInvoker.cs:line 172
   at System.Reflection.MethodBaseInvoker.InvokeWithFewArgs(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) in System.Reflection\MethodBaseInvoker.cs:line 152
   at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) in System.Reflection\RuntimeConstructorInfo.cs:line 410
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopeCache(ServiceCallSite callSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine.<>c__DisplayClass2_0.<RealizeService>b__0(ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(ServiceIdentifier serviceIdentifier, ServiceProviderEngineScope serviceProviderEngineScope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
   at candy_shop_ai.ServiceExtension.MiddlewareExtension.UseSeedData(WebApplication app) in C:\CarryCase\Venkatesh\ASPNETCore\8\candy-shop-ai\ServiceExtension\MiddlewareExtension.cs:line 39
   at candy_shop_ai.ServiceExtension.MiddlewareExtension.UseAppMiddleware(WebApplication app) in C:\CarryCase\Venkatesh\ASPNETCore\8\candy-shop-ai\ServiceExtension\MiddlewareExtension.cs:line 17
   at Program.<Main>$(String[] args) in C:\CarryCase\Venkatesh\ASPNETCore\8\candy-shop-ai\Program.cs:line 11

Comment by VenkateshSrini N/A [ 05/Jan/24 ]

boris.dogadov@mongodb.com please give me a day. I'm on windows laptop and need to get the operator running on my docker. I will try this over the weekend or next week and revert

Comment by Boris Dogadov [ 04/Jan/24 ]

Hi venkateshsrini3@gmail.com,

This error is an expected server side error (not related to C# driver) as local mongodb deployments do not contain search feature.

Vector search is part of Atlas Search, which was only available on cloud Atlas deployments until a recent public preview of local Atlas was announced.
Here is a guide on how to install and use local Atlas (including Atlas search and Vector search), and general Atlas Search documentation.

Thanks.

Comment by VenkateshSrini N/A [ 04/Jan/24 ]

I have tried the same with 7.0.4 release candidate version also and it is not working. The exact image version in the docker is 

docker.io/bitnami/mongodb:7.0.4-debian-11-r4

Comment by PM Bot [ 26/Dec/23 ]

Hi venkateshsrini3@gmail.com, thank you for reporting this issue! The team will look into it and get back to you soon.

Generated at Wed Feb 07 21:49:42 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.