Skip to content

Commit

Permalink
docs[patch]: Update ParentDocument docs to use byte store (#6647)
Browse files Browse the repository at this point in the history
  • Loading branch information
bracesproul authored Aug 28, 2024
1 parent 3f9d6a2 commit 3a61cdb
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
7 changes: 4 additions & 3 deletions examples/src/retrievers/parent_document_retriever.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { OpenAIEmbeddings } from "@langchain/openai";
import { MemoryVectorStore } from "langchain/vectorstores/memory";
import { InMemoryStore } from "@langchain/core/stores";
import { ParentDocumentRetriever } from "langchain/retrievers/parent_document";
import { RecursiveCharacterTextSplitter } from "@langchain/textsplitters";
import { TextLoader } from "langchain/document_loaders/fs/text";
import { InMemoryStore } from "@langchain/core/stores";

const vectorstore = new MemoryVectorStore(new OpenAIEmbeddings());
const docstore = new InMemoryStore();
const byteStore = new InMemoryStore<Uint8Array>();

const retriever = new ParentDocumentRetriever({
vectorstore,
docstore,
byteStore,
// Optional, not required if you're already passing in split documents
parentSplitter: new RecursiveCharacterTextSplitter({
chunkOverlap: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ const pamChunkHeaderOptions = {
};

const vectorstore = await HNSWLib.fromDocuments([], new OpenAIEmbeddings());
const docstore = new InMemoryStore();
const byteStore = new InMemoryStore<Uint8Array>();

const retriever = new ParentDocumentRetriever({
vectorstore,
docstore,
byteStore,
// Very small chunks for demo purposes.
// Use a bigger chunk size for serious use-cases.
childSplitter: new RecursiveCharacterTextSplitter({
Expand Down
4 changes: 2 additions & 2 deletions examples/src/retrievers/parent_document_retriever_rerank.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ const jimDocs = await splitter.createDocuments([`Jim favorite color is blue.`]);
const pamDocs = await splitter.createDocuments([`Pam favorite color is red.`]);

const vectorstore = await HNSWLib.fromDocuments([], new OpenAIEmbeddings());
const docstore = new InMemoryStore();
const byteStore = new InMemoryStore<Uint8Array>();

const retriever = new ParentDocumentRetriever({
vectorstore,
docstore,
byteStore,
// Very small chunks for demo purposes.
// Use a bigger chunk size for serious use-cases.
childSplitter: new RecursiveCharacterTextSplitter({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import { TextLoader } from "langchain/document_loaders/fs/text";
import { ScoreThresholdRetriever } from "langchain/retrievers/score_threshold";

const vectorstore = new MemoryVectorStore(new OpenAIEmbeddings());
const docstore = new InMemoryStore();
const byteStore = new InMemoryStore<Uint8Array>();

const childDocumentRetriever = ScoreThresholdRetriever.fromVectorStore(
vectorstore,
{
Expand All @@ -17,7 +18,7 @@ const childDocumentRetriever = ScoreThresholdRetriever.fromVectorStore(
);
const retriever = new ParentDocumentRetriever({
vectorstore,
docstore,
byteStore,
childDocumentRetriever,
// Optional, not required if you're already passing in split documents
parentSplitter: new RecursiveCharacterTextSplitter({
Expand Down

0 comments on commit 3a61cdb

Please sign in to comment.