examples/code_embedding/README.md
This example extracts code chunks from local Python files, stores the code and their vector embeddings in Postgres (pgvector), and provides a simple semantic search demo for code.
A running Postgres with the pgvector extension. If you don't have one, start a local instance with the compose file in this repo:
docker compose -f ../../dev/postgres.yaml up -d
POSTGRES_URL set, e.g.
export POSTGRES_URL="postgres://cocoindex:cocoindex@localhost/cocoindex"
Install deps:
pip install -e .
Build/update the index (writes rows into Postgres). Pick one of the two modes:
Catch-up run — scan sources, sync changes, exit:
cocoindex update main
Live run — catch up, then keep watching for file changes (the source declares live=True in main.py):
cocoindex update -L main
Query:
python main.py "embedding"