Skip to content

Commit

Permalink
Refactor vector search code
Browse files Browse the repository at this point in the history
  • Loading branch information
ahaapple committed Jan 4, 2025
1 parent 446ef90 commit 70cc866
Show file tree
Hide file tree
Showing 11 changed files with 406 additions and 228 deletions.
4 changes: 4 additions & 0 deletions frontend/lib/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ export const axiom = new Axiom({

export const log = async (message: any) => {
try {
if (process.env.NODE_ENV !== 'production') {
console.log('logClient:', message);
return;
}
axiom.ingest('memfree', [message]);
} catch (error) {
console.error('Error logging to Axiom:', error);
Expand Down
Binary file modified vector/bun.lockb
Binary file not shown.
55 changes: 55 additions & 0 deletions vector/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,60 @@
import type { DatabaseConfig, S3Config } from "./type";

export const DIMENSIONS = 384;

export const TABLE_COMPACT_THRESHOLD = 50;

export const EMBEDDING_MODEL = "text-embedding-3-large";

export function validateS3Config(config: Partial<S3Config>): S3Config {
if (!config.bucket) {
throw new Error("AWS bucket is required");
}
if (!config.awsAccessKeyId) {
throw new Error("AWS access key ID is required");
}
if (!config.awsSecretAccessKey) {
throw new Error("AWS secret access key is required");
}
if (!config.region) {
throw new Error("AWS region is required");
}

return {
bucket: config.bucket,
awsAccessKeyId: config.awsAccessKeyId,
awsSecretAccessKey: config.awsSecretAccessKey,
region: config.region,
s3Express: config.s3Express || "false",
};
}

const createS3Config = (): DatabaseConfig => {
const s3Config = validateS3Config({
bucket: process.env.AWS_BUCKET,
awsAccessKeyId: process.env.AWS_ACCESS_KEY_ID,
awsSecretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
region: process.env.AWS_REGION,
s3Express: "true",
});

return {
type: "s3",
options: s3Config,
};
};

const createLocalConfig = (): DatabaseConfig => {
return {
type: "local",
options: {
localDirectory: process.cwd(),
},
};
};

export const dbConfig = process.env.AWS_BUCKET
? createS3Config()
: createLocalConfig();

export const testConfig = createLocalConfig();
Loading

0 comments on commit 70cc866

Please sign in to comment.