-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d61c717
commit e4c08d6
Showing
4 changed files
with
44 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,43 @@ | ||
import { query } from "./db"; | ||
import Axios from "axios"; | ||
|
||
export const reindex = async () => { | ||
const results = await query( | ||
// TODO: Remove limit | ||
` | ||
SELECT id | ||
FROM image | ||
WHERE embedding IS NULL | ||
SELECT id | ||
FROM image | ||
WHERE | ||
embedding IS NULL | ||
AND NOT index_error | ||
LIMIT 1 | ||
`, | ||
[] | ||
); | ||
results.rows.map((row) => indexItem(row.id)); | ||
}; | ||
|
||
const indexItem = async (id: string) => { | ||
console.log(`Indexing item id ${id}`) | ||
} | ||
console.log(`Indexing item id ${id}`); | ||
const image_url = `https://download.audiobookcovers.com/png/1000/${id}.png`; | ||
const clip_base_url = process.env.CLIP_API_URL || "http://localhost:8080"; | ||
const clip_url = `${clip_base_url}/embedding/image/url?url=${encodeURIComponent( | ||
image_url | ||
)}`; | ||
const embeddingInsertQuery = ` | ||
UPDATE image | ||
SET test_embedding = $1::vector | ||
WHERE id = $2 | ||
`; | ||
const indexErrorQuery = ` | ||
UPDATE image | ||
SET index_error = true | ||
WHERE id = $1 | ||
`; | ||
Axios.get(clip_url) | ||
.then((result) => JSON.stringify(result.data)) | ||
.then((embedding) => { | ||
query(embeddingInsertQuery, [embedding, id]); | ||
}) | ||
.catch(() => query(indexErrorQuery, [id])); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters