Skip to content

Commit d8f1d4e

Browse files
committed
Generated markdown tutorials from Jupyter Notebooks
Generated from: couchbase-examples/vector-search-cookbook
1 parent 2f4c717 commit d8f1d4e

File tree

1 file changed

+60
-36
lines changed
  • tutorial/markdown/generated/vector-search-cookbook

1 file changed

+60
-36
lines changed

tutorial/markdown/generated/vector-search-cookbook/mistralai.md

Lines changed: 60 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ short_title: Mistral AI with Couchbase Vector Search
66
description:
77
- Learn how to generate embeddings using Mistral AI and store them in Couchbase.
88
- This tutorial demonstrates how to use Couchbase's vector search capabilities with Mistral AI embeddings.
9-
- You'll understand how to perform vector searches to find relevant documents based on similarity.
9+
- You'll understand how to perform vector search to find relevant documents based on similarity.
1010
content_type: tutorial
1111
filter: sdk
1212
technology:
@@ -25,7 +25,8 @@ length: 30 Mins
2525

2626
[View Source](https://github.com/couchbase-examples/vector-search-cookbook/tree/main/mistralai/mistralai.ipynb)
2727

28-
# Couchbase and Mistral AI integration example notebook
28+
# Introduction
29+
2930
Couchbase is a NoSQL distributed document database (JSON) with many of the best features of a relational DBMS: SQL, distributed ACID transactions, and much more. [Couchbase Capella™](https://cloud.couchbase.com/sign-up) is the easiest way to get started, but you can also download and run [Couchbase Server](http://couchbase.com/downloads) on-premises.
3031

3132
Mistral AI is a research lab building the best open source models in the world. La Plateforme enables developers and enterprises to build new products and applications, powered by Mistral’s open source and commercial LLMs.
@@ -41,37 +42,39 @@ The [Mistral AI APIs](https://console.mistral.ai/) empower LLM applications via:
4142
- [Guardrailing](https://docs.mistral.ai/capabilities/guardrailing/), enables developers to enforce policies at the system level of Mistral models
4243

4344

44-
# Prerequisites
45-
## Python3 and PIP
46-
Please consult with [pip installation documentation](https://pip.pypa.io/en/stable/installation/) to install pip.
47-
## Dependency Libraries
48-
This tutorial depends on `couchbase` and `mistralai` libraries. Run this shell command to install them:
49-
```shell
50-
pip install -r requirements.txt
51-
```
52-
## Couchbase Cluster
53-
In order to run this tutorial, you will need access to a collection on a Couchbase Cluster either through Couchbase Capella or by running it locally. Please provide your couchbase cluster connection information by running the code block below:
45+
# How to run this tutorial
5446

47+
This tutorial is available as a Jupyter Notebook (`.ipynb` file) that you can run interactively. You can access the original notebook [here](https://github.com/couchbase-examples/vector-search-cookbook/blob/main/mistralai/mistralai.ipynb).
5548

56-
```python
57-
import getpass
58-
couchbase_cluster_url = input("Cluster URL:")
59-
couchbase_username = input("Couchbase username:")
60-
couchbase_password = getpass.getpass("Couchbase password:")
61-
couchbase_bucket = input("Couchbase bucket:")
62-
couchbase_scope = input("Couchbase scope:")
63-
couchbase_collection = input("Couchbase collection:")
64-
```
49+
You can either download the notebook file and run it on [Google Colab](https://colab.research.google.com/) or run it on your system by setting up the Python environment.
6550

66-
Cluster URL: localhost
67-
Couchbase username: Administrator
68-
Couchbase password: ········
69-
Couchbase bucket: mistralai
70-
Couchbase scope: _default
71-
Couchbase collection: mistralai
51+
# Before you start
52+
53+
## Get Credentials for Mistral AI
54+
55+
Please follow the [instructions](https://console.mistral.ai/api-keys/) to generate the Mistral AI credentials.
56+
57+
## Create and Deploy Your Free Tier Operational cluster on Capella
58+
59+
To get started with Couchbase Capella, create an account and use it to deploy a forever free tier operational cluster. This account provides you with a environment where you can explore and learn about Capella with no time constraint.
60+
61+
To know more, please follow the [instructions](https://docs.couchbase.com/cloud/get-started/create-account.html).
62+
63+
### Couchbase Capella Configuration
64+
65+
When running Couchbase using [Capella](https://cloud.couchbase.com/sign-in), the following prerequisites need to be met.
66+
67+
* Create the [database credentials](https://docs.couchbase.com/cloud/clusters/manage-database-users.html) to access the travel-sample bucket (Read and Write) used in the application.
68+
* [Allow access](https://docs.couchbase.com/cloud/clusters/allow-ip-address.html) to the Cluster from the IP on which the application is running.
7269

70+
# Install necessary libraries
7371

74-
## Imports
72+
73+
```python
74+
!pip install couchbase mistralai
75+
```
76+
77+
# Imports
7578

7679

7780
```python
@@ -88,7 +91,29 @@ from couchbase.vector_search import VectorQuery, VectorSearch
8891
import uuid
8992
```
9093

91-
## Couchbase Connection
94+
# Prerequisites
95+
96+
97+
98+
```python
99+
import getpass
100+
couchbase_cluster_url = input("Cluster URL:")
101+
couchbase_username = input("Couchbase username:")
102+
couchbase_password = getpass.getpass("Couchbase password:")
103+
couchbase_bucket = input("Couchbase bucket:")
104+
couchbase_scope = input("Couchbase scope:")
105+
couchbase_collection = input("Couchbase collection:")
106+
```
107+
108+
Cluster URL: localhost
109+
Couchbase username: Administrator
110+
Couchbase password: ········
111+
Couchbase bucket: mistralai
112+
Couchbase scope: _default
113+
Couchbase collection: mistralai
114+
115+
116+
# Couchbase Connection
92117

93118

94119
```python
@@ -108,25 +133,24 @@ scope = bucket.scope(couchbase_scope)
108133
collection = scope.collection(couchbase_collection)
109134
```
110135

111-
## Creating Couchbase Vector Search Index
112-
In order to store Mistral embeddings onto a Couchbase Cluster, a vector search index needs to be created first. We included a sample index definition that will work with this tutorial in the `fts_index.json` file. The definition can be used to create a vector index using Couchbase server web console, on more information on vector indexes, please read [Create a Vector Search Index with the Server Web Console](https://docs.couchbase.com/server/current/vector-search/create-vector-search-index-ui.html).
136+
# Creating Couchbase Vector Search Index
137+
In order to store Mistral embeddings onto a Couchbase Cluster, a vector search index needs to be created first. We included a sample index definition that will work with this tutorial in the `mistralai_index.json` file. The definition can be used to create a vector index using Couchbase server web console, on more information on vector indexes, please read [Create a Vector Search Index with the Server Web Console](https://docs.couchbase.com/server/current/vector-search/create-vector-search-index-ui.html).
113138

114139

115140
```python
116141
search_index_name = couchbase_bucket + "._default.vector_test"
117142
search_index = cluster.search_indexes().get_index(search_index_name)
118143
```
119144

120-
## Mistral Connection
121-
A Mistral API key needs to be obtained and configured in the code before using the Mistral API. A trial key can be obtained for free in MistralAI personal cabinet. For more detailed instructions on obtaining a key please consult with [Mistral documentation site](https://docs.mistral.ai/).
145+
# Mistral Connection
122146

123147

124148
```python
125149
MISTRAL_API_KEY = getpass.getpass("Mistral API Key:")
126150
mistral_client = Mistral(api_key=MISTRAL_API_KEY)
127151
```
128152

129-
## Embedding Documents
153+
# Embedding Documents
130154
Mistral client can be used to generate vector embeddings for given text fragments. These embeddings represent the sentiment of corresponding fragments and can be stored in Couchbase for further retrieval. A custom embedding text can also be added into the embedding texts array by running this code block:
131155

132156

@@ -156,7 +180,7 @@ EmbeddingResponse(
156180
)
157181
```
158182

159-
## Storing Embeddings in Couchbase
183+
# Storing Embeddings in Couchbase
160184
Each embedding needs to be stored as a couchbase document. According to provided search index, embedding vector values need to be stored in the `vector` field. The original text of the embedding can be stored in the same document:
161185

162186

@@ -170,7 +194,7 @@ for i in range(0, len(texts)):
170194
collection.upsert(doc["id"], doc)
171195
```
172196

173-
## Searching For Embeddings
197+
# Searching For Embeddings
174198
Stored in Couchbase embeddings later can be searched using the vector index to, for example, find text fragments that would be the most relevant to some user-entered prompt:
175199

176200

0 commit comments

Comments
 (0)