private native void nativeConstructor()

in java/src/main/java/com/spotify/voyager/jni/Index.java [333:433]


  private native void nativeConstructor(
      SpaceType space,
      int numDimensions,
      long indexM,
      long efConstruction,
      long randomSeed,
      long maxElements,
      StorageDataType storageDataType);

  private native void nativeLoadFromFileWithParameters(
      String filename, SpaceType space, int numDimensions, StorageDataType storageDataType);

  private native void nativeLoadFromFile(String filename);

  private native void nativeLoadFromInputStreamWithParameters(
      InputStream inputStream, SpaceType space, int numDimensions, StorageDataType storageDataType);

  private native void nativeLoadFromInputStream(InputStream inputStream);

  private native void nativeDestructor();

  /**
   * Set the default EF ("query search depth") to use when {@link Index#query} is called.
   *
   * @param ef The new default EF value to use. This value can be overridden on a per-query basis at
   *     query time.
   */
  public native void setEf(long ef);

  /**
   * Get the default EF ("query search depth") that will be uses when {@link Index#query} is called.
   *
   * @return The current default EF value, used by the {@link Index} if no value is provided at
   *     query time.
   */
  public native int getEf();

  /**
   * Get the {@link Index.SpaceType} that this {@link Index} uses to store and compare vectors.
   *
   * @return The {@link Index.SpaceType} that is currently used by this {@link Index}.
   */
  public native SpaceType getSpace();

  /**
   * Get the number of dimensions used in this {@link Index}.
   *
   * @return The number of dimensions used by this {@link Index}, and which all vectors within this
   *     {@link Index} must have.
   */
  public native int getNumDimensions();

  /**
   * Set the default number of threads to use when adding multiple vectors in bulk, or when querying
   * for multiple vectors simultaneously.
   *
   * @param numThreads The default number of threads used for bulk-add or bulk-query methods if not
   *     overridden in each method call. Note that this affects the number of threads started for
   *     each method call - Voyager keeps no long-lived thread pool. For maximum efficiency, pass as
   *     much data as possible to each bulk-add or bulk-query method call to minimize overhead.
   */
  public native void setNumThreads(int numThreads);

  /**
   * Get the default number of threads used when adding multiple vectors in bulk oor when querying
   * for multiple vectors simultaneously.
   *
   * @return The default number of threads used for bulk-add or bulk-query methods if not overridden
   *     in each method call.
   */
  public native int getNumThreads();

  /**
   * Save this Index to a file at the provided filename. This file can be reloaded by using {@code
   * Index.load(...)}.
   *
   * @param pathToIndex The output filename to write to.
   */
  public native void saveIndex(String pathToIndex);

  /**
   * Save this Index to the provided output stream. The stream will not be closed automatically - be
   * sure to close the stream {@code saveIndex} has completed. The data written to the stream can be
   * reloaded by using {@code Index.load(...)}.
   *
   * @param outputStream The output stream to write to. This stream will not be closed
   *     automatically.
   */
  public native void saveIndex(OutputStream outputStream);

  /**
   * Returns the contents of this index as an array of bytes. The resulting bytes will contain the
   * same data as if this index was serialized to disk and then read back into memory again.
   *
   * @return A {@link byte} array representing the contents of the index
   */
  public byte[] asBytes() {
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    saveIndex(byteArrayOutputStream);
    return byteArrayOutputStream.toByteArray();
  }