feat(agents): embed docs & query together
Embed documents and query together to reduce the time taken for retrieving the sources ~1 seconds.
This commit is contained in:
parent
3b66808e7d
commit
99ae8f6998
|
@ -9,6 +9,7 @@ services:
|
||||||
- 4000:8080
|
- 4000:8080
|
||||||
networks:
|
networks:
|
||||||
- perplexica-network
|
- perplexica-network
|
||||||
|
|
||||||
perplexica-backend:
|
perplexica-backend:
|
||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
|
|
|
@ -166,11 +166,10 @@ const createBasicAcademicSearchAnsweringChain = (
|
||||||
(doc) => doc.pageContent && doc.pageContent.length > 0,
|
(doc) => doc.pageContent && doc.pageContent.length > 0,
|
||||||
);
|
);
|
||||||
|
|
||||||
const docEmbeddings = await embeddings.embedDocuments(
|
const [docEmbeddings, queryEmbedding] = await Promise.all([
|
||||||
docsWithContent.map((doc) => doc.pageContent),
|
embeddings.embedDocuments(docsWithContent.map((doc) => doc.pageContent)),
|
||||||
);
|
embeddings.embedQuery(query),
|
||||||
|
]);
|
||||||
const queryEmbedding = await embeddings.embedQuery(query);
|
|
||||||
|
|
||||||
const similarity = docEmbeddings.map((docEmbedding, i) => {
|
const similarity = docEmbeddings.map((docEmbedding, i) => {
|
||||||
const sim = computeSimilarity(queryEmbedding, docEmbedding);
|
const sim = computeSimilarity(queryEmbedding, docEmbedding);
|
||||||
|
|
|
@ -161,11 +161,10 @@ const createBasicRedditSearchAnsweringChain = (
|
||||||
(doc) => doc.pageContent && doc.pageContent.length > 0,
|
(doc) => doc.pageContent && doc.pageContent.length > 0,
|
||||||
);
|
);
|
||||||
|
|
||||||
const docEmbeddings = await embeddings.embedDocuments(
|
const [docEmbeddings, queryEmbedding] = await Promise.all([
|
||||||
docsWithContent.map((doc) => doc.pageContent),
|
embeddings.embedDocuments(docsWithContent.map((doc) => doc.pageContent)),
|
||||||
);
|
embeddings.embedQuery(query),
|
||||||
|
]);
|
||||||
const queryEmbedding = await embeddings.embedQuery(query);
|
|
||||||
|
|
||||||
const similarity = docEmbeddings.map((docEmbedding, i) => {
|
const similarity = docEmbeddings.map((docEmbedding, i) => {
|
||||||
const sim = computeSimilarity(queryEmbedding, docEmbedding);
|
const sim = computeSimilarity(queryEmbedding, docEmbedding);
|
||||||
|
|
|
@ -159,11 +159,10 @@ const createBasicWebSearchAnsweringChain = (
|
||||||
(doc) => doc.pageContent && doc.pageContent.length > 0,
|
(doc) => doc.pageContent && doc.pageContent.length > 0,
|
||||||
);
|
);
|
||||||
|
|
||||||
const docEmbeddings = await embeddings.embedDocuments(
|
const [docEmbeddings, queryEmbedding] = await Promise.all([
|
||||||
docsWithContent.map((doc) => doc.pageContent),
|
embeddings.embedDocuments(docsWithContent.map((doc) => doc.pageContent)),
|
||||||
);
|
embeddings.embedQuery(query),
|
||||||
|
]);
|
||||||
const queryEmbedding = await embeddings.embedQuery(query);
|
|
||||||
|
|
||||||
const similarity = docEmbeddings.map((docEmbedding, i) => {
|
const similarity = docEmbeddings.map((docEmbedding, i) => {
|
||||||
const sim = computeSimilarity(queryEmbedding, docEmbedding);
|
const sim = computeSimilarity(queryEmbedding, docEmbedding);
|
||||||
|
|
|
@ -161,11 +161,10 @@ const createBasicYoutubeSearchAnsweringChain = (
|
||||||
(doc) => doc.pageContent && doc.pageContent.length > 0,
|
(doc) => doc.pageContent && doc.pageContent.length > 0,
|
||||||
);
|
);
|
||||||
|
|
||||||
const docEmbeddings = await embeddings.embedDocuments(
|
const [docEmbeddings, queryEmbedding] = await Promise.all([
|
||||||
docsWithContent.map((doc) => doc.pageContent),
|
embeddings.embedDocuments(docsWithContent.map((doc) => doc.pageContent)),
|
||||||
);
|
embeddings.embedQuery(query),
|
||||||
|
]);
|
||||||
const queryEmbedding = await embeddings.embedQuery(query);
|
|
||||||
|
|
||||||
const similarity = docEmbeddings.map((docEmbedding, i) => {
|
const similarity = docEmbeddings.map((docEmbedding, i) => {
|
||||||
const sim = computeSimilarity(queryEmbedding, docEmbedding);
|
const sim = computeSimilarity(queryEmbedding, docEmbedding);
|
||||||
|
|
Loading…
Reference in New Issue