protected void indexVectorInternal ( double [ ] vector ) throws Exception { if ( vector . length != vectorLength ) { throw new Exception ( "The dimensionality of the vector is wrong!" ) ; } // apply a random transformation if needed if ( transformation == TransformationType . RandomRotation ) { vector = rr . rotate ( vector ) ; } else if ( transformation == TransformationType . RandomPermutation ) { vector = rp . permute ( vector ) ; } // transform the vector into a PQ code int [ ] pqCode = new int [ numSubVectors ] ; for ( int i = 0 ; i < numSubVectors ; i ++ ) { // take the appropriate sub-vector int fromIdex = i * subVectorLength ; int toIndex = fromIdex + subVectorLength ; double [ ] subvector = Arrays . copyOfRange ( vector , fromIdex , toIndex ) ; // assign the sub-vector to the nearest centroid of the respective sub-quantizer pqCode [ i ] = computeNearestProductIndex ( subvector , i ) ; } if ( numProductCentroids <= 256 ) { byte [ ] pqByteCode = transformToByte ( pqCode ) ; if ( loadIndexInMemory ) { // append the ram-based index pqByteCodes . add ( pqByteCode ) ; } appendPersistentIndex ( pqByteCode ) ; // append the disk-based index } else { short [ ] pqShortCode = transformToShort ( pqCode ) ; if ( loadIndexInMemory ) { // append the ram-based index pqShortCodes . add ( pqShortCode ) ; } appendPersistentIndex ( pqShortCode ) ; // append the disk-based index } }
Append the PQ index with the given vector .