Record Class MatchResult
java.lang.Object
java.lang.Record
smile.llm.cache.MatchResult
- Record Components:
indices- a freshly-allocated 1-Dint64tensor containing the concatenated KV cache slot indices for the longest cached prefix found. Its length is always a multiple of the cache'spageSize. An empty tensor (length 0) means nothing was found in the cache.lastNode- the deepestRadixTreeNodereached during matching. Callers should pass this node toRadixCache.incLockRef(RadixTreeNode)to protect the matched prefix from eviction while the request is in flight, and toRadixCache.decLockRef(RadixTreeNode)when done.
- All Implemented Interfaces:
AutoCloseable
public record MatchResult(Tensor indices, RadixTreeNode lastNode)
extends Record
implements AutoCloseable
Result returned by
RadixCache.matchPrefix(int[]).
This record implements AutoCloseable so callers can use
try-with-resources to release the indices() tensor automatically:
try (var result = cache.matchPrefix(tokenIds)) {
process(result.indices());
}
The caller owns the indices() tensor. If
try-with-resources is not used, the caller must call close()
(or indices().close()) explicitly.
-
Constructor Summary
ConstructorsConstructorDescriptionMatchResult(Tensor indices, RadixTreeNode lastNode) Creates an instance of aMatchResultrecord class. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Releases theindices()tensor.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.indices()Returns the value of theindicesrecord component.lastNode()Returns the value of thelastNoderecord component.intlength()Returns the number of matched token slots (equal toindices.length()).final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
Method Details
-
length
public int length()Returns the number of matched token slots (equal toindices.length()).- Returns:
- the number of matched tokens.
-
close
public void close()Releases theindices()tensor. Called automatically when this result is used in a try-with-resources statement.- Specified by:
closein interfaceAutoCloseable
-
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object). -
indices
-
lastNode
-