@bytebitlabs/nest-qdrant
v1.0.0-0
Published
<p align="center"> <a href="https://bytebitlabs.com/" target="_blank"><img src="https://gravatar.com/avatar/61c80d73dfe4c4231e77940cf80fd410?size=256" width="256" alt="ByteBitLabs logo" /></a> </p>
Downloads
344
Readme
nest-qdrant
Description
Qdrant module for Nest based on the official @qdrant/js-client-rest package.
Installation
$ npm i --save @bytebitlabs/nest-qdrant @qdrant/js-client-rest
Usage
Import QdrantModule
:
@Module({
imports: [Qdrant.register({
url: 'http://127.0.0.1:6333',
})],
providers: [...],
})
export class VectorStoreModule {}
Inject QdrantService
:
@Injectable()
export class VectorStoreService {
constructor(private readonly qdrantService: QdrantService) {}
}
Async options
Quite often you might want to asynchronously pass your module options instead of passing them beforehand. In such case, use registerAsync()
method, that provides a couple of various ways to deal with async data.
1. Use factory
QdrantModule.registerAsync({
useFactory: () => ({
url: 'http://127.0.0.1:6333'
})
});
Obviously, our factory behaves like every other one (might be async
and is able to inject dependencies through inject
).
QdrantModule.registerAsync({
imports: [ConfigModule],
useFactory: async (configService: ConfigService) => ({
url: configService.get('QDRANT_URL'),
}),
inject: [ConfigService],
}),
2. Use class
QdrantModule.registerAsync({
useClass: QdrantConfigService
});
Above construction will instantiate QdrantConfigService
inside QdrantModule
and will leverage it to create options object.
class QdrantConfigService implements QdrantOptionsFactory {
createQdrantOptions(): QdrantModuleOptions {
return {
url: 'http://127.0.0.1:6333'
};
}
}
3. Use existing
QdrantModule.registerAsync({
imports: [ConfigModule],
useExisting: ConfigService,
}),
It works the same as useClass
with one critical difference - QdrantModule
will lookup imported modules to reuse already created ConfigService
, instead of instantiating it on its own.
API Spec
The QdrantService
wraps the QdrantClient
from the official @qdrant/js-client-rest
methods. The QdrantModule.register()
takes options
object as an argument, read more.