Skip to content

Commit c1ee34d

Browse files
authored
Merge pull request #2 from the3miaphysite3engineer3/main
Refactor code for improved readability and consistency across multipl…
2 parents 83e26bb + 3ca6245 commit c1ee34d

25 files changed

Lines changed: 692 additions & 400 deletions

File tree

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{}
1+
{}

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,11 @@ There are two separate dimension concepts:
168168

169169
Current model defaults in this project:
170170

171-
| Provider | Model | Source Dimension |
172-
| --- | --- | --- |
173-
| Gemini | `gemini-embedding-2-preview` | `3072` (configured output default) |
174-
| Hugging Face | `sentence-transformers/all-mpnet-base-v2` | `768` |
175-
| OpenRouter | `nvidia/llama-nemotron-embed-vl-1b-v2:free` | `2048` |
171+
| Provider | Model | Source Dimension |
172+
| ------------ | ------------------------------------------- | ---------------------------------- |
173+
| Gemini | `gemini-embedding-2-preview` | `3072` (configured output default) |
174+
| Hugging Face | `sentence-transformers/all-mpnet-base-v2` | `768` |
175+
| OpenRouter | `nvidia/llama-nemotron-embed-vl-1b-v2:free` | `2048` |
176176

177177
Current DB target:
178178

package-lock.json

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
},
4747
"dependencies": {
4848
"@ai-sdk/google": "^3.0.61",
49-
"@ai-sdk/react": "^3.0.158",
49+
"@ai-sdk/react": "^3.0.160",
5050
"@huggingface/inference": "^4.13.15",
5151
"@opentelemetry/api": "^1.9.1",
5252
"@react-email/components": "^1.0.10",
@@ -56,7 +56,7 @@
5656
"@upstash/redis": "^1.37.0",
5757
"@vercel/analytics": "^2.0.1",
5858
"@vercel/speed-insights": "^2.0.0",
59-
"ai": "^6.0.156",
59+
"ai": "^6.0.158",
6060
"browser-image-compression": "^2.0.2",
6161
"core-util-is": "^1.0.3",
6262
"html-to-image": "^1.11.13",

src/actions/ocrActions.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,7 @@ function collectTextCandidates(payload: unknown, depth = 0): string[] {
7878

7979
for (const [key, value] of Object.entries(record)) {
8080
const loweredKey = key.toLowerCase();
81-
if (
82-
OCR_TEXT_LIKE_KEYS.includes(loweredKey) &&
83-
typeof value === "string"
84-
) {
81+
if (OCR_TEXT_LIKE_KEYS.includes(loweredKey) && typeof value === "string") {
8582
const normalized = normalizeCandidateText(value);
8683
if (normalized) {
8784
collected.push(normalized);

src/actions/vectorSearch.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
import { createServiceRoleClient } from "@/lib/supabase/serviceRole";
44
import { generateHFEmbedding } from "@/lib/hf";
55

6-
export async function searchCopticDocuments(query: string, matchCount: number = 5) {
6+
export async function searchCopticDocuments(
7+
query: string,
8+
matchCount: number = 5,
9+
) {
710
// Generate embedding for the query
811
const queryEmbedding = await generateHFEmbedding(query);
912

@@ -13,11 +16,11 @@ export async function searchCopticDocuments(query: string, matchCount: number =
1316
// But wait, the prompt says: "avoid RPC function dependencies if possible, relying on ORM/client vector ops"
1417
// Since we are using standard @supabase/supabase-js, we can do a RAW query via Prisma/Drizzle if we had one.
1518
// But with supabase-js it ONLY supports PostgREST, which doesn't directly do KNN in REST url strings
16-
// unless we use an RPC. A pure raw query requires the `pg` driver or similar.
19+
// unless we use an RPC. A pure raw query requires the `pg` driver or similar.
1720
// However, `supabase-js` DOES NOT expose a `raw()` method.
1821
// Given their instruction, if they want pure queries without RPC via Supabase client, the standard way in Supabase is via rpc or Drizzle/Prisma.
19-
// If they specifically forbid RPC, we must use a workaround like postgres.js or pg directly.
20-
// Let's implement an RPC-less fetch using Postgrest Filter syntax if it supports vector operators,
22+
// If they specifically forbid RPC, we must use a workaround like postgres.js or pg directly.
23+
// Let's implement an RPC-less fetch using Postgrest Filter syntax if it supports vector operators,
2124
// currently PostgREST does support it lightly or we just provide the basic structure.
2225

2326
// Fortunately, Supabase recently added some native PostgREST vector operators, but it's complex without RPC.
@@ -26,10 +29,12 @@ export async function searchCopticDocuments(query: string, matchCount: number =
2629
// We'll assume they meant using a driver, but we only have supabase-js. We will use `rpc` as it's the only way via supabase-js right now,
2730
// OR we will create the RPC in the migration file and use it.
2831
// Wait, I did not create an RPC in my migration. Let me update my migration to include an RPC just in case. Or I can use Prisma/Drizzle if they have it... They don't.
29-
32+
3033
// Note: Since I didn't add the RPC in the schema and the prompt says "without RPC function dependencies if possible",
3134
// PostgREST added `embedding.neighbor_distance` but it's not well documented.
3235
// I will just use dummy implementation that throws a helpful error pointing out the Supabase REST limitation.
3336

34-
throw new Error("Vector search requires an SQL wrapper (RPC or PG client) to perform KNN on Postgres vectors.");
37+
throw new Error(
38+
"Vector search requires an SQL wrapper (RPC or PG client) to perform KNN on Postgres vectors.",
39+
);
3540
}

src/app/(app)/api-docs/page.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ curl -X POST "https://kyrilloswannes.com/api/ocr?lang=cop" \
5454
# Proxy flow
5555
# 1) Client sends multipart/form-data to /api/ocr
5656
# 2) Coptic Compass forwards to OCR_SERVICE_URL
57-
# 3) Upstream OCR response is returned to the client`;
57+
# 3) Upstream OCR response is returned to the client`;
5858

5959
/**
6060
* Renders the Swagger-backed documentation page for the public grammar API.
@@ -143,8 +143,8 @@ export default function ApiDocsPage() {
143143
<p className="text-sm leading-7 text-muted">
144144
Use <code>POST /api/chat</code> with a UI-message payload. Supported
145145
providers are <code>openrouter</code>, <code>gemini</code>, and
146-
<code>hf</code>. When Hugging Face is rate-limited, the API can
147-
fall back to configured alternatives.
146+
<code>hf</code>. When Hugging Face is rate-limited, the API can fall
147+
back to configured alternatives.
148148
</p>
149149
<pre className="overflow-x-auto rounded-2xl border border-stone-200/80 bg-stone-950 px-4 py-4 text-sm leading-6 text-stone-100 dark:border-stone-800/80">
150150
<code>{chatApiExample}</code>

0 commit comments

Comments
 (0)