Skip to content

Latest commit

 

History

History
65 lines (43 loc) · 1.26 KB

File metadata and controls

65 lines (43 loc) · 1.26 KB

Run docker container with a simple query endpoint via fastapi

In this example, we will build index for text embedding from local markdown files, and provide a simple query endpoint via fastapi. We provide a simple docker container using docker compose to build pgvector17 along with a simple python fastapi script

We appreciate a star ⭐ at CocoIndex Github if this is helpful.

Run locally without docker

In the .env file, use local Postgres URL

# For local testing
COCOINDEX_DATABASE_URL=postgres://cocoindex:cocoindex@localhost/cocoindex
  • Install dependencies:

    pip install -e .
  • Setup:

    cocoindex setup main
  • Update index:

    cocoindex update main
  • Run:

    uvicorn main:fastapi_app --reload --host 0.0.0.0 --port 8000

Query the endpoint

```bash
curl "http://localhost:8000/search?q=model&limit=3"
```

Run Docker

In the .env file, use Docker Postgres URL

COCOINDEX_DATABASE_URL=postgres://cocoindex:cocoindex@coco_db:5436/cocoindex

Build the docker container via:

docker compose up --build

Test the endpoint:

curl "http://0.0.0.0:8080/search?q=model&limit=3"