Skip to content

Commit b05e390

Browse files
authored
DOCSP-42282: java avs type support (#170)
1 parent 27a5c2a commit b05e390

File tree

5 files changed

+76
-37
lines changed

5 files changed

+76
-37
lines changed

examples/src/test/kotlin/SearchIndexesTest.kt

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import kotlin.test.assertFalse
1717
// "CONNECTION_URI_PLACEHOLDER": "\"<connection string>\""
1818
// }
1919
// }
20+
2021
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
2122
class SearchIndexesTest {
2223

@@ -42,11 +43,11 @@ class SearchIndexesTest {
4243
@Test
4344
fun singleSearchIndexTest() = runBlocking {
4445
// :snippet-start: single-search-index-create
45-
val index = Document(
46+
val searchIdx = Document(
4647
"mappings",
4748
Document("dynamic", true)
4849
)
49-
val resultCreateIndex = moviesCollection.createSearchIndex("myIndex", index)
50+
val resultCreateIndex = moviesCollection.createSearchIndex("myIndex", searchIdx)
5051
// :snippet-end:
5152
println("Index created: $resultCreateIndex")
5253
assertEquals("myIndex", resultCreateIndex)
@@ -56,24 +57,33 @@ class SearchIndexesTest {
5657
@Test
5758
fun multipleSearchIndexTest() = runBlocking {
5859
// :snippet-start: multi-search-index-create
59-
val indexOne = SearchIndexModel(
60-
"myIndex1",
60+
val searchIdxMdl = SearchIndexModel(
61+
"searchIdx",
6162
Document("analyzer", "lucene.standard").append(
6263
"mappings", Document("dynamic", true)
63-
)
64+
),
65+
SearchIndexType.search()
6466
)
6567

66-
val indexTwo = SearchIndexModel(
67-
"myIndex2",
68-
Document("analyzer", "lucene.simple").append(
69-
"mappings", Document("dynamic", true)
70-
)
68+
val vectorSearchIdxMdl = SearchIndexModel(
69+
"vsIdx",
70+
Document(
71+
"fields",
72+
listOf(
73+
Document("type", "vector")
74+
.append("path", "embeddings")
75+
.append("numDimensions", 1536)
76+
.append("similarity", "dotProduct")
77+
)
78+
),
79+
SearchIndexType.vectorSearch()
7180
)
7281

73-
val resultCreateIndexes = moviesCollection
74-
.createSearchIndexes(listOf(indexOne, indexTwo))
82+
val resultCreateIndexes = moviesCollection.createSearchIndexes(
83+
listOf(searchIdxMdl, vectorSearchIdxMdl)
84+
)
7585
// :snippet-end:
76-
assertEquals(listOf("myIndex1", "myIndex2"), resultCreateIndexes.toList())
86+
assertEquals(listOf("searchIdx", "vsIdx"), resultCreateIndexes.toList())
7787
}
7888

7989
@Ignore
Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
1-
val indexOne = SearchIndexModel(
2-
"myIndex1",
1+
val searchIdxMdl = SearchIndexModel(
2+
"searchIdx",
33
Document("analyzer", "lucene.standard").append(
44
"mappings", Document("dynamic", true)
5-
)
5+
),
6+
SearchIndexType.search()
67
)
78

8-
val indexTwo = SearchIndexModel(
9-
"myIndex2",
10-
Document("analyzer", "lucene.simple").append(
11-
"mappings", Document("dynamic", true)
12-
)
9+
val vectorSearchIdxMdl = SearchIndexModel(
10+
"vsIdx",
11+
Document(
12+
"fields",
13+
listOf(
14+
Document("type", "vector")
15+
.append("path", "embeddings")
16+
.append("numDimensions", 1536)
17+
.append("similarity", "dotProduct")
18+
)
19+
),
20+
SearchIndexType.vectorSearch()
1321
)
1422

15-
val resultCreateIndexes = moviesCollection
16-
.createSearchIndexes(listOf(indexOne, indexTwo))
23+
val resultCreateIndexes = moviesCollection.createSearchIndexes(
24+
listOf(searchIdxMdl, vectorSearchIdxMdl)
25+
)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
val index = Document(
1+
val searchIdx = Document(
22
"mappings",
33
Document("dynamic", true)
44
)
5-
val resultCreateIndex = moviesCollection.createSearchIndex("myIndex", index)
5+
val resultCreateIndex = moviesCollection.createSearchIndex("myIndex", searchIdx)

source/fundamentals/indexes.txt

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -223,19 +223,23 @@ see :manual:`Multikey Indexes </core/index-multikey>` in the Server manual.
223223

224224
.. _kotlin-search-indexes:
225225

226-
Atlas Search Indexes
227-
~~~~~~~~~~~~~~~~~~~~
226+
Atlas Search and Vector Search Indexes
227+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
228+
229+
You can programmatically manage your Atlas Search and Atlas Vector
230+
Search indexes by using the {+driver-short+}.
228231

229232
The Atlas Search feature enables you to perform full-text searches on
230-
collections hosted on MongoDB Atlas. The indexes specify how you can
231-
perform full-text searches on specific fields.
233+
collections hosted on MongoDB Atlas. To learn more about MongoDB Atlas
234+
Search, see the :atlas:`Atlas Search Indexes
235+
</atlas-search/atlas-search-overview/#fts-indexes>` documentation.
232236

233-
To learn more about MongoDB Atlas Search, see the
234-
:atlas:`Atlas Search Indexes </atlas-search/atlas-search-overview/#fts-indexes>`
235-
documentation.
237+
Atlas Vector Search enables you to perform semantic searches on vector
238+
embeddings stored in MongoDB Atlas. To learn more about Atlas Vector Search, see the
239+
:ref:`kotlin-atlas-vector-search` section in the Aggregates Builder guide.
236240

237-
You can call the following methods on a collection to manage your Atlas Search
238-
indexes:
241+
You can call the following methods on a collection to manage your Atlas
242+
Search and Vector Search indexes:
239243

240244
- ``createSearchIndex()``
241245
- ``createSearchIndexes()``
@@ -258,14 +262,16 @@ Create a Search Index
258262

259263
You can use the `createSearchIndex() <{+api+}/apidocs/mongodb-driver-kotlin-coroutine/mongodb-driver-kotlin-coroutine/com.mongodb.kotlin.client.coroutine/-mongo-collection/create-search-index.html>`__
260264
and `createSearchIndexes() <{+api+}/apidocs/mongodb-driver-kotlin-coroutine/mongodb-driver-kotlin-coroutine/com.mongodb.kotlin.client.coroutine/-mongo-collection/create-search-indexes.html>`__
261-
methods to create Atlas Search indexes on a collection.
265+
methods to create Atlas Search and Vector Search indexes on a
266+
collection.
262267

263-
The following code example shows how to create a single index:
268+
The following code example shows how to create an Atlas Search index:
264269

265270
.. literalinclude:: /examples/generated/SearchIndexesTest.snippet.single-search-index-create.kt
266271
:language: kotlin
267272

268-
The following code example shows how to create multiple indexes:
273+
The following code example shows how to create Search and
274+
Vector Search indexes in one call:
269275

270276
.. literalinclude:: /examples/generated/SearchIndexesTest.snippet.multi-search-index-create.kt
271277
:language: kotlin

source/whats-new.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ What's New
1212

1313
Learn what's new in:
1414

15+
* :ref:`Version 5.2 <kotlin-coroutine-version-5.2>`
1516
* :ref:`Version 5.1.3 <kotlin-coroutine-version-5.1.3>`
1617
* :ref:`Version 5.1.2 <kotlin-coroutine-version-5.1.2>`
1718
* :ref:`Version 5.1.1 <kotlin-coroutine-version-5.1.1>`
@@ -20,6 +21,19 @@ Learn what's new in:
2021
* :ref:`Version 4.11 <version-4.11>`
2122
* :ref:`Version 4.10 <version-4.10>`
2223

24+
.. _kotlin-coroutine-version-5.2:
25+
26+
What's New in 5.2
27+
-----------------
28+
29+
New features of the 4.11 driver release include:
30+
31+
.. sharedinclude:: dbx/jvm/v5.2-wn-items.rst
32+
33+
.. replacement:: avs-index-link
34+
35+
:ref:`kotlin-search-indexes` in the Indexes guide
36+
2337
.. _kotlin-coroutine-version-5.1.3:
2438

2539
What's New in 5.1.3

0 commit comments

Comments
 (0)