Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions docs/docs/core/initialization.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,29 @@ This takes care of the following effects:

The following environment variables are supported:

* `COCOINDEX_DATABASE_URL`: The URL of the Postgres database to use as the internal storage, e.g. `postgres://cocoindex:cocoindex@localhost/cocoindex`
* `COCOINDEX_DATABASE_URL` (required): The URI of the Postgres database to use as the internal storage, e.g. `postgres://cocoindex:cocoindex@localhost/cocoindex`
* `COCOINDEX_DATABASE_USER` (optional): The username for the Postgres database. If not provided, username will come from `COCOINDEX_DATABASE_URL`.
* `COCOINDEX_DATABASE_PASSWORD` (optional): The password for the Postgres database. If not provided, password will come from `COCOINDEX_DATABASE_URL`.

## Explicit Initialization

Alternatively, for flexibility, you can also explicitly initialize the library by the `init()` function:

### Settings

It takes a `Settings` object as argument, which is a dataclass that contains the following fields:

* `database` (type: `DatabaseConnectionSpec`, required): The connection to the Postgres database.

#### DatabaseConnectionSpec

`DatabaseConnectionSpec` has the following fields:
* `uri` (type: `str`, required): The URI of the Postgres database to use as the internal storage, e.g. `postgres://cocoindex:cocoindex@localhost/cocoindex`.
* `user` (type: `str`, optional): The username for the Postgres database. If not provided, username will come from `uri`.
* `password` (type: `str`, optional): The password for the Postgres database. If not provided, password will come from `uri`.

### Example

<Tabs>
<TabItem value="python" label="Python" default>

Expand All @@ -63,7 +80,11 @@ import cocoindex

def main():
...
cocoindex.init(cocoindex.Settings(database_url="postgres://cocoindex:cocoindex@localhost/cocoindex"))
cocoindex.init(
cocoindex.Settings(
database=cocoindex.DatabaseConnectionSpec(
uri="postgres://cocoindex:cocoindex@localhost/cocoindex"
)))
...

...
Expand Down
4 changes: 3 additions & 1 deletion docs/docs/ops/storages.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ It should be a unique table, meaning that no other export target should export t

The spec takes the following fields:

* `database_url` (type: `str`, optional): The URL of the Postgres database to use as the internal storage, e.g. `postgres://cocoindex:cocoindex@localhost/cocoindex`. If unspecified, will use the same database as the [internal storage](/docs/core/basics#internal-storage).
* `database` (type: [auth reference](../core/flow_def#auth-registry) to `DatabaseConnectionSpec`, optional): The connection to the Postgres database.
See [DatabaseConnectionSpec](../core/initialization#databaseconnectionspec) for its specific fields.
If not provided, will use the same database as the [internal storage](/docs/core/basics#internal-storage).

* `table_name` (type: `str`, optional): The name of the table to store to. If unspecified, will generate a new automatically. We recommend specifying a name explicitly if you want to directly query the table. It can be omitted if you want to use CocoIndex's query handlers to query the table.

Expand Down