@@ -89,14 +89,11 @@ func (m *Manager) Metrics() metric.Struct {
89
89
return & m .metrics
90
90
}
91
91
92
- // getImpl returns the vector index for the given DB table and index. If the DB
92
+ // Get returns the vector index for the given DB table and index. If the DB
93
93
// index does not currently have an active vector index, one is created and
94
94
// cached.
95
- func (m * Manager ) getImpl (
96
- ctx context.Context ,
97
- tableID catid.DescID ,
98
- indexID catid.IndexID ,
99
- makeIndex func () (* cspann.Index , error ),
95
+ func (m * Manager ) Get (
96
+ ctx context.Context , tableID catid.DescID , indexID catid.IndexID ,
100
97
) (* cspann.Index , error ) {
101
98
m .mu .Lock ()
102
99
defer m .mu .Unlock ()
@@ -133,8 +130,24 @@ func (m *Manager) getImpl(
133
130
if m .testingKnobs != nil && m .testingKnobs .DuringVecIndexPull != nil {
134
131
m .testingKnobs .DuringVecIndexPull ()
135
132
}
136
-
137
- idx , err := makeIndex ()
133
+ config , err := m .getVecConfig (ctx , tableID , indexID )
134
+ if err != nil {
135
+ return nil , err
136
+ }
137
+ // TODO(drewk): use the config to populate the index options as well.
138
+ quantizer := quantize .NewRaBitQuantizer (int (config .Dims ), config .Seed , config .DistanceMetric )
139
+ store , err := vecstore .New (ctx , m .db , quantizer , m .codec , tableID , indexID )
140
+ if err != nil {
141
+ return nil , err
142
+ }
143
+ // Use the stored context so that the vector index can outlive the context
144
+ // of the Get call. The fixup process gets a child context from the context
145
+ // passed to cspann.NewIndex, and we don't want that to be the context of
146
+ // the Get call.
147
+ idx , err := cspann .NewIndex (
148
+ m .ctx , store , quantizer , config .Seed ,
149
+ m .getIndexOptions (& config , store .ReadOnly ()), m .stopper ,
150
+ )
138
151
if err != nil {
139
152
return nil , err
140
153
}
@@ -158,68 +171,6 @@ func (m *Manager) getImpl(
158
171
return idx , err
159
172
}
160
173
161
- // GetWithDesc returns a cached cspann vector index for a given table and index
162
- // using the provided table descriptor and index.
163
- func (m * Manager ) GetWithDesc (
164
- ctx context.Context , desc catalog.TableDescriptor , index catalog.Index ,
165
- ) (* cspann.Index , error ) {
166
- return m .getImpl (
167
- ctx ,
168
- desc .GetID (),
169
- index .GetID (),
170
- func () (* cspann.Index , error ) {
171
- // TODO(drewk): use the config to populate the index options as well.
172
- config := index .GetVecConfig ()
173
- quantizer := quantize .NewRaBitQuantizer (
174
- int (config .Dims ), config .Seed , config .DistanceMetric )
175
- store , err := vecstore .NewWithColumnID (
176
- ctx , m .db , quantizer , m .codec , desc , index .GetID (), index .VectorColumnID (),
177
- )
178
- if err != nil {
179
- return nil , err
180
- }
181
-
182
- return cspann .NewIndex (
183
- m .ctx , store , quantizer , config .Seed ,
184
- m .getIndexOptions (& config , store .ReadOnly ()), m .stopper ,
185
- )
186
- },
187
- )
188
- }
189
-
190
- // Get returns a cached cspann vector index for a given table and index using the
191
- // descriptor IDs for both.
192
- func (m * Manager ) Get (
193
- ctx context.Context , tableID catid.DescID , indexID catid.IndexID ,
194
- ) (* cspann.Index , error ) {
195
- return m .getImpl (
196
- ctx ,
197
- tableID ,
198
- indexID ,
199
- func () (* cspann.Index , error ) {
200
- config , err := m .getVecConfig (ctx , tableID , indexID )
201
- if err != nil {
202
- return nil , err
203
- }
204
- // TODO(drewk): use the config to populate the index options as well.
205
- quantizer := quantize .NewRaBitQuantizer (
206
- int (config .Dims ), config .Seed , config .DistanceMetric )
207
- store , err := vecstore .New (ctx , m .db , quantizer , m .codec , tableID , indexID )
208
- if err != nil {
209
- return nil , err
210
- }
211
- // Use the stored context so that the vector index can outlive the context
212
- // of the Get call. The fixup process gets a child context from the context
213
- // passed to cspann.NewIndex, and we don't want that to be the context of
214
- // the Get call.
215
- return cspann .NewIndex (
216
- m .ctx , store , quantizer , config .Seed ,
217
- m .getIndexOptions (& config , store .ReadOnly ()), m .stopper ,
218
- )
219
- },
220
- )
221
- }
222
-
223
174
func (m * Manager ) getIndexOptions (config * vecpb.Config , readOnly bool ) * cspann.IndexOptions {
224
175
return & cspann.IndexOptions {
225
176
RotAlgorithm : config .RotAlgorithm ,
@@ -256,7 +207,7 @@ func (m *Manager) getVecConfig(
256
207
return vecpb.Config {}, errTableNotFound
257
208
}
258
209
var idxDesc catalog.Index
259
- for _ , desc := range tableDesc .DeletableNonPrimaryIndexes () {
210
+ for _ , desc := range tableDesc .NonPrimaryIndexes () {
260
211
if desc .GetID () == indexID {
261
212
idxDesc = desc
262
213
break
0 commit comments