File size: 1,940 Bytes
8bbe1de
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# Mintoak pgvector PostgreSQL Inspection Commands

Below is a reference guide of all the useful `psql` and SQL commands to inspect, manage, and query your `pgvector` data inside the terminal.

---

## 1. Connecting to the Database
Connect to the database using the PostgreSQL command-line client:
```bash
psql -U postgres -h localhost -d mintoak_db
```

---

## 2. General Database Inspection (psql Meta-commands)
Run these commands inside the `psql` interactive prompt:
* **List all extensions** (verify if `vector` is installed):
  ```sql
  \dx
  ```
* **List all tables** in the database:
  ```sql
  \dt
  ```
* **Inspect the table schema** (view column types):
  ```sql
  \d mintoak_content
  ```
* **Exit the psql shell**:
  ```sql
  \q
  ```

---

## 3. SQL Data Queries
Run these SQL statements to query the knowledge base data:

* **Count the total number of document chunks**:
  ```sql
  SELECT COUNT(*) FROM mintoak_content;
  ```

* **Retrieve sample document contents**:
  ```sql
  SELECT id, document, metadata->>'title' AS title, metadata->>'url' AS url 
  FROM mintoak_content 
  LIMIT 5;
  ```

* **Find documents by specific metadata category**:
  ```sql
  SELECT id, document 
  FROM mintoak_content 
  WHERE metadata->>'category' = 'Company Info' 
  LIMIT 3;
  ```

---

## 4. Vector Search & Similarity Queries
You can run a raw cosine similarity search using the pgvector `<=>` distance operator:

* **Fetch top 3 most similar documents to a test embedding**:
  *(Replace the vector array with your query embedding vector)*
  ```sql
  SELECT id, document, (embedding <=> '[0.012, -0.045, 0.089, ... (384 float values)]'::vector) AS distance 
  FROM mintoak_content 
  ORDER BY distance ASC 
  LIMIT 3;
  ```

* **Inspect raw vector values**:
  *(Trims the vector array printout for readability)*
  ```sql
  SELECT id, subpath(embedding::text, 1, 50) || '...' AS vector_preview 
  FROM mintoak_content 
  LIMIT 3;
  ```