Skip to content

Commit 5c2baf7

Browse files
Expand README with AI usage and retrieval patterns
1 parent 60b1b56 commit 5c2baf7

File tree

1 file changed

+77
-16
lines changed

1 file changed

+77
-16
lines changed

README.md

Lines changed: 77 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,86 @@
1-
# pg4ai: PostgreSQL 18.3 + Apache AGE + pgvector
1+
# pg4ai: PostgreSQL 18.3 + Graph + Vector + Hybrid Search
22

3-
Multi-Arch Docker Image (`linux/amd64`, `linux/arm64`) auf Basis von `postgres:18.3` mit:
3+
Multi-Arch Docker Image (`linux/amd64`, `linux/arm64`) auf Basis von `postgres:18.3` fuer AI-nahe Workloads.
44

5-
- Apache AGE `PG18/v1.7.0-rc0` (Upstream-Tag fuer PG18)
6-
- pgvector `v0.8.2`
7-
- `pg_trgm` + `unaccent` fuer typo-tolerante Volltext-/Hybrid-Suche
5+
## Enthaltene Funktionalitaet
86

9-
Die Extensions werden beim ersten DB-Start automatisch via Init-Skript aktiviert.
7+
- Apache AGE `PG18/v1.7.0-rc0`: Property-Graph und Cypher fuer Graph-RAG und Beziehungsabfragen.
8+
- pgvector `v0.8.2`: Embeddings, ANN-Indizes und semantische Aehnlichkeitssuche.
9+
- `pg_trgm` + `unaccent`: typo-tolerante und sprachrobuste lexikalische Suche.
1010

11-
## Lokale Nutzung
11+
Alle Extensions werden beim ersten DB-Start automatisch aktiviert (`docker/init/01-extensions.sql`).
1212

13-
Build und Start mit Compose:
13+
## Wo Das Fuer AI Eingesetzt Wird
1414

15-
```bash
16-
docker compose up --build
15+
1. Ingestion-Pipeline:
16+
- Dokumente/Chunks schreiben, Embeddings erzeugen und als `vector` speichern.
17+
- Optional Entitaeten/Beziehungen parallel als Graphknoten/-kanten ablegen.
18+
19+
2. Online Retrieval Layer:
20+
- Semantische Suche mit `pgvector` (k-nearest neighbors auf Embeddings).
21+
- Lexikalische Suche mit FTS + `pg_trgm` + `unaccent`.
22+
- Hybrid Retrieval: beide Scores zusammenfuehren und als Kontext fuer das LLM liefern.
23+
24+
3. Reasoning / Context Expansion:
25+
- Mit AGE Nachbarschaften, Pfade oder Abhaengigkeiten aus dem Graphen ziehen.
26+
- Ergebnis mit Vektor/FTS-Hits mergen (Graph-RAG).
27+
28+
## Schnelle SQL-Muster
29+
30+
### 1. Semantische Suche mit pgvector
31+
32+
```sql
33+
CREATE TABLE documents (
34+
id bigserial PRIMARY KEY,
35+
content text NOT NULL,
36+
embedding vector(1536) NOT NULL
37+
);
38+
39+
-- Beispiel: ANN-Index (Operator Class je nach Distanzmetrik auswaehlen)
40+
CREATE INDEX documents_embedding_hnsw_idx
41+
ON documents USING hnsw (embedding vector_l2_ops);
42+
43+
-- Top-k nearest neighbors
44+
SELECT id, content
45+
FROM documents
46+
ORDER BY embedding <-> '[0.01,0.02,0.03]'::vector
47+
LIMIT 10;
1748
```
1849

19-
Smoke-Test gegen ein gebautes Image:
50+
### 2. Lexikalische/typo-tolerante Suche
51+
52+
```sql
53+
-- FTS + unaccent
54+
SELECT id, content
55+
FROM documents
56+
WHERE to_tsvector('simple', unaccent(content))
57+
@@ plainto_tsquery('simple', unaccent('hotel berlin'));
58+
59+
-- Trigram similarity (fuzzy matching)
60+
SELECT id, content, similarity(content, 'hotle berln') AS sim
61+
FROM documents
62+
WHERE content % 'hotle berln'
63+
ORDER BY sim DESC
64+
LIMIT 10;
65+
```
66+
67+
### 3. Graph-RAG mit AGE
68+
69+
```sql
70+
LOAD 'age';
71+
SET search_path = ag_catalog, "$user", public;
72+
73+
SELECT *
74+
FROM cypher('knowledge_graph', $$
75+
MATCH (q:Entity {name: 'PostgreSQL'})-[:RELATED_TO]->(n)
76+
RETURN n.name
77+
$$) AS (name agtype);
78+
```
79+
80+
## Lokale Nutzung
2081

2182
```bash
83+
docker compose up --build
2284
IMAGE_REF=pg4ai:dev ./scripts/smoke-test.sh
2385
```
2486

@@ -32,14 +94,13 @@ make test-arm64
3294
make build-multiarch REGISTRY_IMAGE=ghcr.io/<owner>/<repo> IMAGE_TAG=latest
3395
```
3496

35-
## GitHub Actions
97+
## CI / Quality
3698

3799
Workflow: `.github/workflows/ci-multiarch.yml`
38100

39-
- PRs: Build fuer `amd64` + `arm64` (QEMU), Smoke-Tests auf `amd64`.
40-
- Push auf Branches: identische Tests.
41-
- Push auf Default-Branch: Publish nach GHCR mit Tags `sha-<shortsha>` und `latest`.
42-
- Push auf `v*` Tag: Publish nach GHCR mit Versionstag.
101+
- Quality-Gates: `actionlint`, `hadolint`, `shellcheck`.
102+
- Build/Test: `amd64` + `arm64` (QEMU), Smoke-Tests auf `amd64`.
103+
- Publish: auf Default-Branch und `v*` Tags nach GHCR.
43104

44105
## Lizenz
45106

0 commit comments

Comments
 (0)