Skip to content

Commit dc89e9f

Browse files
Initial Vector page
1 parent 07380bf commit dc89e9f

1 file changed

Lines changed: 132 additions & 0 deletions

File tree

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
= Vector Search
2+
:page-toclevels: 2
3+
:description: Vector Search from the SDK, to enable AI integration, semantic search, and the RAG framework.
4+
5+
6+
// Note to editors
7+
//
8+
// This page pulls in content from -sdk-common-
9+
// and code samples from -example-dir-
10+
//
11+
// It can be seen built at wwww.
12+
13+
14+
[abstract]
15+
{description}
16+
17+
18+
19+
20+
////
21+
* Couchbase Server 7.6 introduces Vector Search to enable AI integration, semantic search, and the RAG framework.
22+
A developer-friendly vector indexing engine exposes a vector database and search functionality.
23+
With Couchbase Vector Search, you can enable fast and highly accurate semantic search, ground LLM responses in relevant data to reduce hallucinations, and enhance or enable use cases like personalized searches in e-commerce and media & entertainment, product recommendations, fraud detection, and reverse image search.
24+
You can also enable full access to an AI ecosystem with a Langchain integration, the most popular open-source framework for LLM-driven applications.
25+
+
26+
A Vector Search database includes:
27+
+
28+
** Standard Couchbase vertical/horizontal scaling
29+
** Indexing capable of efficient Insert/Update/Removal of Items (or documents)
30+
** Storage of raw Embedding Vectors in the Data Service in the documents themselves
31+
** Querying Vector Indexes (REST and UI via a JSON object/fragment, Couchbase SDKs, and {sqlpp})
32+
** {sqlpp}/N1QL integration
33+
** Third-party framework integration: Langchain (later Llamaindex + others)
34+
** Full support for Replicas Partitions and file-based Rebalance
35+
////
36+
37+
38+
39+
////
40+
Vector queries with GSI are fast and scale up, but sometimes you may wish to use Vector with the Search Service instead.
41+
42+
Hybrid searches can combine Vector, geo-spatial search, range search, and traditional fuzzy text search for apps that...........
43+
////
44+
45+
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].
48+
49+
50+
== Prerequisites
51+
52+
Couchbase Server 7.6.0
53+
(7.6.2 for base64-encoded vectors) -- or recent Capella instance.
54+
55+
== Examples
56+
57+
=== Single vector query
58+
59+
In this first example we are performing a single vector query:
60+
61+
[source,java]
62+
----
63+
include::devguide:example$java/Search.java[tag=vector1,indent=0]
64+
----
65+
66+
Let's break this down.
67+
We create a `SearchRequest`, which can contain a traditional FTS query `SearchQuery` and/or the new `VectorSearch`.
68+
Here we are just using the latter.
69+
70+
The `VectorSearch` allows us to perform one or more `VectorQuery` s.
71+
72+
The `VectorQuery` itself takes the name of the document field that contains embedded vectors ("vector_field" here), plus actual vector query in the form of a `float[]`.
73+
74+
(Note that Couchbase itself is not involved in generating the vectors, and these will come from an external source such as an embeddings API.)
75+
76+
Finally we execute the `SearchRequest` against the FTS index "travel-sample-index", which has previously been setup to vector index the "vector_field" field.
77+
78+
This happens to be a scoped index so we are using `scope.search()`.
79+
If it was a global index we would use `cluster.search()` instead - see <<Scoped vs Global Indexes>>.
80+
81+
It returns the same `SearchResult` detailed earlier.
82+
83+
=== Multiple vector queries
84+
You can run multiple vector queries together:
85+
86+
[source,java]
87+
----
88+
include::devguide:example$java/Search.java[tag=vector3,indent=0]
89+
----
90+
91+
How the results are combined (ANDed or ORed) can be controlled with `vectorSearchOptions().vectorQueryCombination()`.
92+
93+
=== Combining FTS and vector queries
94+
95+
You can combine a traditional FTS query with vector queries:
96+
97+
[source,java]
98+
----
99+
include::devguide:example$java/Search.java[tag=vector2,indent=0]
100+
----
101+
102+
How the results are combined (ANDed or ORed) can be controlled with `vectorSearchOptions().vectorQueryCombination()`.
103+
104+
105+
106+
////
107+
=== FTS queries
108+
And note that traditional FTS queries, without vector search, are also supported with the new `cluster.search()` / `scope.search()` APIs:
109+
[source,java]
110+
----
111+
include::devguide:example$java/Search.java[tag=vector4,indent=0]
112+
----
113+
114+
////
115+
116+
117+
118+
119+
120+
// integrations??
121+
122+
123+
124+
125+
126+
== Further Reading
127+
128+
* xref:server:vector-search:vector-search.adoc[Vector Search for AI Apps docs (self-managed Couchbase Server)]
129+
* xref:cloud::vector-search:vector-search.adoc[Vector Search for AI Apps docs (Capella DBaaS)]
130+
* Vector Search in the https://docs.couchbase.com/sdk-api/couchbase-scala-client/com/couchbase/client/scala/search/vector/index.html[Scala API reference].
131+
132+
// https://developer.couchbase.com/tutorial-python-langchain-pdf-chat

0 commit comments

Comments
 (0)