forked from langchain-ai/langchainjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move docstore to store (breaking change, but this isn't an api we adv…
…ertise for using directly)
- Loading branch information
Showing
10 changed files
with
96 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
langchain/src/docstore/googlecloudstorage.ts → langchain/src/stores/doc/gcs.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { Document } from "../../document.js"; | ||
import { Docstore } from "../../schema/index.js"; | ||
|
||
export class InMemoryDocstore extends Docstore { | ||
_docs: Map<string, Document>; | ||
|
||
constructor(docs?: Map<string, Document>) { | ||
super(); | ||
this._docs = docs ?? new Map(); | ||
} | ||
|
||
async search(search: string): Promise<Document> { | ||
const result = this._docs.get(search); | ||
if (!result) { | ||
throw new Error(`ID ${search} not found.`); | ||
} else { | ||
return result; | ||
} | ||
} | ||
|
||
async add(texts: Record<string, Document>): Promise<void> { | ||
const keys = [...this._docs.keys()]; | ||
const overlapping = Object.keys(texts).filter((x) => keys.includes(x)); | ||
|
||
if (overlapping.length > 0) { | ||
throw new Error(`Tried to add ids that already exist: ${overlapping}`); | ||
} | ||
|
||
for (const [key, value] of Object.entries(texts)) { | ||
this._docs.set(key, value); | ||
} | ||
} | ||
} | ||
|
||
export class SynchronousInMemoryDocstore { | ||
_docs: Map<string, Document>; | ||
|
||
constructor(docs?: Map<string, Document>) { | ||
this._docs = docs ?? new Map(); | ||
} | ||
|
||
search(search: string): Document { | ||
const result = this._docs.get(search); | ||
if (!result) { | ||
throw new Error(`ID ${search} not found.`); | ||
} else { | ||
return result; | ||
} | ||
} | ||
|
||
add(texts: Record<string, Document>): void { | ||
const keys = [...this._docs.keys()]; | ||
const overlapping = Object.keys(texts).filter((x) => keys.includes(x)); | ||
|
||
if (overlapping.length > 0) { | ||
throw new Error(`Tried to add ids that already exist: ${overlapping}`); | ||
} | ||
|
||
for (const [key, value] of Object.entries(texts)) { | ||
this._docs.set(key, value); | ||
} | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
...tore/tests/googlecloudstorage.int.test.ts → ...hain/src/stores/doc/tests/gcs.int.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters