MCPcopy Create free account
hub / github.com/apache/solr / CuVSCodec

Class CuVSCodec

solr/modules/cuvs/src/java/org/apache/solr/cuvs/CuVSCodec.java:40–112  ·  view source on GitHub ↗

This codec utilizes the Lucene99AcceleratedHNSWVectorsFormat from the lucene-cuvs library to enable GPU-based accelerated vector search. @since 10.0.0

Source from the content-addressed store, hash-verified

38 * @since 10.0.0
39 */
40public 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,

Callers

nothing calls this directly

Calls 1

lookupMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…