coherence.ai [24.09.2+ server required]
Vector
BitVector
- class coherence.ai.BitVector(hex_string: str, byte_array: bytes | None = None, int_array: List[int] | None = None)
Bases:
Vector
Class that represents a Vector of Bits.
NOTE: This requires using Coherence CE 24.09.2+ on the server side.
- __init__(hex_string: str, byte_array: bytes | None = None, int_array: List[int] | None = None)
Creates an instance of BitVector.
- Parameters:
hex_string – hexadecimal string used to create the BitVector.
byte_array – optional byte array used to create the BitVector.
int_array – optional int array used to create the BitVector.
ByteVector
FloatVector
- class coherence.ai.FloatVector(float_array: List[float])
Bases:
Vector
Class that represents Vector of floats.
NOTE: This requires using Coherence CE 24.09.2+ on the server side.
- __init__(float_array: List[float])
Creates an instance of FloatVector.
- Parameters:
float_array – array of floats used to create a FloatVector.
DocumentChunk
- class coherence.ai.DocumentChunk(text: str, metadata: Dict[str, Any] | OrderedDict[str, Any] | None = None, vector: Vector | None = None)
Bases:
AbstractEvolvable
Class that represents a chunk of text extracted from a document.
NOTE: This requires using Coherence CE 24.09.2+ on the server side.
- __init__(text: str, metadata: Dict[str, Any] | OrderedDict[str, Any] | None = None, vector: Vector | None = None)
Creates an instance of DocumentChunk class.
- Parameters:
text – the chunk of text extracted from a document.
metadata – optional document metadata.
vector – the vector associated with the document chunk.
DistanceAlgorithm
CosineDistance
- class coherence.ai.CosineDistance
Bases:
DistanceAlgorithm
Represents a DistanceAlgorithm that performs a cosine similarity calculation between two vectors. Cosine similarity measures the similarity between two vectors of an inner product space. It is measured by the cosine of the angle between two vectors and determines whether two vectors are pointing in roughly the same direction. It is often used to measure document similarity in text analysis.
NOTE: This requires using Coherence CE 24.09.2+ on the server side.
- __init__() None
InnerProductDistance
- class coherence.ai.InnerProductDistance
Bases:
DistanceAlgorithm
Represents a DistanceAlgorithm that performs inner product distance calculation between two vectors.
NOTE: This requires using Coherence CE 24.09.2+ on the server side.
- __init__() None
L2SquaredDistance
- class coherence.ai.L2SquaredDistance
Bases:
DistanceAlgorithm
Represents a DistanceAlgorithm that performs an L2 squared distance calculation between two vectors.
NOTE: This requires using Coherence CE 24.09.2+ on the server side.
- __init__() None
SimilaritySearch
- class coherence.ai.SimilaritySearch(extractor_or_property: ~coherence.extractor.ValueExtractor[~coherence.ai.T, ~coherence.ai.E] | str, vector: ~coherence.ai.Vector, max_results: int, algorithm: ~coherence.ai.DistanceAlgorithm | None = <coherence.ai.CosineDistance object>, filter: ~coherence.filter.Filter | None = None, brute_force: bool | None = False)
Bases:
EntryAggregator
This class represents an aggregator to execute a similarity query.
NOTE: This requires using Coherence CE 24.09.2+ on the server side.
- __init__(extractor_or_property: ~coherence.extractor.ValueExtractor[~coherence.ai.T, ~coherence.ai.E] | str, vector: ~coherence.ai.Vector, max_results: int, algorithm: ~coherence.ai.DistanceAlgorithm | None = <coherence.ai.CosineDistance object>, filter: ~coherence.filter.Filter | None = None, brute_force: bool | None = False) None
Create a SimilaritySearch aggregator that will use cosine distance to calculate and return up to max_results results that are closest to the specified vector.
- Parameters:
extractor_or_property – the ValueExtractor to extract the vector from the cache value.
vector – the vector to calculate similarity with.
max_results – the maximum number of results to return.
algorithm – the distance algorithm to use.
filter – filter to use to limit the set of entries to search.
brute_force – Force brute force search, ignoring any available indexes.
QueryResult
- class coherence.ai.QueryResult(result: float, key: K, value: V)
Bases:
BaseQueryResult
QueryResult class.
NOTE: This requires using Coherence CE 24.09.2+ on the server side.
- __init__(result: float, key: K, value: V) None
Creates an instance of the QueryResult class.
- Parameters:
result – the query result.
key – the key of the vector the result applies to.
value – the optional result value.
BinaryQuantIndex
- class coherence.ai.BinaryQuantIndex(extractor: ValueExtractor[T, E] | str, over_sampling_factor: int = 3)
Bases:
AbstractEvolvable
This class represents a custom index using binary quantization of vectors.
NOTE: This requires using Coherence CE 24.09.2+ on the server side.
- __init__(extractor: ValueExtractor[T, E] | str, over_sampling_factor: int = 3) None
Creates an instance of BinaryQuantIndex class.
- Parameters:
extractor – the ValueExtractor to use to extract the Vector.
over_sampling_factor – the oversampling factor.