Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Anything Llm
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
MachineLearning
Mintplex Labs
Anything Llm
Commits
cfcd14a3
Commit
cfcd14a3
authored
1 year ago
by
timothycarambat
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' of github.com:Mintplex-Labs/anything-llm
parents
4f8abeb7
2a28415d
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
server/utils/AiProviders/azureOpenAi/index.js
+49
-4
49 additions, 4 deletions
server/utils/AiProviders/azureOpenAi/index.js
server/utils/vectorDbProviders/pinecone/index.js
+6
-4
6 additions, 4 deletions
server/utils/vectorDbProviders/pinecone/index.js
with
55 additions
and
8 deletions
server/utils/AiProviders/azureOpenAi/index.js
+
49
−
4
View file @
cfcd14a3
const
{
toChunks
}
=
require
(
"
../../helpers
"
);
class
AzureOpenAi
{
constructor
()
{
const
{
OpenAIClient
,
AzureKeyCredential
}
=
require
(
"
@azure/openai
"
);
...
...
@@ -6,6 +8,10 @@ class AzureOpenAi {
new
AzureKeyCredential
(
process
.
env
.
AZURE_OPENAI_KEY
)
);
this
.
openai
=
openai
;
// The maximum amount of "inputs" that OpenAI API can process in a single call.
// https://learn.microsoft.com/en-us/azure/ai-services/openai/faq#i-am-trying-to-use-embeddings-and-received-the-error--invalidrequesterror--too-many-inputs--the-max-number-of-inputs-is-1---how-do-i-fix-this-:~:text=consisting%20of%20up%20to%2016%20inputs%20per%20API%20request
this
.
embeddingChunkLimit
=
16
;
}
isValidChatModel
(
_modelName
=
""
)
{
...
...
@@ -83,10 +89,49 @@ class AzureOpenAi {
"
No EMBEDDING_MODEL_PREF ENV defined. This must the name of a deployment on your Azure account for an embedding model.
"
);
const
{
data
=
[]
}
=
await
this
.
openai
.
getEmbeddings
(
textEmbeddingModel
,
textChunks
);
// Because there is a limit on how many chunks can be sent at once to Azure OpenAI
// we concurrently execute each max batch of text chunks possible.
// Refer to constructor embeddingChunkLimit for more info.
const
embeddingRequests
=
[];
for
(
const
chunk
of
toChunks
(
textChunks
,
this
.
embeddingChunkLimit
))
{
embeddingRequests
.
push
(
new
Promise
((
resolve
)
=>
{
this
.
openai
.
getEmbeddings
(
textEmbeddingModel
,
chunk
)
.
then
((
res
)
=>
{
resolve
({
data
:
res
.
data
,
error
:
null
});
})
.
catch
((
e
)
=>
{
resolve
({
data
:
[],
error
:
e
?.
error
});
});
})
);
}
const
{
data
=
[],
error
=
null
}
=
await
Promise
.
all
(
embeddingRequests
).
then
((
results
)
=>
{
// If any errors were returned from Azure abort the entire sequence because the embeddings
// will be incomplete.
const
errors
=
results
.
filter
((
res
)
=>
!!
res
.
error
)
.
map
((
res
)
=>
res
.
error
)
.
flat
();
if
(
errors
.
length
>
0
)
{
return
{
data
:
[],
error
:
`(
${
errors
.
length
}
) Embedding Errors!
${
errors
.
map
((
error
)
=>
`[
${
error
.
type
}
]:
${
error
.
message
}
`
)
.
join
(
"
,
"
)}
`
,
};
}
return
{
data
:
results
.
map
((
res
)
=>
res
?.
data
||
[]).
flat
(),
error
:
null
,
};
});
if
(
!!
error
)
throw
new
Error
(
`Azure OpenAI Failed to embed:
${
error
}
`
);
return
data
.
length
>
0
&&
data
.
every
((
embd
)
=>
embd
.
hasOwnProperty
(
"
embedding
"
))
?
data
.
map
((
embd
)
=>
embd
.
embedding
)
...
...
This diff is collapsed.
Click to expand it.
server/utils/vectorDbProviders/pinecone/index.js
+
6
−
4
View file @
cfcd14a3
...
...
@@ -186,10 +186,12 @@ const Pinecone = {
if
(
knownDocuments
.
length
===
0
)
return
;
const
vectorIds
=
knownDocuments
.
map
((
doc
)
=>
doc
.
vectorId
);
await
pineconeIndex
.
delete1
({
ids
:
vectorIds
,
namespace
,
});
for
(
const
batchOfVectorIds
of
toChunks
(
vectorIds
,
1000
))
{
await
pineconeIndex
.
delete1
({
ids
:
batchOfVectorIds
,
namespace
,
});
}
const
indexes
=
knownDocuments
.
map
((
doc
)
=>
doc
.
id
);
await
DocumentVectors
.
deleteIds
(
indexes
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment