Skip to content

Commit a14ae7b

Browse files
authored
docs[patch]: Adds vector store and tool docstrings (#6521)
1 parent 9ceaa03 commit a14ae7b

File tree

12 files changed

+788
-47
lines changed

12 files changed

+788
-47
lines changed

docs/core_docs/docs/integrations/tools/duckduckgo_search.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"### Integration details\n",
3131
"\n",
3232
"| Class | Package | [PY support](https://python.langchain.com/docs/integrations/tools/ddg/) | Package latest |\n",
33-
"| :--- | :--- | :---: | :---: | :---: |\n",
33+
"| :--- | :--- | :---: | :---: |\n",
3434
"| [DuckDuckGoSearch](https://api.js.langchain.com/classes/langchain_community_tools_duckduckgo_search.DuckDuckGoSearch.html) | [`@langchain/community`](https://www.npmjs.com/package/@langchain/community) | ✅ | ![NPM - Version](https://img.shields.io/npm/v/@langchain/community?style=flat-square&label=%20&) |\n",
3535
"\n",
3636
"## Setup\n",

docs/core_docs/docs/integrations/tools/tavily_search.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"### Integration details\n",
3131
"\n",
3232
"| Class | Package | [PY support](https://python.langchain.com/v0.2/docs/integrations/tools/tavily_search/) | Package latest |\n",
33-
"| :--- | :--- | :---: | :---: | :---: |\n",
33+
"| :--- | :--- | :---: | :---: |\n",
3434
"| [TavilySearchResults](https://api.js.langchain.com/classes/langchain_community_tools_tavily_search.TavilySearchResults.html) | [`@langchain/community`](https://www.npmjs.com/package/@langchain/community) | ✅ | ![NPM - Version](https://img.shields.io/npm/v/@langchain/community?style=flat-square&label=%20&) |\n",
3535
"\n",
3636
"## Setup\n",

docs/core_docs/docs/integrations/vectorstores/memory.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"id": "ef1f0986",
2020
"metadata": {},
2121
"source": [
22-
"# `MemoryVectorStore`\n",
22+
"# MemoryVectorStore\n",
2323
"\n",
2424
"LangChain offers is an in-memory, ephemeral vectorstore that stores embeddings in-memory and does an exact, linear search for the most similar embeddings. The default similarity metric is cosine similarity, but can be changed to any of the similarity metrics supported by [ml-distance](https://mljs.github.io/distance/modules/similarity.html).\n",
2525
"\n",

langchain/src/vectorstores/memory.ts

+108-3
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,114 @@ export interface MemoryVectorStoreArgs {
2929
}
3030

3131
/**
32-
* Class that extends `VectorStore` to store vectors in memory. Provides
33-
* methods for adding documents, performing similarity searches, and
34-
* creating instances from texts, documents, or an existing index.
32+
* In-memory, ephemeral vector store.
33+
*
34+
* Setup:
35+
* Install `langchain`:
36+
*
37+
* ```bash
38+
* npm install langchain
39+
* ```
40+
*
41+
* ## [Constructor args](https://api.js.langchain.com/classes/langchain.vectorstores_memory.MemoryVectorStore.html#constructor)
42+
*
43+
* <details open>
44+
* <summary><strong>Instantiate</strong></summary>
45+
*
46+
* ```typescript
47+
* import { MemoryVectorStore } from 'langchain/vectorstores/memory';
48+
* // Or other embeddings
49+
* import { OpenAIEmbeddings } from '@langchain/openai';
50+
*
51+
* const embeddings = new OpenAIEmbeddings({
52+
* model: "text-embedding-3-small",
53+
* });
54+
*
55+
* const vectorStore = new MemoryVectorStore(embeddings);
56+
* ```
57+
* </details>
58+
*
59+
* <br />
60+
*
61+
* <details>
62+
* <summary><strong>Add documents</strong></summary>
63+
*
64+
* ```typescript
65+
* import type { Document } from '@langchain/core/documents';
66+
*
67+
* const document1 = { pageContent: "foo", metadata: { baz: "bar" } };
68+
* const document2 = { pageContent: "thud", metadata: { bar: "baz" } };
69+
* const document3 = { pageContent: "i will be deleted :(", metadata: {} };
70+
*
71+
* const documents: Document[] = [document1, document2, document3];
72+
*
73+
* await vectorStore.addDocuments(documents);
74+
* ```
75+
* </details>
76+
*
77+
* <br />
78+
*
79+
* <details>
80+
* <summary><strong>Similarity search</strong></summary>
81+
*
82+
* ```typescript
83+
* const results = await vectorStore.similaritySearch("thud", 1);
84+
* for (const doc of results) {
85+
* console.log(`* ${doc.pageContent} [${JSON.stringify(doc.metadata, null)}]`);
86+
* }
87+
* // Output: * thud [{"baz":"bar"}]
88+
* ```
89+
* </details>
90+
*
91+
* <br />
92+
*
93+
*
94+
* <details>
95+
* <summary><strong>Similarity search with filter</strong></summary>
96+
*
97+
* ```typescript
98+
* const resultsWithFilter = await vectorStore.similaritySearch("thud", 1, { baz: "bar" });
99+
*
100+
* for (const doc of resultsWithFilter) {
101+
* console.log(`* ${doc.pageContent} [${JSON.stringify(doc.metadata, null)}]`);
102+
* }
103+
* // Output: * foo [{"baz":"bar"}]
104+
* ```
105+
* </details>
106+
*
107+
* <br />
108+
*
109+
*
110+
* <details>
111+
* <summary><strong>Similarity search with score</strong></summary>
112+
*
113+
* ```typescript
114+
* const resultsWithScore = await vectorStore.similaritySearchWithScore("qux", 1);
115+
* for (const [doc, score] of resultsWithScore) {
116+
* console.log(`* [SIM=${score.toFixed(6)}] ${doc.pageContent} [${JSON.stringify(doc.metadata, null)}]`);
117+
* }
118+
* // Output: * [SIM=0.000000] qux [{"bar":"baz","baz":"bar"}]
119+
* ```
120+
* </details>
121+
*
122+
* <br />
123+
*
124+
* <details>
125+
* <summary><strong>As a retriever</strong></summary>
126+
*
127+
* ```typescript
128+
* const retriever = vectorStore.asRetriever({
129+
* searchType: "mmr", // Leave blank for standard similarity search
130+
* k: 1,
131+
* });
132+
* const resultAsRetriever = await retriever.invoke("thud");
133+
* console.log(resultAsRetriever);
134+
*
135+
* // Output: [Document({ metadata: { "baz":"bar" }, pageContent: "thud" })]
136+
* ```
137+
* </details>
138+
*
139+
* <br />
35140
*/
36141
export class MemoryVectorStore extends VectorStore {
37142
declare FilterType: (doc: Document) => boolean;

libs/langchain-community/src/tools/duckduckgo_search.ts

+63-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,69 @@ export interface DuckDuckGoSearchParameters extends ToolParams {
2424
const DEFAULT_MAX_RESULTS = 10;
2525

2626
/**
27-
* Class for interacting with the DuckDuckGo search engine
28-
* It extends the base Tool class to perform retrieval.
27+
* DuckDuckGo tool integration.
28+
*
29+
* Setup:
30+
* Install `@langchain/community` and `duck-duck-scrape`.
31+
*
32+
* ```bash
33+
* npm install @langchain/community duck-duck-scrape
34+
* ```
35+
*
36+
* ## [Constructor args](https://api.js.langchain.com/classes/_langchain_community.tools_duckduckgo_search.DuckDuckGoSearch.html#constructor)
37+
*
38+
* <details open>
39+
* <summary><strong>Instantiate</strong></summary>
40+
*
41+
* ```typescript
42+
* import { DuckDuckGoSearch } from "@langchain/community/tools/duckduckgo_search";
43+
*
44+
* const tool = new DuckDuckGoSearch({ maxResults: 1 });
45+
* ```
46+
* </details>
47+
*
48+
* <br />
49+
*
50+
* <details>
51+
*
52+
* <summary><strong>Invocation</strong></summary>
53+
*
54+
* ```typescript
55+
* await tool.invoke("what is the current weather in sf?");
56+
*
57+
* // output: [{"title":"San Francisco, CA Current Weather | AccuWeather","link":"https://www.accuweather.com/en/us/san-francisco/94103/current-weather/347629","snippet":"<b>Current</b> <b>weather</b> <b>in</b> San Francisco, CA. Check <b>current</b> conditions in San Francisco, CA with radar, hourly, and more."}]
58+
* ```
59+
* </details>
60+
*
61+
* <br />
62+
*
63+
* <details>
64+
*
65+
* <summary><strong>Invocation with tool call</strong></summary>
66+
*
67+
* ```typescript
68+
* // This is usually generated by a model, but we'll create a tool call directly for demo purposes.
69+
* const modelGeneratedToolCall = {
70+
* args: {
71+
* input: "what is the current weather in sf?",
72+
* },
73+
* id: "tool_call_id",
74+
* name: tool.name,
75+
* type: "tool_call",
76+
* };
77+
* await tool.invoke(modelGeneratedToolCall);
78+
* ```
79+
*
80+
* ```text
81+
* ToolMessage {
82+
* "content": "[{\"title\":\"San Francisco, CA Weather Conditions | Weather Underground\",\"link\":\"https://www.wunderground.com/weather/us/ca/san-francisco\",\"snippet\":\"San Francisco <b>Weather</b> Forecasts. <b>Weather</b> Underground provides local & long-range <b>weather</b> forecasts, weatherreports, maps & tropical <b>weather</b> conditions for the San Francisco area.\"}]",
83+
* "name": "duckduckgo-search",
84+
* "additional_kwargs": {},
85+
* "response_metadata": {},
86+
* "tool_call_id": "tool_call_id"
87+
* }
88+
* ```
89+
* </details>
2990
*/
3091
export class DuckDuckGoSearch extends Tool {
3192
private searchOptions?: SearchOptions;

libs/langchain-community/src/tools/tavily_search.ts

+64-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,70 @@ export type TavilySearchAPIRetrieverFields = ToolParams & {
1212
};
1313

1414
/**
15-
* Tool for the Tavily search API.
15+
* Tavily search API tool integration.
16+
*
17+
* Setup:
18+
* Install `@langchain/community`. You'll also need an API key set as `TAVILY_API_KEY`.
19+
*
20+
* ```bash
21+
* npm install @langchain/community
22+
* ```
23+
*
24+
* ## [Constructor args](https://api.js.langchain.com/classes/_langchain_community.tools_tavily_search.TavilySearchResults.html#constructor)
25+
*
26+
* <details open>
27+
* <summary><strong>Instantiate</strong></summary>
28+
*
29+
* ```typescript
30+
* import { TavilySearchResults } from "@langchain/community/tools/tavily_search";
31+
*
32+
* const tool = new TavilySearchResults({
33+
* maxResults: 2,
34+
* // ...
35+
* });
36+
* ```
37+
* </details>
38+
*
39+
* <br />
40+
*
41+
* <details>
42+
*
43+
* <summary><strong>Invocation</strong></summary>
44+
*
45+
* ```typescript
46+
* await tool.invoke("what is the current weather in sf?");
47+
* ```
48+
* </details>
49+
*
50+
* <br />
51+
*
52+
* <details>
53+
*
54+
* <summary><strong>Invocation with tool call</strong></summary>
55+
*
56+
* ```typescript
57+
* // This is usually generated by a model, but we'll create a tool call directly for demo purposes.
58+
* const modelGeneratedToolCall = {
59+
* args: {
60+
* input: "what is the current weather in sf?",
61+
* },
62+
* id: "tool_call_id",
63+
* name: tool.name,
64+
* type: "tool_call",
65+
* };
66+
* await tool.invoke(modelGeneratedToolCall);
67+
* ```
68+
*
69+
* ```text
70+
* ToolMessage {
71+
* "content": "...",
72+
* "name": "tavily_search_results_json",
73+
* "additional_kwargs": {},
74+
* "response_metadata": {},
75+
* "tool_call_id": "tool_call_id"
76+
* }
77+
* ```
78+
* </details>
1679
*/
1780
export class TavilySearchResults extends Tool {
1881
static lc_name(): string {

libs/langchain-community/src/tools/wikipedia_query_run.ts

+59-5
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,70 @@ interface PageResult {
5353
}
5454

5555
/**
56-
* Class for interacting with and fetching data from the Wikipedia API. It
57-
* extends the Tool class.
58-
* @example
56+
* Wikipedia query tool integration.
57+
*
58+
* Setup:
59+
* Install `@langchain/community`. You'll also need an API key.
60+
*
61+
* ```bash
62+
* npm install @langchain/community
63+
* ```
64+
*
65+
* ## [Constructor args](https://api.js.langchain.com/classes/_langchain_community.tools_wikipedia_query_run.WikipediaQueryRun.html#constructor)
66+
*
67+
* <details open>
68+
* <summary><strong>Instantiate</strong></summary>
69+
*
5970
* ```typescript
60-
* const wikipediaQuery = new WikipediaQueryRun({
71+
* import { WikipediaQueryRun } from "@langchain/community/tools/wikipedia_query_run";
72+
*
73+
* const tool = new WikipediaQueryRun({
6174
* topKResults: 3,
6275
* maxDocContentLength: 4000,
6376
* });
64-
* const result = await wikipediaQuery.call("Langchain");
6577
* ```
78+
* </details>
79+
*
80+
* <br />
81+
*
82+
* <details>
83+
*
84+
* <summary><strong>Invocation</strong></summary>
85+
*
86+
* ```typescript
87+
* await tool.invoke("what is the current weather in sf?");
88+
* ```
89+
* </details>
90+
*
91+
* <br />
92+
*
93+
* <details>
94+
*
95+
* <summary><strong>Invocation with tool call</strong></summary>
96+
*
97+
* ```typescript
98+
* // This is usually generated by a model, but we'll create a tool call directly for demo purposes.
99+
* const modelGeneratedToolCall = {
100+
* args: {
101+
* input: "what is the current weather in sf?",
102+
* },
103+
* id: "tool_call_id",
104+
* name: tool.name,
105+
* type: "tool_call",
106+
* };
107+
* await tool.invoke(modelGeneratedToolCall);
108+
* ```
109+
*
110+
* ```text
111+
* ToolMessage {
112+
* "content": "...",
113+
* "name": "wikipedia-api",
114+
* "additional_kwargs": {},
115+
* "response_metadata": {},
116+
* "tool_call_id": "tool_call_id"
117+
* }
118+
* ```
119+
* </details>
66120
*/
67121
export class WikipediaQueryRun extends Tool {
68122
static lc_name() {

0 commit comments

Comments
 (0)