Skip to content

Commit 6497bb2

Browse files
improvements
1 parent daa71b0 commit 6497bb2

2 files changed

Lines changed: 127 additions & 50 deletions

File tree

modules/howtos/pages/encrypting-using-sdk.adoc

Lines changed: 5 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -179,47 +179,10 @@ include::devguide:example$java/EncryptingUsingSDK.java[tag=encrypting_using_sdk_
179179
[#migration-from-sdk2]
180180
== Migrating from SDK 2
181181

182-
WARNING: SDK 2 cannot read fields encrypted by SDK 3.
182+
SDK 2.x reached end-of-life long ago,
183+
but should you have fields encrypted by SDK 2.x, and the need to read them from SDK 3.x,
184+
then follow the steps in the https://docs-archive.couchbase.com/java-sdk/3.4/howtos/encrypting-using-sdk.html#migration-from-sdk2[archived documents].
183185

184-
It's inadvisable to have both the old and new versions of your application active at the same time.
185-
The simplest way to migrate is to do an offline upgrade during a scheduled a maintenance window.
186-
For an online upgrade without downtime, consider a https://en.wikipedia.org/wiki/Blue-green_deployment[blue-green deployment^].
187186

188-
SDK 3 requires additional configuration to read fields encrypted by SDK 2.
189-
The rest of this section describes how to configure Field-Level Encryption in SDK 3 for backwards compatibility with SDK 2.
190-
191-
[#configure-field-name-prefix]
192-
=== Changing the field name prefix
193-
194-
In SDK 2, the default prefix for encrypted field names was `\__crypt_`.
195-
This caused problems for Couchbase Sync Gateway, which does not like field names to begin with an underscore.
196-
In SDK 3, the default prefix is `encrypted$`.
197-
198-
For compatibility with SDK 2, you can configure the `CryptoManager` to use the old `\__crypt_` prefix:
199-
200-
[source,java]
201-
----
202-
include::devguide:example$java/EncryptingUsingSDK.java[tag=legacy_field_name_prefix,indent=0]
203-
----
204-
205-
Alternatively, you can https://forums.couchbase.com/t/replacing-field-name-prefix/28786[rename the existing fields] using a {sqlpp_url}[{sqlpp} (formerly N1QL)] statement.
206-
207-
WARNING: In SDK 2, only top-level fields could be encrypted.
208-
SDK 3 allows encrypting fields at any depth.
209-
If you decide to rename the existing fields, make sure to do so _before_ writing any encrypted fields below the top level, otherwise it may be difficult to rename the nested fields using a generic {sqlpp} statement.
210-
211-
212-
[#configure-legacy-decrypters]
213-
=== Enabling decrypters for legacy algorithms
214-
215-
The encryption algorithms used by SDK 2 are deprecated, and are no longer used for encrypting new data.
216-
To enable decrypting fields written by SDK 2, register the legacy decrypters when configuring the `CryptoManager`:
217-
218-
[source,java]
219-
----
220-
include::devguide:example$java/EncryptingUsingSDK.java[tag=legacy_decrypters,indent=0]
221-
----
222-
223-
NOTE: The legacy decrypters require a mapping function.
224-
For AES, this function accepts an encryption key name and returns the corresponding signing key name.
225-
For RSA, this function accepts a public key name and returns the corresponding private key name.
187+
IMPORTANT: The encryption algorithms used by SDK 2 are deprecated, and are no longer used for encrypting new data.
188+
Do not rely on the security of outdated encryption algorithms.

modules/howtos/pages/vector-searching-with-sdk.adoc

Lines changed: 122 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,125 @@ Hybrid searches can combine Vector, geo-spatial search, range search, and tradit
4343
////
4444

4545

46-
This is currently implemented using xref:full-text-searching-with-sdk.adoc[Search Indexes], and can even be combined with traditional full text search queries.
47-
Vector embeddings can be an array of floats or a xref:server:vector-search:run-vector-search-ui.adoc#base64[base64 encoded string].
46+
Vector Search has been available in Couchbase Capella Operational and self-managed Server since version 7.6, using the COuchbase Server Search Service.
47+
Version 8.0 introduces vector query using Global Secondary Indexes (GSI), the query index --
48+
using either a fast Hyperscale index, or a composite index to combine scala queries with semantic search.
49+
50+
For fast and scalable vector query, use one of the GSI choices -- detailed in the next section.
51+
If you don't require the scale of vector query with GSI, or need combined searches, then consider {#vector-search-with-the-search-service}.
52+
53+
54+
55+
== Vector Search With the Query Service and GSI
56+
57+
From the SDK, a vector query using GSI is the same as any other query.
58+
However, you will need to build one or more indexes.
59+
60+
=== Prerequisites
61+
62+
Couchbase Server 8.0.0 or newer -- or a recent Capella instance.
63+
64+
Your chosen xref:server:vector-index:use-vector-indexes.adoc[vector index] --
65+
hyperscale or composite.
66+
67+
68+
=== Examples
69+
70+
These examples simply take the {sqlpp} queries shown in the
71+
xref:server:vector-index:composite-vector-index.html#examples[Composite Index] and
72+
xref:server:vector-index:hyperscale-vector-index.html#query-example[Hyperscale Index] example pages,
73+
wrapped inside the {name-sdk} Query API.
74+
75+
76+
77+
78+
79+
.With Composite Vector Index
80+
[source,java]
81+
----
82+
package com.couchbase.client.java.examples.query;
83+
84+
import com.couchbase.client.java.Bucket;
85+
import com.couchbase.client.java.Cluster;
86+
import com.couchbase.client.java.query.QueryResult;
87+
88+
public class SimpleQueryExample {
4889
90+
public static void main(String... args) {
91+
Cluster cluster = Cluster.connect("127.0.0.1", "Administrator", "password");
92+
Bucket bucket = cluster.bucket("travel-sample");
4993
50-
== Prerequisites
94+
QueryResult result = cluster.query(SELECT RAW OBJECT_PUT(d, "embedding_vector_dot",ARRAY_CONCAT(d.embedding_vector_dot[0:4], ["..."])) FROM `vector-sample`.`color`.`rgb` AS d USE KEYS ["#FFEFD5"]);
95+
System.out.println(result.rowsAsObject());
96+
}
97+
98+
}
99+
----
100+
101+
102+
103+
104+
105+
.Hyperscale Index Example
106+
[source,java]
107+
----
108+
import static com.couchbase.client.java.query.QueryOptions.queryOptions;
109+
110+
import com.couchbase.client.core.error.CouchbaseException;
111+
import com.couchbase.client.java.*;
112+
import com.couchbase.client.java.json.*;
113+
import com.couchbase.client.java.query.*;
114+
115+
// tag::vector-hyperscale[]
116+
public class SimpleQueryCloud {
117+
// Update these variables to point to your Couchbase Capella instance and credentials.
118+
static String connectionString = "couchbases://cb.<your-endpoint-here>.cloud.couchbase.com";
119+
static String username = "Administrator";
120+
static String password = "password";
121+
122+
public static void main(String[] args) throws Exception {
123+
Cluster cluster = Cluster.connect(
124+
connectionString,
125+
ClusterOptions.clusterOptions(username, password).environment(env -> {
126+
env.applyProfile("wan-development");
127+
})
128+
);
129+
130+
{
131+
try {
132+
final QueryResult result = cluster.query("SELECT d.id, d.question, d.wanted_similar_color_from_search, ARRAY_CONCAT(d.couchbase_search_query.knn[0].vector[0:4], ["..."]) AS vector FROM `vector-sample`.`color`.`rgb-questions` AS d WHERE d.id = "#87CEEB",
133+
queryOptions().metrics(true));
134+
135+
for (JsonObject row : result.rowsAsObject()) {
136+
System.out.println(row);
137+
}
138+
139+
System.out.println("Reported execution time: " + result.metaData().metrics().get().executionTime());
140+
141+
} catch (CouchbaseException ex) {
142+
ex.printStackTrace();
143+
}
144+
}
145+
}
146+
}
147+
// end::vector-hyperscale[]
148+
----
149+
150+
151+
152+
== Vector Search With the Search Service
153+
154+
Vector search is also implemented using xref:full-text-searching-with-sdk.adoc[Search Indexes], and can be combined with traditional full text search queries.
155+
Vector embeddings can be an array of floats or a xref:server:vector-search:run-vector-search-ui.adoc#base64[base64 encoded string].
156+
157+
=== Prerequisites
51158

52159
Couchbase Server 7.6.0
53160
(7.6.2 for base64-encoded vectors) -- or recent Capella instance.
54161

55-
== Examples
162+
=== Examples
56163

57-
=== Single vector query
164+
==== Single vector query
58165

59166
In this first example we are performing a single vector query:
60167

@@ -80,7 +187,7 @@ If it was a global index we would use `cluster.search()` instead - see <<Scoped
80187

81188
It returns the same `SearchResult` detailed earlier.
82189

83-
=== Multiple vector queries
190+
==== Multiple vector queries
84191
You can run multiple vector queries together:
85192

86193
[source,java]
@@ -90,7 +197,7 @@ include::devguide:example$java/Search.java[tag=vector3,indent=0]
90197

91198
How the results are combined (ANDed or ORed) can be controlled with `vectorSearchOptions().vectorQueryCombination()`.
92199

93-
=== Combining FTS and vector queries
200+
==== Combining FTS and vector queries
94201

95202
You can combine a traditional FTS query with vector queries:
96203

@@ -104,7 +211,7 @@ How the results are combined (ANDed or ORed) can be controlled with `vectorSearc
104211

105212

106213
////
107-
=== FTS queries
214+
==== FTS queries
108215
And note that traditional FTS queries, without vector search, are also supported with the new `cluster.search()` / `scope.search()` APIs:
109216
[source,java]
110217
----
@@ -125,6 +232,13 @@ include::devguide:example$java/Search.java[tag=vector4,indent=0]
125232

126233
== Further Reading
127234

235+
236+
=== Vector Query
237+
238+
239+
240+
=== Vector Search
241+
128242
* xref:server:vector-search:vector-search.adoc[Vector Search for AI Apps docs (self-managed Couchbase Server)]
129243
* xref:cloud::vector-search:vector-search.adoc[Vector Search for AI Apps docs (Capella DBaaS)]
130244
* Vector Search in the https://docs.couchbase.com/sdk-api/couchbase-java-client/com/couchbase/client/java/search/vector/VectorSearch.html[Java API reference].

0 commit comments

Comments
 (0)