mirror of
https://github.com/logancyang/obsidian-copilot.git
synced 2026-07-22 07:50:24 +00:00
Embeddings enhancements (#651)
* Add Google embedding support * Update dependencies
This commit is contained in:
parent
59068fa494
commit
7bb74f9279
11 changed files with 505 additions and 664 deletions
1110
package-lock.json
generated
1110
package-lock.json
generated
File diff suppressed because it is too large
Load diff
15
package.json
15
package.json
|
|
@ -29,7 +29,7 @@
|
|||
},
|
||||
"license": "AGPL-3.0",
|
||||
"devDependencies": {
|
||||
"@langchain/ollama": "^0.0.4",
|
||||
"@langchain/ollama": "^0.1.0",
|
||||
"@testing-library/jest-dom": "^5.16.5",
|
||||
"@testing-library/react": "^14.0.0",
|
||||
"@types/crypto-js": "^4.1.1",
|
||||
|
|
@ -63,11 +63,12 @@
|
|||
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
|
||||
"@huggingface/inference": "^2.6.4",
|
||||
"@koa/cors": "^5.0.0",
|
||||
"@langchain/anthropic": "^0.1.21",
|
||||
"@langchain/cohere": "^0.0.11",
|
||||
"@langchain/community": "^0.0.16",
|
||||
"@langchain/google-genai": "^0.0.7",
|
||||
"@langchain/groq": "^0.0.9",
|
||||
"@langchain/anthropic": "^0.3.3",
|
||||
"@langchain/cohere": "^0.3.0",
|
||||
"@langchain/community": "^0.3.3",
|
||||
"@langchain/core": "^0.3.3",
|
||||
"@langchain/google-genai": "^0.1.0",
|
||||
"@langchain/groq": "^0.1.2",
|
||||
"@tabler/icons-react": "^2.14.0",
|
||||
"@types/pouchdb": "^6.4.0",
|
||||
"axios": "^1.3.4",
|
||||
|
|
@ -78,7 +79,7 @@
|
|||
"eventsource-parser": "^1.0.0",
|
||||
"koa": "^2.14.2",
|
||||
"koa-proxies": "^0.12.3",
|
||||
"langchain": "^0.0.212",
|
||||
"langchain": "^0.3.2",
|
||||
"next-i18next": "^13.2.2",
|
||||
"pouchdb-browser": "^9.0.0",
|
||||
"prop-types": "^15.8.1",
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ import {
|
|||
ChatPromptTemplate,
|
||||
HumanMessagePromptTemplate,
|
||||
MessagesPlaceholder,
|
||||
} from "langchain/prompts";
|
||||
} from "@langchain/core/prompts";
|
||||
import { MultiQueryRetriever } from "langchain/retrievers/multi_query";
|
||||
import { MemoryVectorStore } from "langchain/vectorstores/memory";
|
||||
import { App, Notice } from "obsidian";
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ import { ChatCohere } from "@langchain/cohere";
|
|||
import { ChatGoogleGenerativeAI } from "@langchain/google-genai";
|
||||
import { ChatGroq } from "@langchain/groq";
|
||||
import { ChatOllama } from "@langchain/ollama";
|
||||
import { BaseChatModel } from "langchain/chat_models/base";
|
||||
import { ChatOpenAI } from "langchain/chat_models/openai";
|
||||
import { BaseChatModel } from "@langchain/core/language_models/chat_models";
|
||||
import { ChatOpenAI } from "@langchain/openai";
|
||||
import { Notice } from "obsidian";
|
||||
|
||||
export default class ChatModelManager {
|
||||
|
|
|
|||
|
|
@ -4,9 +4,10 @@ import { EmbeddingModelProviders } from "@/constants";
|
|||
import EncryptionService from "@/encryptionService";
|
||||
import { ProxyOpenAIEmbeddings } from "@/langchainWrappers";
|
||||
import { CohereEmbeddings } from "@langchain/cohere";
|
||||
import { Embeddings } from "langchain/embeddings/base";
|
||||
import { OllamaEmbeddings } from "langchain/embeddings/ollama";
|
||||
import { OpenAIEmbeddings } from "langchain/embeddings/openai";
|
||||
import { GoogleGenerativeAIEmbeddings } from "@langchain/google-genai";
|
||||
import { Embeddings } from "@langchain/core/embeddings";
|
||||
import { OllamaEmbeddings } from "@langchain/community/embeddings/ollama";
|
||||
import { OpenAIEmbeddings } from "@langchain/openai";
|
||||
export default class EmbeddingManager {
|
||||
private encryptionService: EncryptionService;
|
||||
private activeEmbeddingModels: CustomModel[];
|
||||
|
|
@ -66,6 +67,10 @@ export default class EmbeddingManager {
|
|||
constructor = CohereEmbeddings;
|
||||
apiKey = params.cohereApiKey;
|
||||
break;
|
||||
case EmbeddingModelProviders.GOOGLE:
|
||||
constructor = GoogleGenerativeAIEmbeddings;
|
||||
apiKey = params.googleApiKey;
|
||||
break;
|
||||
case EmbeddingModelProviders.AZURE_OPENAI:
|
||||
constructor = OpenAIEmbeddings;
|
||||
apiKey = params.azureOpenAIApiKey;
|
||||
|
|
@ -158,6 +163,10 @@ export default class EmbeddingManager {
|
|||
model: modelName,
|
||||
apiKey: decrypt(params.cohereApiKey),
|
||||
},
|
||||
[EmbeddingModelProviders.GOOGLE]: {
|
||||
modelName: modelName,
|
||||
apiKey: decrypt(params.googleApiKey),
|
||||
},
|
||||
[EmbeddingModelProviders.AZURE_OPENAI]: {
|
||||
azureOpenAIApiKey: decrypt(params.azureOpenAIApiKey),
|
||||
azureOpenAIApiInstanceName: params.azureOpenAIApiInstanceName,
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import {
|
|||
HumanMessagePromptTemplate,
|
||||
MessagesPlaceholder,
|
||||
SystemMessagePromptTemplate,
|
||||
} from "langchain/prompts";
|
||||
} from "@langchain/core/prompts";
|
||||
|
||||
export default class PromptManager {
|
||||
private static instance: PromptManager;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { ChainType } from "@/chainFactory";
|
||||
import { ChatPromptTemplate } from "langchain/prompts";
|
||||
import { ChatPromptTemplate } from "@langchain/core/prompts";
|
||||
import { NoteFile } from "./vectorDBManager";
|
||||
|
||||
export interface ModelConfig {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import { StringOutputParser } from "@langchain/core/output_parsers";
|
||||
import { BaseRetriever } from "@langchain/core/retrievers";
|
||||
import { RunnablePassthrough, RunnableSequence } from "@langchain/core/runnables";
|
||||
import { BaseLanguageModel } from "langchain/base_language";
|
||||
import { BaseLanguageModel } from "@langchain/core/language_models/base";
|
||||
import { BaseChatMemory } from "langchain/memory";
|
||||
import { ChatPromptTemplate, PromptTemplate } from "langchain/prompts";
|
||||
import { ChatPromptTemplate, PromptTemplate } from "@langchain/core/prompts";
|
||||
import { formatDocumentsAsString } from "langchain/util/document";
|
||||
|
||||
export interface LLMChainInput {
|
||||
|
|
|
|||
|
|
@ -102,6 +102,7 @@ export const BUILTIN_CHAT_MODELS: CustomModel[] = [
|
|||
export enum EmbeddingModelProviders {
|
||||
OPENAI = "openai",
|
||||
COHEREAI = "cohereai",
|
||||
GOOGLE = "google",
|
||||
AZURE_OPENAI = "azure_openai",
|
||||
OLLAMA = "ollama",
|
||||
OPENAI_FORMAT = "3rd party (openai-format)",
|
||||
|
|
@ -115,6 +116,7 @@ export enum EmbeddingModels {
|
|||
OPENAI_EMBEDDING_LARGE = "text-embedding-3-large",
|
||||
AZURE_OPENAI = "azure-openai",
|
||||
COHEREAI_EMBED_MULTILINGUAL_LIGHT_V3_0 = "embed-multilingual-light-v3.0",
|
||||
GOOGLE_ENG = "text-embedding-004",
|
||||
}
|
||||
|
||||
export const BUILTIN_EMBEDDING_MODELS: CustomModel[] = [
|
||||
|
|
@ -140,6 +142,13 @@ export const BUILTIN_EMBEDDING_MODELS: CustomModel[] = [
|
|||
isBuiltIn: true,
|
||||
isEmbeddingModel: true,
|
||||
},
|
||||
{
|
||||
name: EmbeddingModels.GOOGLE_ENG,
|
||||
provider: EmbeddingModelProviders.GOOGLE,
|
||||
enabled: true,
|
||||
isBuiltIn: true,
|
||||
isEmbeddingModel: true,
|
||||
},
|
||||
{
|
||||
name: EmbeddingModels.AZURE_OPENAI,
|
||||
provider: EmbeddingModelProviders.AZURE_OPENAI,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import { AnthropicInput, ChatAnthropic } from "@langchain/anthropic";
|
||||
import { ChatOpenAI } from "langchain/chat_models/openai";
|
||||
import { OpenAIEmbeddings } from "langchain/embeddings/openai";
|
||||
import { ChatOpenAI } from "@langchain/openai";
|
||||
import { OpenAIEmbeddings } from "@langchain/openai";
|
||||
import { requestUrl } from "obsidian";
|
||||
import OpenAI from "openai";
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { MD5 } from "crypto-js";
|
||||
import { Document } from "langchain/document";
|
||||
import { Embeddings } from "langchain/embeddings/base";
|
||||
import { Embeddings } from "@langchain/core/embeddings";
|
||||
import { RecursiveCharacterTextSplitter } from "langchain/text_splitter";
|
||||
import { MemoryVectorStore } from "langchain/vectorstores/memory";
|
||||
import EmbeddingManager from "./LLMProviders/embeddingManager";
|
||||
|
|
|
|||
Loading…
Reference in a new issue