Skip to content

Commit

Permalink
Add embedding support for message.content which is string/object arra…
Browse files Browse the repository at this point in the history
…y type
  • Loading branch information
hehua2008 committed Jan 28, 2025
1 parent 4bdd921 commit a5d6675
Show file tree
Hide file tree
Showing 8 changed files with 169 additions and 9 deletions.
22 changes: 21 additions & 1 deletion server/utils/vectorDbProviders/astra/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,27 @@ const AstraDB = {
};
}

const queryVector = await LLMConnector.embedTextInput(input);
let textInput = "";
if (typeof input === "string" || input instanceof String) {
textInput = input;
} else if (Array.isArray(input)) {
textInput = input.map((x) => {
if (typeof x === "string" || x instanceof String) {
return x + "\n";
} else if (typeof x.text === "string" || x.text instanceof String) {
return x.text + "\n";
} else {
return "";
}
});
} else {
return {
contextTexts: [],
sources: [],
message: `Invalid query - the type of input is not string but ${typeof input} !`,
};
}
const queryVector = await LLMConnector.embedTextInput(textInput);
const { contextTexts, sourceDocuments } = await this.similarityResponse({
client,
namespace,
Expand Down
22 changes: 21 additions & 1 deletion server/utils/vectorDbProviders/chroma/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,27 @@ const Chroma = {
};
}

const queryVector = await LLMConnector.embedTextInput(input);
let textInput = "";
if (typeof input === "string" || input instanceof String) {
textInput = input;
} else if (Array.isArray(input)) {
textInput = input.map((x) => {
if (typeof x === "string" || x instanceof String) {
return x + "\n";
} else if (typeof x.text === "string" || x.text instanceof String) {
return x.text + "\n";
} else {
return "";
}
});
} else {
return {
contextTexts: [],
sources: [],
message: `Invalid query - the type of input is not string but ${typeof input} !`,
};
}
const queryVector = await LLMConnector.embedTextInput(textInput);
const { contextTexts, sourceDocuments } = await this.similarityResponse({
client,
namespace,
Expand Down
24 changes: 22 additions & 2 deletions server/utils/vectorDbProviders/lance/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,12 +400,32 @@ const LanceDb = {
};
}

const queryVector = await LLMConnector.embedTextInput(input);
let textInput = "";
if (typeof input === "string" || input instanceof String) {
textInput = input;
} else if (Array.isArray(input)) {
textInput = input.map((x) => {
if (typeof x === "string" || x instanceof String) {
return x + "\n";
} else if (typeof x.text === "string" || x.text instanceof String) {
return x.text + "\n";
} else {
return "";
}
});
} else {
return {
contextTexts: [],
sources: [],
message: `Invalid query - the type of input is not string but ${typeof input} !`,
};
}
const queryVector = await LLMConnector.embedTextInput(textInput);
const result = rerank
? await this.rerankedSimilarityResponse({
client,
namespace,
query: input,
query: textInput,
queryVector,
similarityThreshold,
topN,
Expand Down
22 changes: 21 additions & 1 deletion server/utils/vectorDbProviders/milvus/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,27 @@ const Milvus = {
};
}

const queryVector = await LLMConnector.embedTextInput(input);
let textInput = "";
if (typeof input === "string" || input instanceof String) {
textInput = input;
} else if (Array.isArray(input)) {
textInput = input.map((x) => {
if (typeof x === "string" || x instanceof String) {
return x + "\n";
} else if (typeof x.text === "string" || x.text instanceof String) {
return x.text + "\n";
} else {
return "";
}
});
} else {
return {
contextTexts: [],
sources: [],
message: `Invalid query - the type of input is not string but ${typeof input} !`,
};
}
const queryVector = await LLMConnector.embedTextInput(textInput);
const { contextTexts, sourceDocuments } = await this.similarityResponse({
client,
namespace,
Expand Down
22 changes: 21 additions & 1 deletion server/utils/vectorDbProviders/pinecone/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,27 @@ const PineconeDB = {
"Invalid namespace - has it been collected and populated yet?"
);

const queryVector = await LLMConnector.embedTextInput(input);
let textInput = "";
if (typeof input === "string" || input instanceof String) {
textInput = input;
} else if (Array.isArray(input)) {
textInput = input.map((x) => {
if (typeof x === "string" || x instanceof String) {
return x + "\n";
} else if (typeof x.text === "string" || x.text instanceof String) {
return x.text + "\n";
} else {
return "";
}
});
} else {
return {
contextTexts: [],
sources: [],
message: `Invalid query - the type of input is not string but ${typeof input} !`,
};
}
const queryVector = await LLMConnector.embedTextInput(textInput);
const { contextTexts, sourceDocuments } = await this.similarityResponse({
client: pineconeIndex,
namespace,
Expand Down
22 changes: 21 additions & 1 deletion server/utils/vectorDbProviders/qdrant/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,27 @@ const QDrant = {
};
}

const queryVector = await LLMConnector.embedTextInput(input);
let textInput = "";
if (typeof input === "string" || input instanceof String) {
textInput = input;
} else if (Array.isArray(input)) {
textInput = input.map((x) => {
if (typeof x === "string" || x instanceof String) {
return x + "\n";
} else if (typeof x.text === "string" || x.text instanceof String) {
return x.text + "\n";
} else {
return "";
}
});
} else {
return {
contextTexts: [],
sources: [],
message: `Invalid query - the type of input is not string but ${typeof input} !`,
};
}
const queryVector = await LLMConnector.embedTextInput(textInput);
const { contextTexts, sourceDocuments } = await this.similarityResponse({
client,
namespace,
Expand Down
22 changes: 21 additions & 1 deletion server/utils/vectorDbProviders/weaviate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,27 @@ const Weaviate = {
};
}

const queryVector = await LLMConnector.embedTextInput(input);
let textInput = "";
if (typeof input === "string" || input instanceof String) {
textInput = input;
} else if (Array.isArray(input)) {
textInput = input.map((x) => {
if (typeof x === "string" || x instanceof String) {
return x + "\n";
} else if (typeof x.text === "string" || x.text instanceof String) {
return x.text + "\n";
} else {
return "";
}
});
} else {
return {
contextTexts: [],
sources: [],
message: `Invalid query - the type of input is not string but ${typeof input} !`,
};
}
const queryVector = await LLMConnector.embedTextInput(textInput);
const { contextTexts, sourceDocuments } = await this.similarityResponse({
client,
namespace,
Expand Down
22 changes: 21 additions & 1 deletion server/utils/vectorDbProviders/zilliz/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,27 @@ const Zilliz = {
};
}

const queryVector = await LLMConnector.embedTextInput(input);
let textInput = "";
if (typeof input === "string" || input instanceof String) {
textInput = input;
} else if (Array.isArray(input)) {
textInput = input.map((x) => {
if (typeof x === "string" || x instanceof String) {
return x + "\n";
} else if (typeof x.text === "string" || x.text instanceof String) {
return x.text + "\n";
} else {
return "";
}
});
} else {
return {
contextTexts: [],
sources: [],
message: `Invalid query - the type of input is not string but ${typeof input} !`,
};
}
const queryVector = await LLMConnector.embedTextInput(textInput);
const { contextTexts, sourceDocuments } = await this.similarityResponse({
client,
namespace,
Expand Down

0 comments on commit a5d6675

Please sign in to comment.