(options = {})
| 69 | |
| 70 | export class VectorStore { |
| 71 | constructor(options = {}) { |
| 72 | if (!options.dimension) { |
| 73 | throw new Error('VectorStore requires a dimension.'); |
| 74 | } |
| 75 | |
| 76 | this.name = options.name || 'default'; |
| 77 | this.dimension = options.dimension; |
| 78 | this.metric = normalizeMetric(options.metric); |
| 79 | this.normalize = options.normalize ?? (this.metric === 'cosine'); |
| 80 | this.backendName = typeof options.backend === 'string' ? options.backend : 'custom'; |
| 81 | this.backend = resolveBackend(options.backend, { |
| 82 | ...options, |
| 83 | name: this.name, |
| 84 | dimension: this.dimension, |
| 85 | metric: this.metric, |
| 86 | normalize: this.normalize |
| 87 | }); |
| 88 | this.ready = Promise.resolve().then(() => this.backend.init?.({ |
| 89 | ...options, |
| 90 | name: this.name, |
| 91 | dimension: this.dimension, |
| 92 | metric: this.metric, |
| 93 | normalize: this.normalize |
| 94 | })); |
| 95 | } |
| 96 | |
| 97 | async upsert(items) { |
| 98 | await this.ready; |
nothing calls this directly
no test coverage detected