Skip to content

Commit 369b9f9

Browse files
authored
COH-31299 - Add documentation for AI in Sphinx (#205)
* COH-31299 - Add documentation for AI in Sphinx
1 parent e931389 commit 369b9f9

File tree

4 files changed

+169
-34
lines changed

4 files changed

+169
-34
lines changed

docs/api_reference.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
..
2-
Copyright (c) 2022, 2024, Oracle and/or its affiliates.
2+
Copyright (c) 2022, 2025, Oracle and/or its affiliates.
33
Licensed under the Universal Permissive License v 1.0 as shown at
44
https://oss.oracle.com/licenses/upl.
55
@@ -112,6 +112,7 @@ Modules
112112
:maxdepth: 3
113113
:titlesonly:
114114

115+
api_reference/ai.rst
115116
api_reference/aggregator.rst
116117
api_reference/comparator.rst
117118
api_reference/event.rst

docs/api_reference/ai.rst

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
..
2+
Copyright (c) 2025, Oracle and/or its affiliates.
3+
Licensed under the Universal Permissive License v 1.0 as shown at
4+
https://oss.oracle.com/licenses/upl.
5+
6+
=======================================
7+
coherence.ai [24.09.2+ server required]
8+
=======================================
9+
.. toctree::
10+
:maxdepth: 4
11+
12+
13+
Vector
14+
------
15+
.. autoclass:: coherence.ai.Vector
16+
:show-inheritance:
17+
:members:
18+
19+
.. automethod:: __init__
20+
21+
BitVector
22+
---------
23+
.. autoclass:: coherence.ai.BitVector
24+
:show-inheritance:
25+
:members:
26+
27+
.. automethod:: __init__
28+
29+
ByteVector
30+
----------
31+
.. autoclass:: coherence.ai.ByteVector
32+
:show-inheritance:
33+
:members:
34+
35+
.. automethod:: __init__
36+
37+
FloatVector
38+
-----------
39+
.. autoclass:: coherence.ai.FloatVector
40+
:show-inheritance:
41+
:members:
42+
43+
.. automethod:: __init__
44+
45+
DocumentChunk
46+
-------------
47+
.. autoclass:: coherence.ai.DocumentChunk
48+
:show-inheritance:
49+
:members:
50+
51+
.. automethod:: __init__
52+
53+
DistanceAlgorithm
54+
-----------------
55+
.. autoclass:: coherence.ai.DistanceAlgorithm
56+
:show-inheritance:
57+
:members:
58+
59+
.. automethod:: __init__
60+
61+
CosineDistance
62+
--------------
63+
.. autoclass:: coherence.ai.CosineDistance
64+
:show-inheritance:
65+
:members:
66+
67+
.. automethod:: __init__
68+
69+
InnerProductDistance
70+
--------------------
71+
.. autoclass:: coherence.ai.InnerProductDistance
72+
:show-inheritance:
73+
:members:
74+
75+
.. automethod:: __init__
76+
77+
L2SquaredDistance
78+
-----------------
79+
.. autoclass:: coherence.ai.L2SquaredDistance
80+
:show-inheritance:
81+
:members:
82+
83+
.. automethod:: __init__
84+
85+
SimilaritySearch
86+
-----------------
87+
.. autoclass:: coherence.ai.SimilaritySearch
88+
:show-inheritance:
89+
:members:
90+
91+
.. automethod:: __init__
92+
93+
QueryResult
94+
-----------
95+
.. autoclass:: coherence.ai.QueryResult
96+
:show-inheritance:
97+
:members:
98+
99+
.. automethod:: __init__
100+
101+
BinaryQuantIndex
102+
----------------
103+
.. autoclass:: coherence.ai.BinaryQuantIndex
104+
:show-inheritance:
105+
:members:
106+
107+
.. automethod:: __init__

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2022, 2024, Oracle and/or its affiliates.
1+
# Copyright (c) 2022, 2025, Oracle and/or its affiliates.
22
# Licensed under the Universal Permissive License v 1.0 as shown at
33
# https://oss.oracle.com/licenses/upl.
44
[tool.poetry]
@@ -37,6 +37,7 @@ pytest-asyncio = "~0.25"
3737
pytest-cov = "~6.0"
3838
pytest-unordered = "~0.6"
3939
pre-commit = "~4.1"
40+
docutils="~0.20"
4041
Sphinx = "~7.4"
4142
sphinx-rtd-theme = "~3.0"
4243
sphinxcontrib-napoleon = "~0.7"

src/coherence/ai.py

Lines changed: 58 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525

2626
class Vector(ABC):
2727
"""
28-
Base class that represents a Vector
28+
Base class that represents a Vector.
29+
30+
**NOTE:** This requires using Coherence CE 24.09.2+ on the server side.
2931
"""
3032

3133
def __init__(self) -> None:
@@ -38,7 +40,9 @@ def __init__(self) -> None:
3840
@proxy("ai.BitVector")
3941
class BitVector(Vector):
4042
"""
41-
Class that represents a Vector of Bits
43+
Class that represents a Vector of Bits.
44+
45+
**NOTE:** This requires using Coherence CE 24.09.2+ on the server side.
4246
"""
4347

4448
def __init__(
@@ -48,11 +52,11 @@ def __init__(
4852
int_array: Optional[List[int]] = None,
4953
):
5054
"""
51-
Creates an instance of BitVector
55+
Creates an instance of BitVector.
5256
53-
:param hex_string: hexadecimal string used to create the BitVector
54-
:param byte_array: optional byte array used to create the BitVector
55-
:param int_array: optional int array used to create the BitVector
57+
:param hex_string: hexadecimal string used to create the BitVector.
58+
:param byte_array: optional byte array used to create the BitVector.
59+
:param int_array: optional int array used to create the BitVector.
5660
"""
5761
super().__init__()
5862
if hex_string is not None:
@@ -72,14 +76,16 @@ def __init__(
7276
@proxy("ai.Int8Vector")
7377
class ByteVector(Vector):
7478
"""
75-
Class that represents Vector of bytes
79+
Class that represents Vector of bytes.
80+
81+
**NOTE:** This requires using Coherence CE 24.09.2+ on the server side.
7682
"""
7783

7884
def __init__(self, byte_array: bytes):
7985
"""
80-
Creates an instance of ByteVector
86+
Creates an instance of ByteVector.
8187
82-
:param byte_array: byte array used to create a ByteVector
88+
:param byte_array: byte array used to create a ByteVector.
8389
"""
8490
super().__init__()
8591
self.array = base64.b64encode(byte_array).decode("UTF-8")
@@ -88,14 +94,16 @@ def __init__(self, byte_array: bytes):
8894
@proxy("ai.Float32Vector")
8995
class FloatVector(Vector):
9096
"""
91-
Class that represents Vector of floats
97+
Class that represents Vector of floats.
98+
99+
**NOTE:** This requires using Coherence CE 24.09.2+ on the server side.
92100
"""
93101

94102
def __init__(self, float_array: List[float]):
95103
"""
96-
Creates an instance of FloatVector
104+
Creates an instance of FloatVector.
97105
98-
:param float_array: array of floats used to create a FloatVector
106+
:param float_array: array of floats used to create a FloatVector.
99107
"""
100108
super().__init__()
101109
self.array = float_array
@@ -111,20 +119,22 @@ def __init__(self, data_version: int = 0, bin_future: Optional[Any] = None):
111119
class DocumentChunk(AbstractEvolvable):
112120
"""
113121
Class that represents a chunk of text extracted from a document.
122+
123+
**NOTE:** This requires using Coherence CE 24.09.2+ on the server side.
114124
"""
115125

116126
def __init__(
117127
self,
118128
text: str,
119-
metadata: Optional[Dict[str, Any] | OrderedDict[str, Any]] = None,
129+
metadata: Optional[Union[Dict[str, Any], OrderedDict[str, Any]]] = None,
120130
vector: Optional[Vector] = None,
121131
):
122132
"""
123-
Creates an instance of DocumentChunk class
133+
Creates an instance of DocumentChunk class.
124134
125-
:param text: the chunk of text extracted from a document
126-
:param metadata: optional document metadata
127-
:param vector: the vector associated with the document chunk
135+
:param text: the chunk of text extracted from a document.
136+
:param metadata: optional document metadata.
137+
:param vector: the vector associated with the document chunk.
128138
"""
129139
super().__init__()
130140
self.text = text
@@ -182,7 +192,9 @@ def restore(self, obj: Dict[str, Any]) -> DocumentChunk:
182192

183193
class DistanceAlgorithm(ABC):
184194
"""
185-
Base class that represents algorithm that can calculate distance to a given vector
195+
Base class that represents algorithm that can calculate distance to a given vector.
196+
197+
**NOTE:** This requires using Coherence CE 24.09.2+ on the server side.
186198
"""
187199

188200
def __init__(self) -> None:
@@ -198,6 +210,8 @@ class CosineDistance(DistanceAlgorithm):
198210
between two vectors and determines whether two vectors are pointing in
199211
roughly the same direction. It is often used to measure document similarity
200212
in text analysis.
213+
214+
**NOTE:** This requires using Coherence CE 24.09.2+ on the server side.
201215
"""
202216

203217
def __init__(self) -> None:
@@ -209,6 +223,8 @@ class InnerProductDistance(DistanceAlgorithm):
209223
"""
210224
Represents a DistanceAlgorithm that performs inner product distance
211225
calculation between two vectors.
226+
227+
**NOTE:** This requires using Coherence CE 24.09.2+ on the server side.
212228
"""
213229

214230
def __init__(self) -> None:
@@ -220,6 +236,8 @@ class L2SquaredDistance(DistanceAlgorithm):
220236
"""
221237
Represents a DistanceAlgorithm that performs an L2 squared distance
222238
calculation between two vectors.
239+
240+
**NOTE:** This requires using Coherence CE 24.09.2+ on the server side.
223241
"""
224242

225243
def __init__(self) -> None:
@@ -230,6 +248,8 @@ def __init__(self) -> None:
230248
class SimilaritySearch(EntryAggregator):
231249
"""
232250
This class represents an aggregator to execute a similarity query.
251+
252+
**NOTE:** This requires using Coherence CE 24.09.2+ on the server side.
233253
"""
234254

235255
def __init__(
@@ -247,10 +267,10 @@ def __init__(
247267
specified `vector`.
248268
249269
:param extractor_or_property: the ValueExtractor to extract the vector
250-
from the cache value
251-
:param vector: the vector to calculate similarity with
252-
:param max_results: the maximum number of results to return
253-
:param algorithm: the distance algorithm to use
270+
from the cache value.
271+
:param vector: the vector to calculate similarity with.
272+
:param max_results: the maximum number of results to return.
273+
:param algorithm: the distance algorithm to use.
254274
:param filter: filter to use to limit the set of entries to search.
255275
:param brute_force: Force brute force search, ignoring any available indexes.
256276
"""
@@ -264,7 +284,9 @@ def __init__(
264284

265285
class BaseQueryResult(ABC):
266286
"""
267-
A base class for QueryResult implementation
287+
A base class for QueryResult implementation.
288+
289+
**NOTE:** This requires using Coherence CE 24.09.2+ on the server side.
268290
"""
269291

270292
def __init__(self, result: float, key: K, value: V) -> None:
@@ -276,16 +298,18 @@ def __init__(self, result: float, key: K, value: V) -> None:
276298
@proxy("ai.results.QueryResult")
277299
class QueryResult(BaseQueryResult):
278300
"""
279-
QueryResult class
301+
QueryResult class.
302+
303+
**NOTE:** This requires using Coherence CE 24.09.2+ on the server side.
280304
"""
281305

282306
def __init__(self, result: float, key: K, value: V) -> None:
283307
"""
284-
Creates an instance of the QueryResult class
308+
Creates an instance of the QueryResult class.
285309
286-
:param result: the query result
287-
:param key: the key of the vector the result applies to
288-
:param value: the optional result value
310+
:param result: the query result.
311+
:param key: the key of the vector the result applies to.
312+
:param value: the optional result value.
289313
"""
290314
super().__init__(result, key, value)
291315

@@ -296,15 +320,17 @@ def __str__(self) -> str:
296320
@proxy("ai.index.BinaryQuantIndex")
297321
class BinaryQuantIndex(AbstractEvolvable):
298322
"""
299-
This class represents a custom index using binary quantization of vectors
323+
This class represents a custom index using binary quantization of vectors.
324+
325+
**NOTE:** This requires using Coherence CE 24.09.2+ on the server side.
300326
"""
301327

302328
def __init__(self, extractor: Union[ValueExtractor[T, E], str], over_sampling_factor: int = 3) -> None:
303329
"""
304-
Creates an instance of BinaryQuantIndex class
330+
Creates an instance of BinaryQuantIndex class.
305331
306-
:param extractor: the ValueExtractor to use to extract the Vector
307-
:param over_sampling_factor: the oversampling factor
332+
:param extractor: the ValueExtractor to use to extract the Vector.
333+
:param over_sampling_factor: the oversampling factor.
308334
"""
309335
super().__init__()
310336
self.extractor = extractor

0 commit comments

Comments
 (0)