Skip to content

Commit 69f3113

Browse files
committed
docs: update the documentation page with Pydantic Classes
1 parent e1401d9 commit 69f3113

File tree

1 file changed

+29
-30
lines changed

1 file changed

+29
-30
lines changed

docs/docs/examples/examples/product_recommendation.md

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ Product taxonomy is a way to organize product catalogs in a logical and hierarch
2929

3030
## Prerequisites
3131

32-
* [Install PostgreSQL](https://cocoindex.io/docs/getting_started/installation#-install-postgres). CocoIndex uses PostgreSQL internally for incremental processing.
32+
- [Install PostgreSQL](https://cocoindex.io/docs/getting_started/installation#-install-postgres). CocoIndex uses PostgreSQL internally for incremental processing.
3333
- [Install Neo4j](https://cocoindex.io/docs/targets/neo4j), a graph database.
34-
- - [Configure your OpenAI API key](https://cocoindex.io/docs/ai/llm#openai). Create a `.env` file from `.env.example`, and fill `OPENAI_API_KEY`.
34+
- [Configure your OpenAI API key](https://cocoindex.io/docs/ai/llm#openai). Create a `.env` file from `.env.example`, and fill `OPENAI_API_KEY`.
3535

3636
Alternatively, we have native support for Gemini, Ollama, LiteLLM. You can choose your favorite LLM provider and work completely on-premises.
3737

@@ -134,44 +134,43 @@ It performs the following transformations:
134134

135135
### Product Taxonomy Definition
136136

137-
Since we are using LLM to extract product taxonomy, we need to provide a detailed instruction at the class-level docstring.
137+
Since we are using LLM to extract product taxonomy, we need to provide a detailed instruction at the field-level description.
138138

139139
```python
140-
@dataclasses.dataclass
141-
class ProductTaxonomy:
142-
"""
143-
Taxonomy for the product.
144-
145-
A taxonomy is a concise noun (or short noun phrase), based on its core functionality, without specific details such as branding, style, etc.
146-
147-
Always use the most common words in US English.
148-
149-
Use lowercase without punctuation, unless it's a proper noun or acronym.
150-
151-
A product may have multiple taxonomies. Avoid large categories like "office supplies" or "electronics". Use specific ones, like "pen" or "printer".
152-
"""
153-
name: str
140+
class ProductTaxonomy(BaseModel):
141+
"""
142+
Taxonomy for the product.
143+
"""
144+
145+
name: str = Field(
146+
description="A taxonomy is a concise noun (or short noun phrase), based on its core functionality, "
147+
"without specific details such as branding, style, etc. Always use the most common words in US "
148+
"English. Use lowercase without punctuation, unless it's a proper noun or acronym. A product may "
149+
"have multiple taxonomies. Avoid large categories like 'office supplies' or 'electronics'. Use "
150+
"specific ones, like 'pen' or 'printer'."
151+
)
154152
```
155153

156154
### Define Product Taxonomy Info
157155

158-
Basically we want to extract all possible taxonomies for a product, and think about what other products are likely to be bought together with the current product.
156+
Basically, we want to extract all possible taxonomies for a product and think about what other products are likely to be bought together with the current product.
159157

160158
```python
161-
@dataclasses.dataclass
162-
class ProductTaxonomyInfo:
163-
"""
164-
Taxonomy information for the product.
165-
166-
Fields:
167-
- taxonomies: Taxonomies for the current product.
168-
- complementary_taxonomies: Think about when customers buy this product, what else they might need as complementary products. Put labels for these complentary products.
169-
"""
170-
taxonomies: list[ProductTaxonomy]
171-
complementary_taxonomies: list[ProductTaxonomy]
159+
class ProductTaxonomyInfo(BaseModel):
160+
"""
161+
Taxonomy information for the product.
162+
"""
163+
164+
taxonomies: list[ProductTaxonomy] = Field(
165+
description="Taxonomies for the current product."
166+
)
167+
complementary_taxonomies: list[ProductTaxonomy] = Field(
168+
"Think about when customers buy this product, what else they might need as complementary products. Put labels "
169+
"for these complementary products."
170+
)
172171
```
173172

174-
For each product, we want some insight about its taxonomy and complementary taxonomy and we could use that as bridge to find related product using knowledge graph.
173+
For each product, we want some insight about its taxonomy and complementary taxonomy, and we could use that as a bridge to find a related product using the knowledge graph.
175174

176175
### LLM Extraction
177176

0 commit comments

Comments
 (0)