You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
6. In CocoIndex, a *collector* collects multiple entries of data together. In this example, the `doc_embeddings` collector collects data from all `chunk`s across all `doc`s, and using the collected data to build a vector index `"doc_embeddings"`, using `Postgres`.
This handler queries the vector index `"doc_embeddings"`, and uses the same embedding model `"sentence-transformers/all-MiniLM-L6-v2"` to transform query text into vectors for similarity matching.
140
-
141
-
142
-
### Step 2.3: Define the main function
143
-
144
-
The main functionis used to interact with users and run queries using the query handler above.
126
+
We can provide an empty main functionfor now, with a `@cocoindex.main_fn()` decorator:
145
127
146
128
```python title="quickstart.py"
147
129
@cocoindex.main_fn()
148
130
def _main():
149
-
# Run queries to demonstrate the query capabilities.
150
-
while True:
151
-
try:
152
-
query = input("Enter search query (or Enter to quit): ")
@@ -171,7 +139,6 @@ The `@cocoindex.main_fn` declares a function as the main function for an indexin
171
139
* Initialize the CocoIndex librart states. Settings (e.g. database URL) are loaded from environment variables by default.
172
140
* When the CLI is invoked with `cocoindex` subcommand, `cocoindex CLI` takes over the control, which provides convenient ways to manage the index. See the next step for more details.
173
141
174
-
175
142
## Step 3: Run the indexing pipeline and queries
176
143
177
144
Specify the database URL by environment variable:
@@ -206,9 +173,129 @@ It will run for a few seconds and output the following statistics:
206
173
documents: 3 added, 0 removed, 0 updated
207
174
```
208
175
209
-
### Step 3.3: Run queries against the index
176
+
## Step 4 (optional): Run queries against the index
177
+
178
+
CocoIndex excels at transforming your data and storing it (a.k.a. indexing).
179
+
The goal of transforming your data is usually to query against it.
180
+
Once you already have your index built, you can directly access the transformed data in the target database.
181
+
CocoIndex also provides utilities for you to do this more seamlessly.
182
+
183
+
In this example, we'll use the [`psycopg` library](https://www.psycopg.org/) to connect to the database and run queries.
184
+
Please make sure it's installed:
185
+
186
+
```bash
187
+
pip install psycopg[binary,pool]
188
+
```
189
+
190
+
### Step 4.1: Extract common transformations
191
+
192
+
Between your indexing flow and the query logic, one piece of transformation is shared: compute the embedding of a text.
193
+
i.e. they should use exactly the same embedding model and parameters.
0 commit comments