Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ In separate terminal windows from project root:

On first boot and visiting of the homepage, you will be automatically redirected to create your primary admin account, organization, and database connection.


### Support for OpenAI Compatible API embedding model.
Use below variables in your server or docker .env settings.
```
OPENAI_BASE_PATH="https://api.openai.com/v1"
OPENAI_MODEL_NAME="text-embedding-ada-002"
MODEL_DIMENSIONS=1536
```

## Contributing
- create issue
- create PR with branch name format of `<issue number>-<short name>`
Expand Down
13 changes: 10 additions & 3 deletions backend/utils/openAi/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
const { Configuration, OpenAIApi } = require("openai");

class OpenAi {
constructor(apiKey = "") {
const config = new Configuration({ apiKey });
const basePath = process.env.OPENAI_BASE_PATH || "https://api.openai.com/v1";
const modelName = process.env.OPENAI_MODEL_NAME || "text-embedding-ada-002";
const config = new Configuration({
apiKey,
basePath,
});
const openai = new OpenAIApi(config);
this.openai = openai;
this.modelName = modelName;
}

async embedTextChunk(textChunk = "") {
const {
data: { data },
} = await this.openai.createEmbedding({
model: "text-embedding-ada-002",
model: this.modelName,
input: textChunk,
});
return data.length > 0 && data[0].hasOwnProperty("embedding")
Expand All @@ -22,7 +29,7 @@ class OpenAi {
const {
data: { data },
} = await this.openai.createEmbedding({
model: "text-embedding-ada-002",
model: this.modelName,
input: chunks,
});
return data.length > 0 &&
Expand Down
7 changes: 6 additions & 1 deletion docker/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@ JWT_SECRET="your-random-string-here"
INNGEST_EVENT_KEY="background_workers"
INNGEST_SIGNING_KEY="random-string-goes-here"
INNGEST_LANDING_PAGE="true"
DATABASE_CONNECTION_STRING="postgresql://vectoradmin:[email protected]:5433/vdbms"
DATABASE_CONNECTION_STRING="postgresql://vectoradmin:[email protected]:5433/vdbms"

## Support for OpenAI Compatible API model support.
# OPENAI_BASE_PATH="https://api.openai.com/v1"
# OPENAI_MODEL_NAME="text-embedding-ada-002"
# MODEL_DIMENSIONS=1536
8 changes: 7 additions & 1 deletion workers/.env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
INNGEST_EVENT_KEY="background_workers"
INNGEST_SIGNING_KEY=""
# DISABLE_TELEMETRY="true" # Uncomment to disable telemetry on workers for any ENV.
# DISABLE_TELEMETRY="true" # Uncomment to disable telemetry on workers for any ENV.

## Support for OpenAI Compatible API model support.

# OPENAI_BASE_PATH="https://api.openai.com/v1"
# OPENAI_MODEL_NAME="text-embedding-ada-002"
# MODEL_DIMENSIONS=1536
2 changes: 1 addition & 1 deletion workers/functions/newWorkspace/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const newWorkspaceCreated = InngestClient.createFunction(
workspace.fname,
{
vectors: {
size: 1536, // TODO: Fixed to OpenAI models - when other embeddings exist make variable.
size: parseInt(process.env.MODEL_DIMENSIONS) || 1536, // TODO: Fixed to OpenAI models - when other embeddings exist make variable.
distance: 'Cosine',
},
}
Expand Down