{"id":37819117,"url":"https://github.com/daviszhen/pg_hybrid","last_synced_at":"2026-01-16T15:40:34.693Z","repository":{"id":326886959,"uuid":"1099718365","full_name":"daviszhen/pg_hybrid","owner":"daviszhen","description":"hybrid storage engine: columnar, vector, fulltext","archived":false,"fork":false,"pushed_at":"2025-12-27T11:40:11.000Z","size":55,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-12-29T05:30:08.582Z","etag":null,"topics":["columar","fulltext","lance","postgresql-database","postgresql-extension","storage-engine","vector"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/daviszhen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-11-19T11:01:35.000Z","updated_at":"2025-12-27T11:52:19.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/daviszhen/pg_hybrid","commit_stats":null,"previous_names":["daviszhen/pg_hybrid"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/daviszhen/pg_hybrid","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daviszhen%2Fpg_hybrid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daviszhen%2Fpg_hybrid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daviszhen%2Fpg_hybrid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daviszhen%2Fpg_hybrid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/daviszhen","download_url":"https://codeload.github.com/daviszhen/pg_hybrid/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daviszhen%2Fpg_hybrid/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28479409,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-16T11:59:17.896Z","status":"ssl_error","status_checked_at":"2026-01-16T11:55:55.838Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["columar","fulltext","lance","postgresql-database","postgresql-extension","storage-engine","vector"],"created_at":"2026-01-16T15:40:34.611Z","updated_at":"2026-01-16T15:40:34.677Z","avatar_url":"https://github.com/daviszhen.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pg_hybrid\n\nPostgreSQL 16 extension providing IVFFlat index access method for vector similarity search.\n\n## 功能特性\n\n- **IVFFlat 索引访问方法** (`pg_hybrid_ivfflat`): \n- 单向量函数: \n\n`hvector_in`\n`hvector_out`\n`hvector_typmod_in`\n`hvector_recv`\n`hvector_send`\n`hvector_dims`\n`hvector_norm`\n`hvector_l2_normalize`\n\n- 双向量函数: \n\n`hvector_l2_distance`\n`hvector_l2_squared_distance`\n\n- 向量操作符: `\u003c-\u003e`\n- 向量索引: `pg_hybrid_ivfflat`\n- 向量索引选项: `lists`\n- 向量索引配置参数: `ivfflat.probes`\n\n## 编译和安装\n\n- PostgreSQL 16 开发包（包含头文件和 pg_config）\n- GCC 或 Clang 编译器\n- Make\n\n### 1. 编译 Extension\n\n```bash\nmake\n```\n\n### 2. 安装到 PostgreSQL\n\n```bash\nmake install\n```\n\n**注意**：Makefile 默认使用 `pg_config`。如果您的 PostgreSQL 16 安装在不同的路径，请修改 `Makefile` 中的 `PG_CONFIG` 变量。\n\n\n### 3. 在数据库中创建 Extension\n\n```sql\nDROP EXTENSION IF EXISTS pg_hybrid CASCADE;\n\n-- 然后安装 pg_hybrid 扩展\nCREATE EXTENSION pg_hybrid;\n```\n\n### 4. 验证安装\n\n检查访问方法是否创建成功：\n\n```sql\nselect * from pg_am;\nselect * from pg_extension;\n\n-- 查看访问方法\nSELECT amname, amhandler FROM pg_am WHERE amname = 'pg_hybrid_ivfflat';\n\n```\n\n### 5. 卸载\n\n```sql\nDROP EXTENSION IF EXISTS pg_hybrid CASCADE;\n```\n\n然后删除安装的文件：\n\n```bash\nsudo make uninstall\n```\n\n## PostgreSQL 16 数据库管理\n\n### 初始化数据库\n\n如果还没有初始化 PostgreSQL 16 数据目录，需要先初始化：\n\n```bash\nmkdir -p ~/pg16_data\ninitdb -D ~/pg16_data -U postgres --locale=C --encoding=UTF8\n```\n\n### 启动数据库\n\n```bash\npg_ctl -D ~/pg16_data -l ~/pg16_data/logfile start\n```\n\n### 停止数据库\n\n```bash\npg_ctl -D ~/pg16_data stop\n```\n\n### 重启数据库\n\n```bash\npg_ctl -D ~/pg16_data restart\n```\n\n### 查看数据库状态\n\n```bash\npg_ctl -D ~/pg16_data status\n```\n\n### 连接数据库\n\n```bash\npsql -d postgres -U postgres\n```\n\n### 查看日志\n\n```bash\ntail -f ~/pg16_data/logfile\n```\n\n**注意**：默认数据目录为 `~/pg16_data`，默认端口为 `5432`。如果您的配置不同，请相应调整命令中的路径和端口。\n\n\n## 使用示例\n\n### 创建向量表和索引\n\n```sql\nDROP TABLE IF EXISTS items;\n\n-- 创建包含向量列的表\nCREATE TABLE items (\n    id bigserial PRIMARY KEY,\n    embedding hvector(5)\n);\n\n-- 生成 1 万行，每行一个 5 维随机向量\nINSERT INTO items (embedding) \nSELECT \n    ('[' || \n     string_agg((random() * 10)::text, ',') || \n     ']')::hvector(5) AS embedding\nFROM generate_series(1, 10000) AS row_num\nCROSS JOIN generate_series(1, 5) AS dim\nGROUP BY row_num;\n\nselect * from items;\n\n-- 向量相似度搜索（使用 L2 距离）\nSELECT * FROM items \nORDER BY embedding \u003c-\u003e '[1,2,3,4,5]'::hvector \nLIMIT 10;\n\n-- 使用 pg_hybrid_ivfflat 访问方法创建 IVFFlat 索引\nCREATE INDEX ON items USING pg_hybrid_ivfflat (embedding hvector_l2_ops)\nWITH (lists = 100);\n\nSELECT * FROM items \nORDER BY embedding \u003c-\u003e '[1,2,3,4,5]'::hvector \nLIMIT 10;\n```\n\n### 索引选项\n\n- `lists`: 倒排列表的数量（默认: 100，范围: 1-32768）\n  ```sql\n  CREATE INDEX idx_embedding ON items USING pg_hybrid_ivfflat (embedding)\n  WITH (lists = 200);\n  ```\n\n### 配置参数\n\n- `ivfflat.probes`: 设置查询时探测的列表数量（默认: 1）\n  ```sql\n  SET ivfflat.probes = 10;\n  SELECT * FROM items ORDER BY embedding \u003c-\u003e '[1,2,3]'::hvector LIMIT 5;\n  ```\n\n\n## 许可证\n\nApache License 2.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaviszhen%2Fpg_hybrid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdaviszhen%2Fpg_hybrid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaviszhen%2Fpg_hybrid/lists"}