feat: Improve memory embedding and vector store handling

This commit includes the following improvements:

- Update the `memoryEmbedding` function to use the `PAMemoryVectorStore` instead of the generic `MemoryVectorStore`. This ensures that the vector store is specifically designed for the Page Assist application.
- Modify the `useMessage` hook to use the `PAMemoryVectorStore` type for the `keepTrackOfEmbedding` state.
- Update the `rerankDocs` function to use the `EmbeddingsInterface` type instead of the deprecated `Embeddings` type.
- Add a new `PageAssistVectorStore` class that extends the `VectorStore` interface and provides a custom implementation for the Page Assist application.

These changes improve the handling of memory embeddings and vector stores, ensuring better compatibility and performance within the Page Assist application.
This commit is contained in:
n4ze3m
2024-11-16 19:33:51 +05:30
parent 64e88bd493
commit ca26e059eb
5 changed files with 116 additions and 11 deletions

View File

@@ -34,6 +34,8 @@ import { pageAssistModel } from "@/models"
import { getPrompt } from "@/services/application"
import { humanMessageFormatter } from "@/utils/human-message"
import { pageAssistEmbeddingModel } from "@/models/embedding"
import { PageAssistVectorStore } from "@/libs/PageAssistVectorStore"
import { PAMemoryVectorStore } from "@/libs/PAMemoryVectorStore"
export const useMessage = () => {
const {
@@ -90,7 +92,7 @@ export const useMessage = () => {
)
const [keepTrackOfEmbedding, setKeepTrackOfEmbedding] = React.useState<{
[key: string]: MemoryVectorStore
[key: string]: PAMemoryVectorStore
}>({})
const clearChat = () => {
@@ -177,7 +179,7 @@ export const useMessage = () => {
let embedURL: string, embedHTML: string, embedType: string
let embedPDF: { content: string; page: number }[] = []
let isAlreadyExistEmbedding: MemoryVectorStore
let isAlreadyExistEmbedding: PAMemoryVectorStore
const {
content: html,
url: websiteUrl,
@@ -212,7 +214,7 @@ export const useMessage = () => {
currentChatModelSettings?.keepAlive ??
userDefaultModelSettings?.keepAlive
})
let vectorstore: MemoryVectorStore
let vectorstore: PAMemoryVectorStore
try {
if (isAlreadyExistEmbedding) {