Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nomic[patch]: Use Nomic SDK instead of rest api #4445

Merged
merged 1 commit into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libs/langchain-nomic/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# @langchain/nomic

This package contains the LangChain.js integrations for Nomic via their REST API.
This package contains the LangChain.js integrations for Nomic via the @nomic-ai/atlas package.

## Installation

Expand Down
1 change: 1 addition & 0 deletions libs/langchain-nomic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"license": "MIT",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there! 👋 I noticed that this PR adds a new dependency, "@nomic-ai/atlas", to the "dependencies" section. This change is flagged for maintainers to review the impact on peer/dev/hard dependencies. Keep up the great work! 🚀

"dependencies": {
"@langchain/core": "~0.1",
"@nomic-ai/atlas": "^0.8.0",
"uuid": "^9.0.1",
"weaviate-ts-client": "^2.0.0"
},
Expand Down
29 changes: 9 additions & 20 deletions libs/langchain-nomic/src/embeddings.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { getEnvironmentVariable } from "@langchain/core/utils/env";
import { Embeddings, type EmbeddingsParams } from "@langchain/core/embeddings";
import { chunkArray } from "@langchain/core/utils/chunk_array";
import { AtlasUser } from "@nomic-ai/atlas";

export type EmbeddingTaskType =
| "search_query"
Expand Down Expand Up @@ -70,9 +71,7 @@ export class NomicEmbeddings

stripNewLines = true;

endpoint = "https://api-atlas.nomic.ai";

apiKey: string;
client: AtlasUser;

dimensionality?: number;

Expand All @@ -88,12 +87,12 @@ export class NomicEmbeddings
if (!apiKey) {
throw new Error("NOMIC_API_KEY is required.");
}
this.client = new AtlasUser({ apiKey });
this.modelName = fields?.modelName ?? this.modelName;
this.taskType = fields?.taskType ?? this.taskType;
this.batchSize = fields?.batchSize ?? this.batchSize;
this.stripNewLines = fields?.stripNewLines ?? this.stripNewLines;
this.dimensionality = fields?.dimensionality;
this.apiKey = apiKey;
}

/**
Expand Down Expand Up @@ -142,23 +141,13 @@ export class NomicEmbeddings
input: string | Array<string>
): Promise<NomicEmbeddingsResult> {
return this.caller.call(async () => {
const res = await fetch(`${this.endpoint}/v1/embedding/text`, {
method: "POST",
body: JSON.stringify({
model: this.modelName,
texts: Array.isArray(input) ? input : [input],
task_type: this.taskType,
dimensionality: this.dimensionality,
}),
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${this.apiKey}`,
},
const result = await this.client.apiCall(`/v1/embedding/text`, "POST", {
model: this.modelName,
texts: Array.isArray(input) ? input : [input],
task_type: this.taskType,
dimensionality: this.dimensionality,
});
if (!res.ok) {
throw new Error(`Failed to generate embeddings: ${res.statusText}`);
}
return res.json();
return result;
});
}
}
40 changes: 40 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9527,6 +9527,7 @@ __metadata:
"@langchain/core": ~0.1
"@langchain/openai": "workspace:^"
"@langchain/scripts": ~0.0
"@nomic-ai/atlas": ^0.8.0
"@swc/core": ^1.3.90
"@swc/jest": ^0.2.29
"@tsconfig/recommended": ^1.0.3
Expand Down Expand Up @@ -9976,6 +9977,18 @@ __metadata:
languageName: node
linkType: hard

"@nomic-ai/atlas@npm:^0.8.0":
version: 0.8.0
resolution: "@nomic-ai/atlas@npm:0.8.0"
dependencies:
apache-arrow: ^12.0.1
dotenv: ^16.0.3
js-yaml: ^4.1.0
ts-md5: ^1.3.1
checksum: 19538f84a5dd9021870125879772e37925c730b75cb1716d619b8c014542503e93f843c04a32c1cab84dedd2ba797c108258453bb949b4bef0d7586290fb1337
languageName: node
linkType: hard

"@notionhq/client@npm:^2.2.10":
version: 2.2.10
resolution: "@notionhq/client@npm:2.2.10"
Expand Down Expand Up @@ -15972,6 +15985,26 @@ __metadata:
languageName: node
linkType: hard

"apache-arrow@npm:^12.0.1":
version: 12.0.1
resolution: "apache-arrow@npm:12.0.1"
dependencies:
"@types/command-line-args": 5.2.0
"@types/command-line-usage": 5.0.2
"@types/node": 18.14.5
"@types/pad-left": 2.1.1
command-line-args: 5.2.1
command-line-usage: 6.1.3
flatbuffers: 23.3.3
json-bignum: ^0.0.3
pad-left: ^2.1.0
tslib: ^2.5.0
bin:
arrow2csv: bin/arrow2csv.js
checksum: c753ccc5daeacd6c02ca51e263aa11fdffe3991a6bc9c6eb3a2d59a063c8738c48e55e3cb92cc43de588613f74d2975434a50e3f1130e01d136a406b6d282469
languageName: node
linkType: hard

"api_refs@workspace:docs/api_refs":
version: 0.0.0-use.local
resolution: "api_refs@workspace:docs/api_refs"
Expand Down Expand Up @@ -33659,6 +33692,13 @@ __metadata:
languageName: node
linkType: hard

"ts-md5@npm:^1.3.1":
version: 1.3.1
resolution: "ts-md5@npm:1.3.1"
checksum: 88fc4df837e17949fef92a8e71a0691b20e2f8b02a002876a162a102e7c9d364f1eb00cbd217f9578fec5fa07bb66ffa14ed054cdfe164486fab2173c8e9ea23
languageName: node
linkType: hard

"ts-mixer@npm:^6.0.3":
version: 6.0.3
resolution: "ts-mixer@npm:6.0.3"
Expand Down
Loading