This codec utilizes the Lucene99AcceleratedHNSWVectorsFormat from the lucene-cuvs library to enable GPU-based accelerated vector search. @since 10.0.0
| 38 | * @since 10.0.0 |
| 39 | */ |
| 40 | public class CuVSCodec extends FilterCodec { |
| 41 | |
| 42 | private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); |
| 43 | private static final String FALLBACK_CODEC = "Lucene104"; |
| 44 | private final SolrCore core; |
| 45 | private final Lucene104Codec fallbackCodec; |
| 46 | |
| 47 | public CuVSCodec(SolrCore core, Lucene104Codec fallback, NamedList<?> args) { |
| 48 | super(FALLBACK_CODEC, fallback); |
| 49 | this.core = core; |
| 50 | this.fallbackCodec = fallback; |
| 51 | } |
| 52 | |
| 53 | @Override |
| 54 | public KnnVectorsFormat knnVectorsFormat() { |
| 55 | return perFieldKnnVectorsFormat; |
| 56 | } |
| 57 | |
| 58 | private PerFieldKnnVectorsFormat perFieldKnnVectorsFormat = |
| 59 | new PerFieldKnnVectorsFormat() { |
| 60 | @Override |
| 61 | public KnnVectorsFormat getKnnVectorsFormatForField(String field) { |
| 62 | final SchemaField schemaField = core.getLatestSchema().getFieldOrNull(field); |
| 63 | FieldType fieldType = (schemaField == null ? null : schemaField.getType()); |
| 64 | if (fieldType instanceof DenseVectorField vectorType) { |
| 65 | String knnAlgorithm = vectorType.getKnnAlgorithm(); |
| 66 | if (DenseVectorField.CAGRA_HNSW_ALGORITHM.equals(knnAlgorithm)) { |
| 67 | |
| 68 | int cuvsWriterThreads = vectorType.getCuvsWriterThreads(); |
| 69 | int cuvsIntGraphDegree = vectorType.getCuvsIntGraphDegree(); |
| 70 | int cuvsGraphDegree = vectorType.getCuvsGraphDegree(); |
| 71 | int cuvsHnswLayers = vectorType.getCuvsHnswLayers(); |
| 72 | int cuvsHnswM = vectorType.getCuvsHnswMaxConn(); |
| 73 | int cuvsHnswEfConstruction = vectorType.getCuvsHnswEfConstruction(); |
| 74 | |
| 75 | assert cuvsWriterThreads > 0 : "cuvsWriterThreads cannot be less then or equal to 0"; |
| 76 | assert cuvsIntGraphDegree > 0 |
| 77 | : "cuvsIntGraphDegree cannot be less then or equal to 0"; |
| 78 | assert cuvsGraphDegree > 0 : "cuvsGraphDegree cannot be less then or equal to 0"; |
| 79 | assert cuvsHnswLayers > 0 : "cuvsHnswLayers cannot be less then or equal to 0"; |
| 80 | assert cuvsHnswM > 0 : "cuvsHnswM cannot be less then or equal to 0"; |
| 81 | assert cuvsHnswEfConstruction > 0 |
| 82 | : "cuvsHnswEfConstruction cannot be less then or equal to 0"; |
| 83 | |
| 84 | if (log.isInfoEnabled()) { |
| 85 | log.info( |
| 86 | "Initializing Lucene99AcceleratedHNSWVectorsFormat with parameter values: cuvsWriterThreads {}, cuvsIntGraphDegree {}, cuvsGraphDegree {}, cuvsHnswLayers {}, cuvsHnswM {}, cuvsHnswEfConstruction {}", |
| 87 | cuvsWriterThreads, |
| 88 | cuvsIntGraphDegree, |
| 89 | cuvsGraphDegree, |
| 90 | cuvsHnswLayers, |
| 91 | cuvsHnswM, |
| 92 | cuvsHnswEfConstruction); |
| 93 | } |
| 94 | return new Lucene99AcceleratedHNSWVectorsFormat( |
| 95 | cuvsWriterThreads, |
| 96 | cuvsIntGraphDegree, |
| 97 | cuvsGraphDegree, |
nothing calls this directly
no test coverage detected
searching dependent graphs…