Skip to content

Commit

Permalink
Working single image index
Browse files Browse the repository at this point in the history
  • Loading branch information
Weldawadyathink committed Feb 8, 2024
1 parent d61c717 commit e4c08d6
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 6 deletions.
11 changes: 11 additions & 0 deletions services/embedding-indexer/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions services/embedding-indexer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"author": "Spenser Bushey",
"license": "ISC",
"devDependencies": {
"@types/axios": "^0.14.0",
"@types/node": "^20.11.16",
"@types/node-cron": "^3.0.11",
"@types/pg": "^8.11.0",
Expand Down
36 changes: 31 additions & 5 deletions services/embedding-indexer/src/reindex.ts
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]));
};
2 changes: 1 addition & 1 deletion services/embedding-indexer/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
/* Modules */
"module": "commonjs", /* Specify what module code is generated. */
"rootDir": "./src", /* Specify the root folder within your source files. */
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
"moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
Expand Down

0 comments on commit e4c08d6

Please sign in to comment.