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: docs/docs/core/initialization.mdx
+53-28Lines changed: 53 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,20 +1,24 @@
1
1
---
2
2
title: Initialization
3
-
description: Initialize the CocoIndex library
3
+
description: Initialize and set environment for CocoIndex library
4
4
---
5
5
6
6
importTabsfrom'@theme/Tabs';
7
7
importTabItemfrom'@theme/TabItem';
8
8
9
9
# Initialize the CocoIndex Library
10
10
11
-
Before everything starts, the `cocoindex` library needs to be initialized with settings.
12
-
There're two options to do this:
11
+
Before everything starts, the CocoIndex library needs to be initialized with settings.
12
+
We'll talk about the code skeleton to initialize the library in your code, and the way to provide settings for CocoIndex.
13
13
14
-
* Using packaged main function. It's easier to start with.
14
+
## Initialize the library
15
+
16
+
There're two options to initialize in your code:
17
+
18
+
* Use packaged main function. It's easier to start with.
15
19
* Explicit initialization. It's more flexible.
16
20
17
-
##Using Packaged Main
21
+
###Packaged Main
18
22
19
23
The easiest way is to use a packaged main function:
20
24
@@ -45,33 +49,13 @@ This takes care of the following effects:
45
49
See [CocoIndex CLI](/docs/core/cli) for more details.
46
50
3. Otherwise, it will run the main function.
47
51
48
-
### Environment Variables
49
-
50
-
The following environment variables are supported:
52
+
See [Environment Variables](#environment-variables) for supported environment variables.
51
53
52
-
*`COCOINDEX_DATABASE_URL` (required): The URL of the Postgres database to use as the internal storage, e.g. `postgres://cocoindex:cocoindex@localhost/cocoindex`
53
-
*`COCOINDEX_DATABASE_USER` (optional): The username for the Postgres database. If not provided, username will come from `COCOINDEX_DATABASE_URL`.
54
-
*`COCOINDEX_DATABASE_PASSWORD` (optional): The password for the Postgres database. If not provided, password will come from `COCOINDEX_DATABASE_URL`.
55
54
56
-
## Explicit Initialization
55
+
###Explicit Initialization
57
56
58
57
Alternatively, for flexibility, you can also explicitly initialize the library by the `init()` function:
59
58
60
-
### Settings
61
-
62
-
It takes a `Settings` object as argument, which is a dataclass that contains the following fields:
63
-
64
-
*`database` (type: `DatabaseConnectionSpec`, required): The connection to the Postgres database.
65
-
66
-
#### DatabaseConnectionSpec
67
-
68
-
`DatabaseConnectionSpec` has the following fields:
69
-
*`url` (type: `str`, required): The URL of the Postgres database to use as the internal storage, e.g. `postgres://cocoindex:cocoindex@localhost/cocoindex`.
70
-
*`user` (type: `str`, optional): The username for the Postgres database. If not provided, username will come from `url`.
71
-
*`password` (type: `str`, optional): The password for the Postgres database. If not provided, password will come from `url`.
72
-
73
-
### Example
74
-
75
59
<Tabs>
76
60
<TabItemvalue="python"label="Python"default>
77
61
@@ -93,4 +77,45 @@ if __name__ == "__main__":
93
77
```
94
78
95
79
</TabItem>
96
-
</Tabs>
80
+
</Tabs>
81
+
82
+
## Settings
83
+
84
+
`cocoindex.Settings` is used to configure the CocoIndex library. It's a dataclass that contains the following fields:
85
+
86
+
*`database` (type: `DatabaseConnectionSpec`, required): The connection to the Postgres database.
87
+
88
+
### DatabaseConnectionSpec
89
+
90
+
`DatabaseConnectionSpec` configures the connection to a database. Only Postgres is supported for now. It has the following fields:
91
+
92
+
*`url` (type: `str`, required): The URL of the Postgres database to use as the internal storage, e.g. `postgres://cocoindex:cocoindex@localhost/cocoindex`.
93
+
*`user` (type: `str`, optional): The username for the Postgres database. If not provided, username will come from `url`.
94
+
*`password` (type: `str`, optional): The password for the Postgres database. If not provided, password will come from `url`.
95
+
96
+
:::tip
97
+
98
+
Please be careful that all values in `url` needs to be url-encoded if they contain special characters.
99
+
For this reason, prefer to use the separated `user` and `password` fields for username and password.
100
+
101
+
:::
102
+
103
+
:::info
104
+
105
+
If you use the Postgres database hosted by [Supabase](https://supabase.com/), please click **Connect** on your project dashboard and find the following URL:
106
+
107
+
* If you're on a IPv6 network, use the URL under **Direct connection**. You can visit [IPv6 test](https://test-ipv6.com/) to see if you have IPv6 Internet connection.
108
+
* Otherwise, use the URL under **Session pooler**.
109
+
110
+
:::
111
+
112
+
## Environment Variables
113
+
114
+
When you use the packaged main function, settings will be loaded from environment variables.
115
+
Each setting field has a corresponding environment variable:
116
+
117
+
| environment variable | corresponding field in `Settings`| required? |
0 commit comments