Class Collection

java.lang.Object
org.zvec.binding.Collection
All Implemented Interfaces:
AutoCloseable

public class Collection extends Object implements AutoCloseable
High-level wrapper for zvec_collection_t.

Obtain via Zvec.createAndOpen(java.lang.String, org.zvec.binding.CollectionSchema, org.zvec.binding.CollectionOptions) or Zvec.open(java.lang.String, org.zvec.binding.CollectionOptions). Always call close() when done.

After close() every operation on this object throws a ZvecException with ErrorCode.FAILED_PRECONDITION instead of passing a released handle into the native layer.

close() and destroy() are safe to call from any thread and are idempotent. The operations themselves are not synchronized: the native collection is safe to use from several threads, but a caller must not use a collection concurrently with closing it.

  • Method Details

    • isOpen

      public boolean isOpen()
      Returns true while the native handle is still usable.
    • close

      public void close()
      Close the collection. Safe to call multiple times and from any thread.
      Specified by:
      close in interface AutoCloseable
    • destroy

      public void destroy()
      Destroy collection data on disk AND close the handle.
    • flush

      public void flush()
    • optimize

      public void optimize()
    • getSchema

      public CollectionSchema getSchema()
      Get the collection schema. Caller must destroy the returned schema.
    • getOptions

      public CollectionOptions getOptions()
      Get the collection options. Caller must destroy the returned options.
    • getStats

      public CollectionStats getStats()
      Get collection statistics. The C stats pointer is consumed internally.
    • createIndex

      public void createIndex(String fieldName, IndexParams params)
    • dropIndex

      public void dropIndex(String fieldName)
    • addColumn

      public void addColumn(FieldSchema fieldSchema, String defaultExpr)
    • dropColumn

      public void dropColumn(String columnName)
    • alterColumn

      public void alterColumn(String columnName, String newName, FieldSchema newSchema)
    • insert

      public Collection.WriteResult insert(List<Doc> docs)
    • update

      public Collection.WriteResult update(List<Doc> docs)
    • upsert

      public Collection.WriteResult upsert(List<Doc> docs)
    • delete

      public Collection.WriteResult delete(List<String> pks)
    • deleteByFilter

      public void deleteByFilter(String filter)
    • query

      public List<Doc> query(VectorQuery query)
      Execute a vector query. Returns a list of owned Docs; caller must free them.
    • query

      public List<Doc> query(MultiQuery query)
      Execute a multi-query (e.g., vector + FTS fusion). Returns a list of owned Docs.
    • fetch

      public List<Doc> fetch(List<String> pks)
      Fetch documents by primary key. Returns a list of owned Docs; caller must free them.
    • createIterator

      public DocIterator createIterator(IteratorOptions options)
      Create a snapshot document iterator over this collection.

      The iterator sees an isolated snapshot taken at call time. While any iterator is open, schema changes (create/drop index, add/alter/drop column) and destroy() return an error; close every iterator before releasing the last collection handle.

      Parameters:
      options - iterator options, or null for defaults (all fields, vectors included)