Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOCSP-42282: java avs type support #170

Merged
merged 1 commit into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 deletions examples/src/test/kotlin/SearchIndexesTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import kotlin.test.assertFalse
// "CONNECTION_URI_PLACEHOLDER": "\"<connection string>\""
// }
// }

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class SearchIndexesTest {

Expand All @@ -42,11 +43,11 @@ class SearchIndexesTest {
@Test
fun singleSearchIndexTest() = runBlocking {
// :snippet-start: single-search-index-create
val index = Document(
val searchIdx = Document(
"mappings",
Document("dynamic", true)
)
val resultCreateIndex = moviesCollection.createSearchIndex("myIndex", index)
val resultCreateIndex = moviesCollection.createSearchIndex("myIndex", searchIdx)
// :snippet-end:
println("Index created: $resultCreateIndex")
assertEquals("myIndex", resultCreateIndex)
Expand All @@ -56,24 +57,33 @@ class SearchIndexesTest {
@Test
fun multipleSearchIndexTest() = runBlocking {
// :snippet-start: multi-search-index-create
val indexOne = SearchIndexModel(
"myIndex1",
val searchIdxMdl = SearchIndexModel(
"searchIdx",
Document("analyzer", "lucene.standard").append(
"mappings", Document("dynamic", true)
)
),
SearchIndexType.search()
)

val indexTwo = SearchIndexModel(
"myIndex2",
Document("analyzer", "lucene.simple").append(
"mappings", Document("dynamic", true)
)
val vectorSearchIdxMdl = SearchIndexModel(
"vsIdx",
Document(
"fields",
listOf(
Document("type", "vector")
.append("path", "embeddings")
.append("numDimensions", 1536)
.append("similarity", "dotProduct")
)
),
SearchIndexType.vectorSearch()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: this is causing the compile to fail because this is a new class in v5.2.

)

val resultCreateIndexes = moviesCollection
.createSearchIndexes(listOf(indexOne, indexTwo))
val resultCreateIndexes = moviesCollection.createSearchIndexes(
listOf(searchIdxMdl, vectorSearchIdxMdl)
)
// :snippet-end:
assertEquals(listOf("myIndex1", "myIndex2"), resultCreateIndexes.toList())
assertEquals(listOf("searchIdx", "vsIdx"), resultCreateIndexes.toList())
}

@Ignore
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
val indexOne = SearchIndexModel(
"myIndex1",
val searchIdxMdl = SearchIndexModel(
"searchIdx",
Document("analyzer", "lucene.standard").append(
"mappings", Document("dynamic", true)
)
),
SearchIndexType.search()
)

val indexTwo = SearchIndexModel(
"myIndex2",
Document("analyzer", "lucene.simple").append(
"mappings", Document("dynamic", true)
)
val vectorSearchIdxMdl = SearchIndexModel(
"vsIdx",
Document(
"fields",
listOf(
Document("type", "vector")
.append("path", "embeddings")
.append("numDimensions", 1536)
.append("similarity", "dotProduct")
)
),
SearchIndexType.vectorSearch()
)

val resultCreateIndexes = moviesCollection
.createSearchIndexes(listOf(indexOne, indexTwo))
val resultCreateIndexes = moviesCollection.createSearchIndexes(
listOf(searchIdxMdl, vectorSearchIdxMdl)
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
val index = Document(
val searchIdx = Document(
"mappings",
Document("dynamic", true)
)
val resultCreateIndex = moviesCollection.createSearchIndex("myIndex", index)
val resultCreateIndex = moviesCollection.createSearchIndex("myIndex", searchIdx)
30 changes: 18 additions & 12 deletions source/fundamentals/indexes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -223,19 +223,23 @@ see :manual:`Multikey Indexes </core/index-multikey>` in the Server manual.

.. _kotlin-search-indexes:

Atlas Search Indexes
~~~~~~~~~~~~~~~~~~~~
Atlas Search and Vector Search Indexes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

You can programmatically manage your Atlas Search and Atlas Vector
Search indexes by using the {+driver-short+}.

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

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

You can call the following methods on a collection to manage your Atlas Search
indexes:
You can call the following methods on a collection to manage your Atlas
Search and Vector Search indexes:

- ``createSearchIndex()``
- ``createSearchIndexes()``
Expand All @@ -258,14 +262,16 @@ Create a Search Index

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>`__
and `createSearchIndexes() <{+api+}/apidocs/mongodb-driver-kotlin-coroutine/mongodb-driver-kotlin-coroutine/com.mongodb.kotlin.client.coroutine/-mongo-collection/create-search-indexes.html>`__
methods to create Atlas Search indexes on a collection.
methods to create Atlas Search and Vector Search indexes on a
collection.

The following code example shows how to create a single index:
The following code example shows how to create an Atlas Search index:

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

The following code example shows how to create multiple indexes:
The following code example shows how to create Search and
Vector Search indexes in one call:

.. literalinclude:: /examples/generated/SearchIndexesTest.snippet.multi-search-index-create.kt
:language: kotlin
Expand Down
14 changes: 14 additions & 0 deletions source/whats-new.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ What's New

Learn what's new in:

* :ref:`Version 5.2 <kotlin-coroutine-version-5.2>`
* :ref:`Version 5.1.3 <kotlin-coroutine-version-5.1.3>`
* :ref:`Version 5.1.2 <kotlin-coroutine-version-5.1.2>`
* :ref:`Version 5.1.1 <kotlin-coroutine-version-5.1.1>`
Expand All @@ -20,6 +21,19 @@ Learn what's new in:
* :ref:`Version 4.11 <version-4.11>`
* :ref:`Version 4.10 <version-4.10>`

.. _kotlin-coroutine-version-5.2:

What's New in 5.2
-----------------

New features of the 4.11 driver release include:

.. sharedinclude:: dbx/jvm/v5.2-wn-items.rst

.. replacement:: avs-index-link

:ref:`kotlin-search-indexes` in the Indexes guide

.. _kotlin-coroutine-version-5.1.3:

What's New in 5.1.3
Expand Down
Loading