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
Copy file name to clipboardExpand all lines: README.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -137,7 +137,7 @@ It defines an index flow like this:
137
137
|[Docs to Knowledge Graph](examples/docs_to_knowledge_graph)| Extract relationships from Markdown documents and build a knowledge graph |
138
138
|[Embeddings to Qdrant](examples/text_embedding_qdrant)| Index documents in a Qdrant collection for semantic search |
139
139
|[FastAPI Server with Docker](examples/fastapi_server_docker)| Run the semantic search server in a Dockerized FastAPI setup |
140
-
|[Product_Taxonomy_Knowledge_Graph](examples/product_taxonomy_knowledge_graph)| Build knowledge graph for product recommendations |
140
+
|[Product Recommendation](examples/product_recommendation)| Build real-time product recommendations with LLM and graph database|
141
141
|[Image Search with Vision API](examples/image_search_example)| Generates detailed captions for images using a vision model, embeds them, enables live-updating semantic search via FastAPI and served on a React frontend|
@@ -54,11 +54,7 @@ Create a new file `quickstart.py` and import the `cocoindex` library:
54
54
import cocoindex
55
55
```
56
56
57
-
Then we'll put the following pieces into the file:
58
-
59
-
* Define an indexing flow, which specifies a data flow to transform data from specified data source into a vector index.
60
-
* Define a query handler, which can be used to query the vector index.
61
-
* A main function, to interact with users and run queries using the query handler above.
57
+
Then we'll create the indexing flow.
62
58
63
59
### Step 2.1: Define the indexing flow
64
60
@@ -121,46 +117,14 @@ Notes:
121
117
122
118
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
120
+
### Step 2.2: Define the main function
143
121
144
-
The main functionis used to interact with users and run queries using the query handler above.
122
+
We can provide an empty main functionfor now, with a `@cocoindex.main_fn()` decorator:
145
123
146
124
```python title="quickstart.py"
147
125
@cocoindex.main_fn()
148
126
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 +135,6 @@ The `@cocoindex.main_fn` declares a function as the main function for an indexin
171
135
* Initialize the CocoIndex librart states. Settings (e.g. database URL) are loaded from environment variables by default.
172
136
* 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
137
174
-
175
138
## Step 3: Run the indexing pipeline and queries
176
139
177
140
Specify the database URL by environment variable:
@@ -206,9 +169,129 @@ It will run for a few seconds and output the following statistics:
206
169
documents: 3 added, 0 removed, 0 updated
207
170
```
208
171
209
-
### Step 3.3: Run queries against the index
172
+
## Step 4 (optional): Run queries against the index
173
+
174
+
CocoIndex excels at transforming your data and storing it (a.k.a. indexing).
175
+
The goal of transforming your data is usually to query against it.
176
+
Once you already have your index built, you can directly access the transformed data in the target database.
177
+
CocoIndex also provides utilities for you to do this more seamlessly.
178
+
179
+
In this example, we'll use the [`psycopg` library](https://www.psycopg.org/) to connect to the database and run queries.
180
+
Please make sure it's installed:
181
+
182
+
```bash
183
+
pip install psycopg[binary,pool]
184
+
```
185
+
186
+
### Step 4.1: Extract common transformations
187
+
188
+
Between your indexing flow and the query logic, one piece of transformation is shared: compute the embedding of a text.
189
+
i.e. they should use exactly the same embedding model and parameters.
It interacts with users and search the database by calling the `search()` method created in Step 4.2.
291
+
292
+
### Step 4.4: Run queries against the index
210
293
211
-
Now we have the index built. We can run the same Python file without additional arguments, which will run the main function defined in Step 2.3:
294
+
Now we can run the same Python file, which will run the new main function:
212
295
213
296
```bash
214
297
python quickstart.py
@@ -222,5 +305,5 @@ Next, you may want to:
222
305
223
306
* Learn about [CocoIndex Basics](../core/basics.md).
224
307
* Learn about other examples in the [examples](https://github.com/cocoindex-io/cocoindex/tree/main/examples) directory.
225
-
* The `text_embedding` example is this quickstart with some polishing (loading environment variables from `.env` file, extract pieces shared by the indexing flow and query handler into a function).
308
+
* The `text_embedding` example is this quickstart.
226
309
* Pick other examples to learn upon your interest.
Copy file name to clipboardExpand all lines: examples/product_recommendation/README.md
+4-2Lines changed: 4 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,8 @@
1
-
# Build Real-Time Product Recommendation based on LLM Taxonomy Extraction and Knowledge Graph
1
+
# Build Real-Time Recommendation Engine with LLM and Graph Database
2
2
3
-
We will process a list of products and use LLM to extract the taxonomy and complimentary taxonomy for each product.
3
+
We will build a real-time product recommendation engine with LLM and graph database. In particular, we will use LLM to understand the category (taxonomy) of a product. In addition, we will use LLM to enumerate the complementary products - users are likely to buy together with the current product (pencil and notebook).
4
+
5
+
We will use Graph to explore the relationships between products that can be further used for product recommendations or labeling.
4
6
5
7
Please drop [CocoIndex on Github](https://github.com/cocoindex-io/cocoindex) a star to support us and stay tuned for more updates. Thank you so much 🥥🤗. [](https://github.com/cocoindex-io/cocoindex)
0 commit comments