Back to Cocoindex

Code Embedding (v1) 🧑‍💻

examples/code_embedding/README.md

1.0.3595 B
Original Source

Code Embedding (v1) 🧑‍💻

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.

Prerequisites

  • A running Postgres with the pgvector extension available
  • POSTGRES_URL set, e.g.
sh
export POSTGRES_URL="postgres://cocoindex:cocoindex@localhost/cocoindex"

Run

Install deps:

sh
pip install -e .

Build/update the index (writes rows into Postgres):

sh
cocoindex update main.py

Query:

sh
python main.py query "embedding"