microsoft / kernel-memory

RAG architecture: index and query any data using LLM and natural language, track sources, show citations, asynchronous memory patterns.
https://microsoft.github.io/kernel-memory
MIT License
1.52k stars 293 forks source link

[Question] Could we make ITextGenerator a loose dependency? #466

Closed cthlo closed 4 months ago

cthlo commented 4 months ago

Context / Scenario

In my case, I'm just using Kernel Memory to import memory (ImportDocumentAsync) and query memory (SearchAsync). And I am excluding the summarization step, i.e. just extract, partition, gen_embeddings, save_records.

Without configuring an ITextGenerator, it won't activate the orchestrator.

## Error ##
* Message:  Unable to resolve service for type 'Microsoft.KernelMemory.AI.ITextGenerator' while attempting to activate 'Microsoft.KernelMemory.Pipeline.InProcessPipelineOrchestrator'.
* Type:     InvalidOperationException [System.InvalidOperationException]
* Location: at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateArgumentCallSites(ServiceIdentifier serviceIdentifier, Type implementationType, CallSiteChain callSiteChain, ParameterInfo[] parameters, Boolean throwIfCallSiteNotFound)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateConstructorCallSite(ResultCache lifetime, ServiceIdentifier serviceIdentifier, Type implementationType, CallSiteChain callSiteChain)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact(ServiceDescriptor descriptor, ServiceIdentifier serviceIdentifier, CallSiteChain callSiteChain, Int32 slot)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact(ServiceIdentifier serviceIdentifier, CallSiteChain callSiteChain)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateCallSite(ServiceIdentifier serviceIdentifier, CallSiteChain callSiteChain)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.GetCallSite(ServiceIdentifier serviceIdentifier, CallSiteChain callSiteChain)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.CreateServiceAccessor(ServiceIdentifier serviceIdentifier)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(ServiceIdentifier serviceIdentifier, ServiceProviderEngineScope serviceProviderEngineScope)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.ConstructorInfoEx.GetService(IServiceProvider serviceProvider, Int32 parameterIndex)
   at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.ConstructorMatcher.CreateInstance(IServiceProvider provider)
   at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance(IServiceProvider provider, Type instanceType, Object[] parameters)
   at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance[T](IServiceProvider provider, Object[] parameters)
   at Microsoft.KernelMemory.KernelMemoryBuilder.BuildServerlessClient()

Question

Is it reasonable to make ITextGenerator a loose dependency?

dluc commented 4 months ago

I have the same problem, there are a bunch of dependencies currently mandatory even when they are not used. We'll address that at some point, for now you can use this workaround:

kmBuilder.WithOpenAITextGeneration(new OpenAIConfig { APIKey = "none" })
dluc commented 4 months ago

For a temporary solution, please see https://github.com/microsoft/kernel-memory/pull/472

I'll close this issue for now, although the issue is not completely solved, something that will be addressed at some point.