Skip to content

Commit 7ad6922

Browse files
authored
Polish document for quickstart (#40)
* Update the quickstart document to separate out input files download step. * Add titles for `quickstart.py` in docs.
1 parent c7e511f commit 7ad6922

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

docs/docs/getting_started/quickstart.md

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,18 @@ This guide will help you get up and running with CocoIndex in just a few minutes
1111
* loads the data into a vector store (PG Vector)
1212

1313

14-
## Step 1: Set up the CocoIndex environment
14+
## Prerequisite: Install CocoIndex environment
1515

16-
1. Open the terminal and create a new directory for your project:
16+
We'll need to install a bunch of dependencies for this project.
1717

18-
```bash
19-
mkdir cocoindex-quickstart
20-
cd cocoindex-quickstart
21-
```
22-
23-
2. Install CocoIndex:
18+
1. Install CocoIndex:
2419

2520
```bash
2621
pip install cocoindex
2722
```
28-
29-
3. You need to setup a Postgres database with pgvector extension installed; or bring up a Postgres database using docker compose:
23+
24+
2. You can skip this step if you already have a Postgres database with pgvector extension installed.
25+
If not, the easiest way is to bring up a Postgres database using docker compose:
3026

3127
- Make sure Docker Compose is installed: [docs](https://docs.docker.com/compose/install/)
3228
- Start a Postgres SQL database for cocoindex using our docker compose config:
@@ -35,11 +31,23 @@ This guide will help you get up and running with CocoIndex in just a few minutes
3531
docker compose -f <(curl -L https://raw.githubusercontent.com/cocoindex-io/cocoindex/refs/heads/main/dev/postgres.yaml) up -d
3632
```
3733

34+
## Step 1: Prepare directory for your project
35+
36+
1. Open the terminal and create a new directory for your project:
37+
38+
```bash
39+
mkdir cocoindex-quickstart
40+
cd cocoindex-quickstart
41+
```
42+
43+
2. Prepare input files for the index. Put them in a directory, e.g. `markdown_files`.
44+
If you don't have any files at hand, you may download the example [markdown_files.zip](markdown_files.zip) and unzip it in the current directory.
45+
3846
## Step 2: Create the Python file `quickstart.py`
3947
4048
Create a new file `quickstart.py` and import the `cocoindex` library:
4149
42-
```python
50+
```python title="quickstart.py"
4351
import cocoindex
4452
```
4553
@@ -53,11 +61,12 @@ Then we'll put the following pieces into the file:
5361

5462
Starting from the indexing flow:
5563

56-
```python
64+
```python title="quickstart.py"
5765
@cocoindex.flow_def(name="TextEmbedding")
5866
def text_embedding_flow(flow_builder: cocoindex.FlowBuilder, data_scope: cocoindex.DataScope):
5967
# Add a data source to read files from a directory
60-
data_scope["documents"] = flow_builder.add_source(cocoindex.sources.LocalFile(path="markdown_files"))
68+
data_scope["documents"] = flow_builder.add_source(
69+
cocoindex.sources.LocalFile(path="markdown_files"))
6170
6271
# Add a collector for data to be exported to the vector index
6372
doc_embeddings = data_scope.add_collector()
@@ -109,7 +118,7 @@ Notes:
109118

110119
Starting from the query handler:
111120

112-
```python
121+
```python title="quickstart.py"
113122
query_handler = cocoindex.query.SimpleSemanticsQueryHandler(
114123
name="SemanticsSearch",
115124
flow=text_embedding_flow,
@@ -127,7 +136,7 @@ This handler queries the vector index `"doc_embeddings"`, and uses the same embe
127136

128137
The main function is used to interact with users and run queries using the query handler above.
129138

130-
```python
139+
```python title="quickstart.py"
131140
@cocoindex.main_fn()
132141
def _main():
133142
# Run queries to demonstrate the query capabilities.
@@ -178,9 +187,6 @@ Now we have tables needed by this CocoIndex flow.
178187
179188
### Step 3.2: Build the index
180189
181-
Before building the index, make sure input markdown files are in the `markdown_files` directory.
182-
You may download the example [markdown_files.zip](markdown_files.zip) and unzip it in the current directory.
183-
184190
Now we're ready to build the index:
185191
186192
```bash

0 commit comments

Comments
 (0)