Skip to content

Commit e43f297

Browse files
committed
Merge branch 'main' into jelly-docs
2 parents 4195479 + e846a28 commit e43f297

File tree

6 files changed

+198
-220
lines changed

6 files changed

+198
-220
lines changed

.github/workflows/docs.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,21 @@ jobs:
3737
- name: Test build website
3838
run: yarn build
3939

40+
deploy-precheck:
41+
runs-on: ubuntu-latest
42+
if: ${{ github.event_name != 'pull_request' }}
43+
outputs:
44+
gh-deploy-key: ${{ steps.gh-deploy-key.outputs.defined }}
45+
steps:
46+
- id: gh-deploy-key
47+
env:
48+
GH_PAGES_DEPLOY: ${{ secrets.GH_PAGES_DEPLOY }}
49+
if: "${{ env.GH_PAGES_DEPLOY != '' }}"
50+
run: echo "defined=true" >> $GITHUB_OUTPUT
51+
4052
deploy:
41-
if: github.event_name != 'pull_request'
53+
needs: [deploy-precheck]
54+
if: ${{ needs.deploy-precheck.outputs.gh-deploy-key == 'true' }}
4255
runs-on: ubuntu-latest
4356
steps:
4457
- uses: actions/checkout@v4
@@ -61,6 +74,8 @@ jobs:
6174
env:
6275
USE_SSH: true
6376
run: |
77+
export COCOINDEX_DOCS_POSTHOG_API_KEY=${{ secrets.COCOINDEX_DOCS_POSTHOG_API_KEY }}
78+
export COCOINDEX_DOCS_MIXPANEL_API_KEY=${{ secrets.COCOINDEX_DOCS_MIXPANEL_API_KEY }}
6479
git config --global user.email "[email protected]"
6580
git config --global user.name "CocoIndex"
6681
yarn install --frozen-lockfile

docs/docs/core/basics.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ An indexing flow involves source data and transformed data (either as an interme
2222
Each piece of data has a **data type**, falling into one of the following categories:
2323

2424
* Basic type.
25-
* Composite type
26-
* Struct: a collection of **fields**, each with a name and a type.
27-
* Table: a collection of **rows**, each of which is a struct with specified schema.
25+
* Struct type: a collection of **fields**, each with a name and a type.
26+
* Collection type: a collection of **rows**, each of which is a struct with specified schema. A collection type can be a table (which has a key field) or a list (ordered but without key field).
2827

2928
An indexing flow always has a top-level struct, containing all data within and managed by the flow.
3029

docs/docs/core/data_types.mdx

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,37 +17,50 @@ This is the list of all basic types supported by CocoIndex:
1717

1818
| Type | Type in Python | Original Type in Python |
1919
|------|-----------------|--------------------------|
20-
| `bytes` | `bytes` | `bytes` |
21-
| `str` | `str` | `str` |
22-
| `bool` | `bool` | `bool` |
23-
| `int64` | `int` | `int` |
24-
| `float32` | `cocoindex.typing.Float32` |`float` |
25-
| `float64` | `cocoindex.typing.Float64` |`float` |
26-
| `range` | `cocoindex.typing.Range` | `tuple[int, int]` |
27-
| `vector(*type* [, *N*])` |`Annotated[list[type], cocoindex.typing.Vector(dim=N)]` | `list[type]` |
28-
| `json` | `cocoindex.typing.Json` | Any type convertible to JSON by `json` package |
20+
| bytes | `bytes` | `bytes` |
21+
| str | `str` | `str` |
22+
| bool | `bool` | `bool` |
23+
| int64 | `int` | `int` |
24+
| float32 | `cocoindex.typing.Float32` |`float` |
25+
| float64 | `cocoindex.typing.Float64` |`float` |
26+
| range | `cocoindex.typing.Range` | `tuple[int, int]` |
27+
| vector[*type*, *N*?] |`Annotated[list[type], cocoindex.typing.Vector(dim=N)]` | `list[type]` |
28+
| json | `cocoindex.typing.Json` | Any type convertible to JSON by `json` package |
2929

3030
For some types, CocoIndex Python SDK provides annotated types with finer granularity than Python's original type, e.g. `Float32` and `Float64` for `float`, and `vector` has dimension information.
3131

3232
When defining [custom functions](/docs/core/custom_function), use the specific types as type annotations for arguments and return values.
3333
So CocoIndex will have information about the specific type.
3434

35-
### Struct
35+
### Struct Type
3636

3737
A struct has a bunch of fields, each with a name and a type.
3838

39-
### Table
39+
In Python, a struct type is represented by a [dataclass](https://docs.python.org/3/library/dataclasses.html),
40+
and all fields must be annotated with a specific type. For example:
4041

41-
A table has a collection of rows, each of which is a struct with specified schema.
42+
```python
43+
from dataclasses import dataclass
4244

43-
The first field of a table is always the primary key.
45+
@dataclass
46+
class Order:
47+
order_id: str
48+
name: str
49+
price: float
50+
```
4451

45-
:::note
52+
### Collection Types
4653

47-
CocoIndex will support functions taking struct and table types as arguments or returning composite types soon.
48-
We'll update this section with corresponding Python types by then.
54+
A collection type models a collection of rows, each of which is a struct with specific schema.
4955

50-
:::
56+
We have two specific types of collection:
57+
58+
| Type | Description |Type in Python | Original Type in Python |
59+
|------|-------------|---------------|-------------------------|
60+
| Table[*type*] | The first field is the key, and CocoIndex enforces its uniqueness | `cocoindex.typing.Table[type]` | `list[type]` |
61+
| List[*type*] | No key field; row order is preserved | `cocoindex.typing.List[type]` | `list[type]` |
62+
63+
For example, we can use `cocoindex.typing.Table[Order]` to represent a table of orders, and the first field `order_id` will be taken as the key field.
5164

5265
## Types to Create Indexes
5366

docs/docusaurus.config.ts

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import webpack from 'webpack';
12
import { themes as prismThemes } from 'prism-react-renderer';
23
import type { Config } from '@docusaurus/types';
34
import type * as Preset from '@docusaurus/preset-classic';
@@ -33,14 +34,17 @@ const config: Config = {
3334
},
3435

3536
plugins: [
36-
[
37-
"posthog-docusaurus",
38-
{
39-
apiKey: "phc_SgKiQafwZjHu4jQW2q402gbz6FYQ2NJRkcgooZMNNcy",
40-
appUrl: "https://us.i.posthog.com",
41-
enableInDevelopment: false,
42-
},
43-
],
37+
() => ({
38+
name: 'load-env-vars',
39+
configureWebpack: () => ({
40+
mergeStrategy: { plugins: "append", resolve: "merge" },
41+
plugins: [
42+
new webpack.DefinePlugin({
43+
'process.env.COCOINDEX_DOCS_MIXPANEL_API_KEY': JSON.stringify(process.env.COCOINDEX_DOCS_MIXPANEL_API_KEY),
44+
})
45+
],
46+
}),
47+
}),
4448
],
4549

4650
presets: [
@@ -147,4 +151,16 @@ const config: Config = {
147151
} satisfies Preset.ThemeConfig,
148152
};
149153

154+
155+
if (!!process.env.COCOINDEX_DOCS_POSTHOG_API_KEY) {
156+
config.plugins.push([
157+
"posthog-docusaurus",
158+
{
159+
apiKey: process.env.COCOINDEX_DOCS_POSTHOG_API_KEY,
160+
appUrl: "https://us.i.posthog.com",
161+
enableInDevelopment: false,
162+
},
163+
]);
164+
}
165+
150166
export default config;

docs/src/theme/Root.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import React from 'react';
22
import mixpanel from 'mixpanel-browser';
33

44
// Default implementation, that you can customize
5-
export default function Root({children}) {
5+
export default function Root({ children }) {
66
React.useEffect(() => {
7-
if (typeof window !== 'undefined') {
7+
const mixpanelApiKey = process.env.COCOINDEX_DOCS_MIXPANEL_API_KEY;
8+
if (typeof window !== 'undefined' && !!mixpanelApiKey) {
89
// Initialize Mixpanel with the token
9-
mixpanel.init('46addeb6bedf8684a445aced6e67c76e', {
10+
mixpanel.init(mixpanelApiKey, {
1011
track_pageview: true,
1112
debug: process.env.NODE_ENV === 'development'
1213
});

0 commit comments

Comments
 (0)