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

Get Node from Document Store with relationships #874

Open
garviand opened this issue May 22, 2024 · 2 comments
Open

Get Node from Document Store with relationships #874

garviand opened this issue May 22, 2024 · 2 comments

Comments

@garviand
Copy link
Contributor

Hi, I have the following code where I create an index from documents and then fetch a node.

const index = await VectorStoreIndex.fromDocuments(documents, {
  serviceContext: this.getServiceContext()
})
// some other stuff
const node = await index.docStore.getDocument('some-node-id', false);

The returned node doesn't have relationship information. Is this on purpose?

It seems like it is not being included when converting JSON to a TextNode in storage/docStore/utils.ts

export function jsonToDoc(docDict) {
    const docType = docDict[TYPE_KEY];
    const dataDict = JSON.parse(docDict[DATA_KEY]);
    let doc;
    if (docType === ObjectType.DOCUMENT) {
        doc = new Document({
            text: dataDict.text,
            id_: dataDict.id_,
            embedding: dataDict.embedding,
            hash: dataDict.hash,
            metadata: dataDict.metadata,
        });
    } else if (docType === ObjectType.TEXT) {
        doc = new TextNode({
            text: dataDict.text,
            id_: dataDict.id_,
            hash: dataDict.hash,
            metadata: dataDict.metadata,
            // relationships: dataDict.relationships, # not in existing code
        });
    } else {
        throw new Error(`Unknown doc type: ${docType}`);
    }
    return doc;
}

Curious if this is done for a specific reason, and if there are any recommended ways to fetch nodes from an index while retaining their relationships.

@marcusschiesser
Copy link
Collaborator

@garviand yes this looks wrong. Great catch! Want to send a PR?

@garviand
Copy link
Contributor Author

@marcusschiesser sure! I should have time in the next couple of days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants