Skip to content
Snippets Groups Projects
Commit 9ea84014 authored by Sourabh Desai's avatar Sourabh Desai
Browse files

changes to get test script running

parent a1c45294
Branches
Tags
No related merge requests found
......@@ -227,7 +227,7 @@ export class ImageDocument extends Document {
export interface NodeWithScore {
node: BaseNode;
score?: number;
score: number;
}
export interface NodeWithEmbedding {
......
......@@ -84,35 +84,33 @@ Given the new context, refine the original answer to better answer the question.
export const defaultChoiceSelectPrompt: SimplePrompt = (input) => {
const { context = "", query = "" } = input;
return `
A list of documents is shown below. Each document has a number next to it along
with a summary of the document. A question is also provided.
Respond with the numbers of the documents
you should consult to answer the question, in order of relevance, as well
as the relevance score. The relevance score is a number from 1-10 based on
how relevant you think the document is to the question.
Do not include any documents that are not relevant to the question.
Example format:
Document 1:
<summary of document 1>
Document 2:
<summary of document 2>
...
Document 10:\n<summary of document 10>
Question: <question>
Answer:
Doc: 9, Relevance: 7
Doc: 3, Relevance: 4
Doc: 7, Relevance: 3
Let's try this now:
${context}
Question: ${query}
Answer:
`.trim();
return `A list of documents is shown below. Each document has a number next to it along
with a summary of the document. A question is also provided.
Respond with the numbers of the documents
you should consult to answer the question, in order of relevance, as well
as the relevance score. The relevance score is a number from 1-10 based on
how relevant you think the document is to the question.
Do not include any documents that are not relevant to the question.
Example format:
Document 1:
<summary of document 1>
Document 2:
<summary of document 2>
...
Document 10:\n<summary of document 10>
Question: <question>
Answer:
Doc: 9, Relevance: 7
Doc: 3, Relevance: 4
Doc: 7, Relevance: 3
Let's try this now:
${context}
Question: ${query}
Answer:`;
};
......@@ -11,7 +11,7 @@ import {
ServiceContext,
serviceContextFromDefaults,
} from "../../ServiceContext";
import { RefDocInfo } from "../../storage/docStore/types";
import { BaseDocumentStore, RefDocInfo } from "../../storage/docStore/types";
import _ from "lodash";
export enum ListRetrieverMode {
......@@ -53,7 +53,10 @@ export class ListIndex extends BaseIndex<IndexList> {
"Cannot initialize VectorStoreIndex without nodes or indexStruct"
);
}
indexStruct = ListIndex._buildIndexFromNodes(options.nodes);
indexStruct = ListIndex._buildIndexFromNodes(
options.nodes,
storageContext.docStore
);
}
return new ListIndex({
......@@ -74,6 +77,7 @@ export class ListIndex extends BaseIndex<IndexList> {
serviceContext = serviceContext ?? serviceContextFromDefaults({});
const docStore = storageContext.docStore;
docStore.addDocuments(documents, true);
for (const doc of documents) {
docStore.setDocumentHash(doc.id_, doc.hash);
}
......@@ -108,10 +112,12 @@ export class ListIndex extends BaseIndex<IndexList> {
static _buildIndexFromNodes(
nodes: BaseNode[],
docStore: BaseDocumentStore,
indexStruct?: IndexList
): IndexList {
indexStruct = indexStruct || new IndexList();
docStore.addDocuments(nodes, true);
for (const node of nodes) {
indexStruct.addNode(node);
}
......
......@@ -26,6 +26,7 @@ export class ListIndexRetriever implements BaseRetriever {
const nodes = await this.index.docStore.getNodes(nodeIds);
return nodes.map((node) => ({
node: node,
score: 1,
}));
}
}
......
......@@ -77,7 +77,7 @@ export class KVDocumentStore extends BaseDocumentStore {
let json = await this.kvstore.get(docId, this.nodeCollection);
if (_.isNil(json)) {
if (raiseError) {
throw new Error(`doc_id ${docId} not found.`);
throw new Error(`docId ${docId} not found.`);
} else {
return;
}
......
......@@ -23,12 +23,11 @@ export function jsonToDoc(docDict: Record<string, any>): BaseNode {
hash: dataDict.hash,
});
} else if (docType === ObjectType.TEXT) {
const relationships = dataDict.relationships;
console.log({ dataDict });
doc = new TextNode({
text: relationships.text,
id_: relationships.id_,
embedding: relationships.embedding,
hash: relationships.hash,
text: dataDict.text,
id_: dataDict.id_,
hash: dataDict.hash,
});
} else {
throw new Error(`Unknown doc type: ${docType}`);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment