exa-js 1.6.13 → 1.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +82 -42
- package/dist/index.d.mts +1874 -0
- package/dist/index.d.ts +66 -3
- package/dist/index.js +69 -29
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +65 -26
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,82 +8,91 @@ features associated with Metaphor's rename to Exa. New site is https://exa.ai
|
|
|
8
8
|
https://www.npmjs.com/package/exa-js
|
|
9
9
|
|
|
10
10
|
## Installation
|
|
11
|
+
|
|
11
12
|
```
|
|
12
13
|
npm install exa-js
|
|
13
14
|
```
|
|
14
15
|
|
|
15
|
-
## Initialization
|
|
16
|
+
## Initialization
|
|
17
|
+
|
|
16
18
|
```js
|
|
17
|
-
import Exa from "exa-js"
|
|
19
|
+
import Exa from "exa-js";
|
|
18
20
|
|
|
19
|
-
const exa = new Exa(process.env.EXA_API_KEY)
|
|
21
|
+
const exa = new Exa(process.env.EXA_API_KEY);
|
|
20
22
|
```
|
|
21
23
|
|
|
22
24
|
### Common commands
|
|
23
25
|
|
|
24
26
|
```js
|
|
25
|
-
|
|
26
27
|
// Basic search
|
|
27
28
|
const basicResults = await exa.search("This is a Exa query:");
|
|
28
29
|
|
|
29
|
-
// Autoprompted search
|
|
30
|
-
const autoPromptedResults = await exa.search("autopromptable query", { useAutoprompt: true });
|
|
31
|
-
|
|
32
30
|
// Search with date filters
|
|
33
31
|
const dateFilteredResults = await exa.search("This is a Exa query:", {
|
|
34
32
|
startPublishedDate: "2019-01-01",
|
|
35
|
-
endPublishedDate: "2019-01-31"
|
|
33
|
+
endPublishedDate: "2019-01-31",
|
|
36
34
|
});
|
|
37
35
|
|
|
38
36
|
// Search with domain filters
|
|
39
37
|
const domainFilteredResults = await exa.search("This is a Exa query:", {
|
|
40
|
-
includeDomains: ["www.cnn.com", "www.nytimes.com"]
|
|
38
|
+
includeDomains: ["www.cnn.com", "www.nytimes.com"],
|
|
41
39
|
});
|
|
42
40
|
|
|
43
41
|
// Search and get text contents
|
|
44
|
-
const searchAndTextResults = await exa.searchAndContents(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
42
|
+
const searchAndTextResults = await exa.searchAndContents(
|
|
43
|
+
"This is a Exa query:",
|
|
44
|
+
{ text: true }
|
|
45
|
+
);
|
|
48
46
|
|
|
49
47
|
// Search and get contents with contents options
|
|
50
|
-
const searchAndCustomContentsResults = await exa.searchAndContents(
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
48
|
+
const searchAndCustomContentsResults = await exa.searchAndContents(
|
|
49
|
+
"This is a Exa query:",
|
|
50
|
+
{
|
|
51
|
+
text: { maxCharacters: 3000 },
|
|
52
|
+
}
|
|
53
|
+
);
|
|
54
54
|
|
|
55
55
|
// Find similar documents
|
|
56
56
|
const similarResults = await exa.findSimilar("https://example.com");
|
|
57
57
|
|
|
58
58
|
// Find similar excluding source domain
|
|
59
|
-
const similarExcludingSourceResults = await exa.findSimilar(
|
|
59
|
+
const similarExcludingSourceResults = await exa.findSimilar(
|
|
60
|
+
"https://example.com",
|
|
61
|
+
{ excludeSourceDomain: true }
|
|
62
|
+
);
|
|
60
63
|
|
|
61
64
|
// Find similar with contents
|
|
62
|
-
const similarWithContentsResults = await exa.findSimilarAndContents(
|
|
65
|
+
const similarWithContentsResults = await exa.findSimilarAndContents(
|
|
66
|
+
"https://example.com",
|
|
67
|
+
{ text: true }
|
|
68
|
+
);
|
|
63
69
|
|
|
64
70
|
// Get text contents
|
|
65
71
|
const textContentsResults = await exa.getContents(["urls"], { text: true });
|
|
66
72
|
|
|
67
|
-
// Get highlights
|
|
68
|
-
const highlightsContentsResults = await exa.getContents(["urls"], { highlights: true });
|
|
69
|
-
|
|
70
73
|
// Get contents with contents options
|
|
71
74
|
const customContentsResults = await exa.getContents(["urls"], {
|
|
72
|
-
text: { includeHtmlTags: true, maxCharacters:
|
|
73
|
-
highlights: { highlightsPerUrl: 2, numSentences: 1, query: "This is the highlight query:" }
|
|
75
|
+
text: { includeHtmlTags: true, maxCharacters: 3000 },
|
|
74
76
|
});
|
|
75
77
|
|
|
76
78
|
// Get an answer to a question
|
|
77
|
-
const answerResult = await exa.answer(
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
79
|
+
const answerResult = await exa.answer(
|
|
80
|
+
"What is the population of New York City?"
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
// Get answer with citation contents and use the exa-pro model, which passes 2 extra queries to exa to increase coverage of the search space.
|
|
84
|
+
const answerWithTextResults = await exa.answer(
|
|
85
|
+
"What is the population of New York City?",
|
|
86
|
+
{
|
|
87
|
+
text: true,
|
|
88
|
+
model: "exa-pro",
|
|
89
|
+
}
|
|
90
|
+
);
|
|
84
91
|
|
|
85
92
|
// Get an answer with streaming
|
|
86
|
-
for await (const chunk of exa.streamAnswer(
|
|
93
|
+
for await (const chunk of exa.streamAnswer(
|
|
94
|
+
"What is the population of New York City?"
|
|
95
|
+
)) {
|
|
87
96
|
if (chunk.content) {
|
|
88
97
|
process.stdout.write(chunk.content);
|
|
89
98
|
}
|
|
@@ -91,45 +100,72 @@ for await (const chunk of exa.streamAnswer("What is the population of New York C
|
|
|
91
100
|
console.log("\nCitations:", chunk.citations);
|
|
92
101
|
}
|
|
93
102
|
}
|
|
103
|
+
|
|
104
|
+
// Get an answer with output schema
|
|
105
|
+
const answerResult = await exa.answer(
|
|
106
|
+
"What is the population of New York City?",
|
|
107
|
+
{
|
|
108
|
+
outputSchema: {
|
|
109
|
+
type: "object",
|
|
110
|
+
required: ["answer"],
|
|
111
|
+
additionalProperties: false,
|
|
112
|
+
properties: {
|
|
113
|
+
answer: {
|
|
114
|
+
type: "number",
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
}
|
|
119
|
+
);
|
|
94
120
|
```
|
|
95
121
|
|
|
96
122
|
### `exa.search(query: string, options?: SearchOptions): Promise<SearchResponse>`
|
|
123
|
+
|
|
97
124
|
Performs a search on the Exa system with the given parameters.
|
|
98
125
|
|
|
99
126
|
```javascript
|
|
100
|
-
const response = await exa.search(
|
|
127
|
+
const response = await exa.search("funny article about tech culture", {
|
|
101
128
|
numResults: 5,
|
|
102
|
-
includeDomains: [
|
|
103
|
-
startPublishedDate:
|
|
129
|
+
includeDomains: ["nytimes.com", "wsj.com"],
|
|
130
|
+
startPublishedDate: "2023-06-12",
|
|
104
131
|
});
|
|
105
132
|
```
|
|
106
133
|
|
|
107
134
|
### `exa.findSimilar(url: string, options?: FindSimilarOptions): Promise<SearchResponse>`
|
|
135
|
+
|
|
108
136
|
Finds content similar to the specified URL.
|
|
109
137
|
|
|
110
138
|
```javascript
|
|
111
|
-
const response = await exa.findSimilar(
|
|
112
|
-
|
|
113
|
-
|
|
139
|
+
const response = await exa.findSimilar(
|
|
140
|
+
"https://waitbutwhy.com/2014/05/fermi-paradox.html",
|
|
141
|
+
{
|
|
142
|
+
numResults: 10,
|
|
143
|
+
}
|
|
144
|
+
);
|
|
114
145
|
```
|
|
115
146
|
|
|
116
147
|
### `exa.getContents(urls: string[] | Result[]): Promise<GetContentsResponse>`
|
|
148
|
+
|
|
117
149
|
Retrieves the contents of the specified documents.
|
|
118
150
|
|
|
119
151
|
```javascript
|
|
120
|
-
const response = await exa.getContents([
|
|
152
|
+
const response = await exa.getContents([
|
|
153
|
+
"https://blog.samaltman.com/how-to-be-successful",
|
|
154
|
+
]);
|
|
121
155
|
```
|
|
122
156
|
|
|
123
157
|
### `exa.answer(query: string, options?: AnswerOptions): Promise<AnswerResponse>`
|
|
158
|
+
|
|
124
159
|
Generates an answer to a query using search results as context.
|
|
125
160
|
|
|
126
161
|
```javascript
|
|
127
|
-
const response = await exa.answer(
|
|
128
|
-
text: true
|
|
162
|
+
const response = await exa.answer("What is the population of New York City?", {
|
|
163
|
+
text: true,
|
|
129
164
|
});
|
|
130
165
|
```
|
|
131
166
|
|
|
132
167
|
### `exa.streamAnswer(query: string, options?: { text?: boolean }): AsyncGenerator<AnswerStreamChunk>`
|
|
168
|
+
|
|
133
169
|
Streams an answer as it's being generated, yielding chunks of text and citations. This is useful for providing real-time updates in chat interfaces or displaying partial results as they become available.
|
|
134
170
|
|
|
135
171
|
```javascript
|
|
@@ -143,13 +179,17 @@ for await (const chunk of exa.streamAnswer("What is quantum computing?")) {
|
|
|
143
179
|
}
|
|
144
180
|
}
|
|
145
181
|
|
|
146
|
-
for await (const chunk of exa.streamAnswer("What is quantum computing?", {
|
|
182
|
+
for await (const chunk of exa.streamAnswer("What is quantum computing?", {
|
|
183
|
+
text: true,
|
|
184
|
+
})) {
|
|
147
185
|
}
|
|
148
186
|
```
|
|
149
187
|
|
|
150
188
|
Each chunk contains:
|
|
189
|
+
|
|
151
190
|
- `content`: A string containing the next piece of generated text
|
|
152
191
|
- `citations`: An array of citation objects containing source information
|
|
153
192
|
|
|
154
193
|
# Contributing
|
|
194
|
+
|
|
155
195
|
Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.
|