@anvia/graph 0.0.0-bootstrap.0 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +120 -1
- package/dist/chunk-N3CKMOPE.js +85 -0
- package/dist/chunk-N3CKMOPE.js.map +1 -0
- package/dist/explore-9jm2c1mG.d.ts +277 -0
- package/dist/explore.d.ts +5 -0
- package/dist/explore.js +7 -0
- package/dist/explore.js.map +1 -0
- package/dist/index.d.ts +69 -0
- package/dist/index.js +672 -0
- package/dist/index.js.map +1 -0
- package/package.json +40 -5
- package/index.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/extract.ts","../src/schema.ts","../src/ingest.ts","../src/tool.ts"],"sourcesContent":["import { Usage } from \"@anvia/core\";\nimport { extract } from \"@anvia/core/extractor\";\nimport { z } from \"zod\";\nimport { parseGraphProperties } from \"./schema.js\";\nimport type {\n ExtractGraphFactsOptions,\n ExtractGraphFactsResult,\n GraphEntity,\n GraphFacts,\n GraphMention,\n GraphNodeIdentity,\n GraphProperties,\n GraphRelationship,\n GraphSchemaLike,\n} from \"./types.js\";\n\ntype RawEntity = { ref: string; type: string; properties: Record<string, unknown> };\ntype RawRelationship = {\n type: string;\n from: string;\n to: string;\n properties: Record<string, unknown>;\n};\ntype RawChunkFacts = { entities: RawEntity[]; relationships: RawRelationship[] };\ntype ChunkExtraction = { chunkId: string; output: RawChunkFacts; usage: Usage };\n\nexport async function extractGraphFacts<\n Schema extends GraphSchemaLike,\n Model extends import(\"@anvia/core\").CompletionModel,\n>(options: ExtractGraphFactsOptions<Schema, Model>): Promise<ExtractGraphFactsResult<Schema>> {\n assertConcurrency(options.concurrency);\n throwIfAborted(options.abortSignal);\n const ids = new Set<string>();\n for (const chunk of options.chunks) {\n if (ids.has(chunk.id)) throw new TypeError(`Duplicate graph chunk id: ${chunk.id}`);\n ids.add(chunk.id);\n if (typeof chunk.text !== \"string\") {\n throw new TypeError(`Graph chunk ${chunk.id} text must be a string.`);\n }\n }\n\n const outputSchema = extractionSchema(options.schema);\n const instructions = graphInstructions(options.schema, options.instructions);\n const extractions = await mapConcurrent(\n options.chunks,\n options.concurrency ?? 1,\n async (chunk): Promise<ChunkExtraction> => {\n throwIfAborted(options.abortSignal);\n const result = await extract({\n model: options.model,\n text: chunk.text,\n outputSchema,\n instructions,\n retries: options.retries,\n abortSignal: options.abortSignal,\n });\n return { chunkId: chunk.id, output: result.output as RawChunkFacts, usage: result.usage };\n },\n );\n return {\n output: normalizeFacts(options.schema, extractions),\n usage: extractions.reduce((usage, item) => Usage.add(usage, item.usage), Usage.empty()),\n };\n}\n\nfunction extractionSchema(schema: GraphSchemaLike): z.ZodType<RawChunkFacts> {\n const entities = Object.entries(schema.nodes).map(([type, definition]) =>\n z.object({ ref: z.string().min(1), type: z.literal(type), properties: definition.properties }),\n );\n const relationships = Object.entries(schema.relationships).map(([type, definition]) =>\n z.object({\n type: z.literal(type),\n from: z.string().min(1),\n to: z.string().min(1),\n properties: definition.properties,\n }),\n );\n return z.object({\n entities: z.array(union(entities, z.never())),\n relationships: z.array(union(relationships, z.never())),\n }) as unknown as z.ZodType<RawChunkFacts>;\n}\n\nfunction union(items: z.ZodType[], empty: z.ZodType): z.ZodType {\n if (items.length === 0) return empty;\n if (items.length === 1) return items[0] as z.ZodType;\n return z.union(items as [z.ZodType, z.ZodType, ...z.ZodType[]]);\n}\n\nfunction graphInstructions(schema: GraphSchemaLike, extra: string | undefined): string {\n const nodes = Object.entries(schema.nodes)\n .map(([type, definition]) => `- ${type}: ${definition.description}`)\n .join(\"\\n\");\n const relationships = Object.entries(schema.relationships)\n .map(\n ([type, definition]) =>\n `- ${type}: ${definition.from} -> ${definition.to}. ${definition.description}`,\n )\n .join(\"\\n\");\n return [\n \"Extract only facts directly supported by the source text.\",\n \"Give every extracted entity a unique local ref and use those refs as relationship endpoints.\",\n \"Do not invent entity or relationship types outside the declared schema.\",\n `Node types:\\n${nodes}`,\n relationships.length === 0\n ? \"No relationship types are allowed.\"\n : `Relationship types:\\n${relationships}`,\n extra,\n ]\n .filter((part): part is string => part !== undefined && part.length > 0)\n .join(\"\\n\\n\");\n}\n\nfunction normalizeFacts<Schema extends GraphSchemaLike>(\n schema: Schema,\n extractions: readonly ChunkExtraction[],\n): GraphFacts<Schema> {\n const entities = new Map<string, GraphEntity<Schema>>();\n const relationships = new Map<string, GraphRelationship<Schema>>();\n const mentions = new Map<string, GraphMention>();\n\n for (const extraction of extractions) {\n const refs = new Map<string, GraphEntity<Schema>>();\n for (const raw of extraction.output.entities) {\n if (refs.has(raw.ref)) {\n throw new TypeError(`Duplicate entity ref ${raw.ref} in chunk ${extraction.chunkId}.`);\n }\n const definition = schema.nodes[raw.type];\n if (definition === undefined) throw new TypeError(`Unknown graph entity type: ${raw.type}`);\n const properties = parseGraphProperties(\n definition.properties.parse(raw.properties),\n `entity ${raw.type}`,\n );\n const identity = identityFromProperties(definition.identity, properties, raw.type);\n const key = `${raw.type}:${stableObject(identity)}`;\n const current = entities.get(key);\n const next = {\n key,\n type: raw.type,\n identity,\n properties,\n sourceChunkIds: [extraction.chunkId],\n } as unknown as GraphEntity<Schema>;\n if (current === undefined) {\n entities.set(key, next);\n refs.set(raw.ref, next);\n } else {\n assertSameProperties(\n current.properties,\n properties,\n key,\n current.sourceChunkIds,\n extraction.chunkId,\n );\n const merged = {\n ...current,\n sourceChunkIds: [...current.sourceChunkIds, extraction.chunkId],\n } as GraphEntity<Schema>;\n entities.set(key, merged);\n refs.set(raw.ref, merged);\n }\n mentions.set(`${extraction.chunkId}\\u0000${key}`, {\n chunkId: extraction.chunkId,\n entityKey: key,\n });\n }\n\n for (const raw of extraction.output.relationships) {\n const definition = schema.relationships[raw.type];\n if (definition === undefined) {\n throw new TypeError(`Unknown graph relationship type: ${raw.type}`);\n }\n const from = refs.get(raw.from);\n const to = refs.get(raw.to);\n if (from === undefined || to === undefined) {\n throw new TypeError(\n `Relationship ${raw.type} in chunk ${extraction.chunkId} references an unknown entity ref.`,\n );\n }\n if (from.type !== definition.from || to.type !== definition.to) {\n throw new TypeError(\n `Relationship ${raw.type} has invalid endpoint types ${from.type} -> ${to.type}.`,\n );\n }\n const properties = parseGraphProperties(\n definition.properties.parse(raw.properties),\n `relationship ${raw.type}`,\n );\n const identity = identityFromProperties(definition.identity ?? [], properties, raw.type);\n const key = `${raw.type}:${from.key}->${to.key}:${stableObject(identity)}`;\n const current = relationships.get(key);\n const next = {\n key,\n type: raw.type,\n from: from.key,\n to: to.key,\n properties,\n sourceChunkIds: [extraction.chunkId],\n } as unknown as GraphRelationship<Schema>;\n if (current === undefined) relationships.set(key, next);\n else {\n assertSameProperties(\n current.properties,\n properties,\n key,\n current.sourceChunkIds,\n extraction.chunkId,\n );\n relationships.set(key, {\n ...current,\n sourceChunkIds: [...current.sourceChunkIds, extraction.chunkId],\n } as GraphRelationship<Schema>);\n }\n }\n }\n return {\n entities: [...entities.values()],\n relationships: [...relationships.values()],\n mentions: [...mentions.values()],\n };\n}\n\nfunction identityFromProperties(\n keys: readonly string[],\n properties: GraphProperties,\n type: string,\n): GraphNodeIdentity {\n const identity: Record<string, string | number | boolean> = {};\n for (const key of keys) {\n const value = properties[key];\n if (\n value === undefined ||\n !(typeof value === \"string\" || typeof value === \"number\" || typeof value === \"boolean\")\n ) {\n throw new TypeError(`Identity property ${key} for ${type} must be a primitive value.`);\n }\n identity[key] = value;\n }\n return identity;\n}\n\nfunction stableObject(value: Readonly<Record<string, unknown>>): string {\n return JSON.stringify(\n Object.fromEntries(Object.entries(value).sort(([left], [right]) => left.localeCompare(right))),\n );\n}\n\nfunction assertSameProperties(\n left: GraphProperties,\n right: GraphProperties,\n key: string,\n sourceChunkIds: readonly string[],\n nextChunkId: string,\n): void {\n if (stableObject(left) !== stableObject(right)) {\n throw new GraphFactConflictError(key, [...sourceChunkIds, nextChunkId]);\n }\n}\n\nexport class GraphFactConflictError extends Error {\n constructor(\n readonly factKey: string,\n readonly sourceChunkIds: readonly string[],\n ) {\n super(\n `Conflicting graph fact ${factKey} was extracted from chunks ${sourceChunkIds.join(\", \")}.`,\n );\n this.name = \"GraphFactConflictError\";\n }\n}\n\nfunction assertConcurrency(value: number | undefined): void {\n if (value !== undefined && (!Number.isSafeInteger(value) || value < 1)) {\n throw new RangeError(\"Graph extraction concurrency must be a positive safe integer.\");\n }\n}\n\nfunction throwIfAborted(signal: AbortSignal | undefined): void {\n if (signal?.aborted !== true) return;\n if (signal.reason instanceof Error) throw signal.reason;\n throw new DOMException(\"The operation was aborted.\", \"AbortError\");\n}\n\nasync function mapConcurrent<Input, Output>(\n values: readonly Input[],\n concurrency: number,\n run: (value: Input) => Promise<Output>,\n): Promise<Output[]> {\n const output = Array<Output>(values.length);\n let cursor = 0;\n await Promise.all(\n Array.from({ length: Math.min(concurrency, values.length) }, async () => {\n for (;;) {\n const index = cursor;\n cursor += 1;\n if (index >= values.length) return;\n output[index] = await run(values[index] as Input);\n }\n }),\n );\n return output;\n}\n","import { z } from \"zod\";\nimport type {\n GraphProperties,\n GraphPropertyPrimitive,\n GraphPropertyValue,\n GraphSchema,\n GraphSchemaOptions,\n} from \"./types.js\";\n\nexport const graphReservedPropertyPrefix = \"__anvia_\";\n\nexport function defineGraphSchema<const Options extends GraphSchemaOptions>(\n options: Options,\n): GraphSchema<Options> {\n validateGraphSchemaOptions(options);\n return freezeGraphSchema(options, \"graph-schema\");\n}\n\nexport function validateGraphSchemaOptions(options: GraphSchemaOptions): void {\n if (Object.keys(options.nodes).length === 0) {\n throw new TypeError(\"A graph schema requires at least one node type.\");\n }\n for (const [type, definition] of Object.entries(options.nodes)) {\n assertGraphName(type, \"node type\");\n assertDescription(definition.description, `node ${type}`);\n if (!(definition.properties instanceof z.ZodObject)) {\n throw new TypeError(`Properties for node ${type} must be a Zod object schema.`);\n }\n assertExactPropertySchema(definition.properties, `node ${type}`);\n if (\n definition.identity.length === 0 ||\n new Set(definition.identity).size !== definition.identity.length\n ) {\n throw new TypeError(`Node ${type} must declare unique identity properties.`);\n }\n for (const property of definition.identity) {\n assertGraphPropertyName(property);\n if (!(property in definition.properties.shape)) {\n throw new TypeError(`Identity property ${property} is not declared by node ${type}.`);\n }\n }\n for (const property of Object.keys(definition.properties.shape)) {\n assertGraphPropertyName(property);\n }\n }\n for (const [type, definition] of Object.entries(options.relationships)) {\n assertGraphName(type, \"relationship type\");\n assertDescription(definition.description, `relationship ${type}`);\n if (!(definition.from in options.nodes) || !(definition.to in options.nodes)) {\n throw new TypeError(`Relationship ${type} references an unknown endpoint type.`);\n }\n if (!(definition.properties instanceof z.ZodObject)) {\n throw new TypeError(`Properties for relationship ${type} must be a Zod object schema.`);\n }\n assertExactPropertySchema(definition.properties, `relationship ${type}`);\n const identity = definition.identity ?? [];\n if (new Set(identity).size !== identity.length) {\n throw new TypeError(`Relationship ${type} contains duplicate identity properties.`);\n }\n for (const property of Object.keys(definition.properties.shape)) {\n assertGraphPropertyName(property);\n }\n for (const property of identity) {\n if (!(property in definition.properties.shape)) {\n throw new TypeError(\n `Identity property ${property} is not declared by relationship ${type}.`,\n );\n }\n }\n }\n}\n\nexport function freezeGraphSchema<\n const Options extends GraphSchemaOptions,\n const Kind extends string,\n>(options: Options, kind: Kind): Readonly<Options & { kind: Kind }> {\n const nodes = Object.fromEntries(\n Object.entries(options.nodes).map(([type, definition]) => [\n type,\n Object.freeze({ ...definition, identity: Object.freeze([...definition.identity]) }),\n ]),\n );\n const relationships = Object.fromEntries(\n Object.entries(options.relationships).map(([type, definition]) => {\n const copy = { ...definition };\n if (definition.identity !== undefined) {\n Object.assign(copy, { identity: Object.freeze([...definition.identity]) });\n }\n return [type, Object.freeze(copy)];\n }),\n );\n return Object.freeze({\n nodes: Object.freeze(nodes),\n relationships: Object.freeze(relationships),\n kind,\n }) as Readonly<Options & { kind: Kind }>;\n}\n\nexport function parseGraphProperties(value: unknown, label: string): GraphProperties {\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n throw new TypeError(`${label} must be an object of graph property values.`);\n }\n const output: Record<string, GraphPropertyValue> = {};\n for (const [key, item] of Object.entries(value)) {\n assertGraphPropertyName(key);\n output[key] = parseGraphPropertyValue(item, `${label}.${key}`);\n }\n return output;\n}\n\nexport function parseGraphPropertyValue(value: unknown, label: string): GraphPropertyValue {\n if (typeof value === \"string\" || typeof value === \"boolean\") return value;\n if (typeof value === \"number\") {\n if (!Number.isFinite(value)) throw new TypeError(`${label} must be finite.`);\n if (Number.isInteger(value) && !Number.isSafeInteger(value)) {\n throw new TypeError(`${label} must be a safe integer.`);\n }\n return value;\n }\n if (Array.isArray(value)) {\n if (value.length === 0) return [];\n const parsed = value.map((item, index) => parsePrimitive(item, `${label}[${index}]`));\n const type = typeof parsed[0];\n if (!parsed.every((item) => typeof item === type)) {\n throw new TypeError(`${label} must be a homogeneous array.`);\n }\n return parsed as GraphPropertyValue;\n }\n throw new TypeError(`${label} is not a supported graph property value.`);\n}\n\nexport function assertGraphName(value: string, label: string): void {\n if (typeof value !== \"string\" || value.length === 0) {\n throw new TypeError(`${label} must be a non-empty string.`);\n }\n}\n\nexport function assertGraphPropertyName(value: string): void {\n assertGraphName(value, \"graph property name\");\n if (value.startsWith(graphReservedPropertyPrefix)) {\n throw new TypeError(\n `Graph property names beginning with ${graphReservedPropertyPrefix} are reserved.`,\n );\n }\n}\n\nfunction parsePrimitive(value: unknown, label: string): GraphPropertyPrimitive {\n const parsed = parseGraphPropertyValue(value, label);\n if (typeof parsed === \"string\" || typeof parsed === \"number\" || typeof parsed === \"boolean\") {\n return parsed;\n }\n throw new TypeError(`${label} must be a primitive property value.`);\n}\n\nfunction assertDescription(value: string, label: string): void {\n if (typeof value !== \"string\" || value.trim().length === 0) {\n throw new TypeError(`${label} requires a non-empty description.`);\n }\n}\n\nfunction assertExactPropertySchema(schema: z.ZodObject<z.ZodRawShape>, label: string): void {\n const definition = schema._zod.def;\n if (!(definition.catchall instanceof z.ZodNever)) {\n throw new TypeError(`${label} properties must use a strict Zod object schema.`);\n }\n for (const [property, propertySchema] of Object.entries(schema.shape)) {\n assertNonEffectfulSchema(propertySchema, `${label} property ${property}`, new Set());\n }\n}\n\nfunction assertNonEffectfulSchema(value: unknown, label: string, visited: Set<z.ZodType>): void {\n if (!(value instanceof z.ZodType)) throw new TypeError(`${label} must be a Zod schema.`);\n if (visited.has(value)) return;\n visited.add(value);\n const definition = value._zod.def as unknown as Record<string, unknown>;\n const type = definition.type;\n if (\n definition.coerce === true ||\n type === \"default\" ||\n type === \"prefault\" ||\n type === \"catch\" ||\n type === \"transform\" ||\n type === \"pipe\"\n ) {\n throw new TypeError(\n `${label} must not coerce, default, transform, preprocess, or catch values.`,\n );\n }\n const checks = definition.checks;\n if (\n Array.isArray(checks) &&\n checks.some((check) => {\n if (typeof check !== \"object\" || check === null) return false;\n return (check as { _zod?: { def?: { check?: unknown } } })._zod?.def?.check === \"overwrite\";\n })\n ) {\n throw new TypeError(`${label} must not normalize or overwrite values.`);\n }\n for (const child of schemaChildren(definition)) assertNonEffectfulSchema(child, label, visited);\n}\n\nfunction schemaChildren(definition: Record<string, unknown>): z.ZodType[] {\n const children: z.ZodType[] = [];\n for (const key of [\"innerType\", \"element\", \"left\", \"right\", \"rest\", \"keyType\", \"valueType\"]) {\n const value = definition[key];\n if (value instanceof z.ZodType) children.push(value);\n }\n for (const key of [\"options\", \"items\"]) {\n const value = definition[key];\n if (Array.isArray(value)) {\n for (const item of value) if (item instanceof z.ZodType) children.push(item);\n }\n }\n return children;\n}\n","import type { CompletionModel, RetrySetting, Usage } from \"@anvia/core\";\nimport {\n chunkTextDocuments,\n type TextDocument,\n type TextDocumentChunk,\n type TextDocumentChunkingOptions,\n type TextDocumentMetadata,\n} from \"@anvia/core/documents\";\nimport { embedDocuments, type EmbeddedDocument, type EmbeddingModel } from \"@anvia/core/embeddings\";\nimport { extractGraphFacts } from \"./extract.js\";\nimport { parseGraphProperties } from \"./schema.js\";\nimport type {\n GraphChunk,\n GraphDocument,\n GraphDocumentWriter,\n GraphEntity,\n GraphMention,\n GraphOrphanEntityPolicy,\n GraphProperties,\n GraphRelationship,\n GraphSchemaLike,\n GraphWriteConflict,\n GraphWriteResult,\n} from \"./types.js\";\n\ntype GraphPreparationOptions<\n Schema extends GraphSchemaLike,\n ExtractionModel extends CompletionModel,\n> = Readonly<{\n graph: Readonly<{ schema: Schema }>;\n documents: readonly TextDocument<TextDocumentMetadata>[];\n extractionModel: ExtractionModel;\n embeddingModel: EmbeddingModel;\n chunking?: TextDocumentChunkingOptions | undefined;\n entityText?: ((entity: GraphEntity<Schema>) => string) | undefined;\n instructions?: string | undefined;\n retries?: RetrySetting | undefined;\n concurrency?: number | undefined;\n abortSignal?: AbortSignal | undefined;\n}>;\n\nexport type PrepareGraphDocumentsOptions<\n Schema extends GraphSchemaLike,\n ExtractionModel extends CompletionModel = CompletionModel,\n> = GraphPreparationOptions<Schema, ExtractionModel>;\n\nexport type IngestGraphDocumentsOptions<\n Schema extends GraphSchemaLike,\n ExtractionModel extends CompletionModel = CompletionModel,\n> = Omit<GraphPreparationOptions<Schema, ExtractionModel>, \"graph\"> &\n Readonly<{\n graph: GraphDocumentWriter<Schema>;\n conflict: GraphWriteConflict;\n orphanEntities: GraphOrphanEntityPolicy;\n }>;\n\nexport type IngestGraphTextOptions<\n Schema extends GraphSchemaLike,\n ExtractionModel extends CompletionModel = CompletionModel,\n> = Omit<IngestGraphDocumentsOptions<Schema, ExtractionModel>, \"documents\"> &\n Readonly<{ document: TextDocument<TextDocumentMetadata> }>;\n\nexport type PreparedGraphDocuments<Schema extends GraphSchemaLike> = Readonly<{\n documents: readonly GraphDocument[];\n chunks: readonly EmbeddedDocument<GraphChunk<TextDocumentMetadata>, TextDocumentMetadata>[];\n vectorDocuments: readonly EmbeddedDocument<\n TextDocument<TextDocumentMetadata>,\n TextDocumentMetadata\n >[];\n entities: readonly EmbeddedDocument<GraphEntity<Schema>>[];\n relationships: readonly GraphRelationship<Schema>[];\n mentions: readonly GraphMention[];\n usage: Usage;\n}>;\n\nexport type IngestGraphDocumentsResult<Schema extends GraphSchemaLike> =\n PreparedGraphDocuments<Schema> & Readonly<{ write: GraphWriteResult }>;\n\nexport async function ingestGraphText<\n Schema extends GraphSchemaLike,\n ExtractionModel extends CompletionModel,\n>(\n options: IngestGraphTextOptions<Schema, ExtractionModel>,\n): Promise<IngestGraphDocumentsResult<Schema>> {\n return ingestGraphDocuments({\n graph: options.graph,\n documents: [options.document],\n extractionModel: options.extractionModel,\n embeddingModel: options.embeddingModel,\n chunking: options.chunking,\n entityText: options.entityText,\n instructions: options.instructions,\n retries: options.retries,\n concurrency: options.concurrency,\n abortSignal: options.abortSignal,\n conflict: options.conflict,\n orphanEntities: options.orphanEntities,\n });\n}\n\nexport async function ingestGraphDocuments<\n Schema extends GraphSchemaLike,\n ExtractionModel extends CompletionModel,\n>(\n options: IngestGraphDocumentsOptions<Schema, ExtractionModel>,\n): Promise<IngestGraphDocumentsResult<Schema>> {\n const prepared = await prepareGraphDocuments(options);\n const write = await options.graph.replaceDocuments({\n documents: prepared.documents,\n chunks: prepared.chunks,\n entities: prepared.entities,\n relationships: prepared.relationships,\n mentions: prepared.mentions,\n conflict: options.conflict,\n orphanEntities: options.orphanEntities,\n abortSignal: options.abortSignal,\n });\n return { ...prepared, write };\n}\n\nexport async function prepareGraphDocuments<\n Schema extends GraphSchemaLike,\n ExtractionModel extends CompletionModel,\n>(\n options: PrepareGraphDocumentsOptions<Schema, ExtractionModel>,\n): Promise<PreparedGraphDocuments<Schema>> {\n validatePortableMetadata(options.documents);\n const chunks = chunkTextDocuments({\n documents: options.documents,\n chunking: options.chunking,\n });\n const graphChunks: GraphChunk<TextDocumentMetadata>[] = chunks.map((chunk) => graphChunk(chunk));\n const [facts, embeddedChunks] = await Promise.all([\n extractGraphFacts({\n model: options.extractionModel,\n schema: options.graph.schema,\n chunks: graphChunks,\n instructions: options.instructions,\n retries: options.retries,\n concurrency: options.concurrency,\n abortSignal: options.abortSignal,\n }),\n embedDocuments({\n model: options.embeddingModel,\n documents: graphChunks,\n id: (chunk) => chunk.id,\n content: (chunk) => chunk.text,\n metadata: (chunk) => chunk.metadata,\n retries: options.retries,\n concurrency: options.concurrency,\n abortSignal: options.abortSignal,\n }),\n ]);\n const embeddedEntities = await embedDocuments({\n model: options.embeddingModel,\n documents: [...facts.output.entities],\n id: (entity) => entity.key,\n content: options.entityText ?? defaultGraphEntityText,\n retries: options.retries,\n concurrency: options.concurrency,\n abortSignal: options.abortSignal,\n });\n const vectorDocuments = groupVectorDocuments(options.documents, embeddedChunks.documents);\n return {\n documents: options.documents.map((document) => graphDocument(document)),\n chunks: embeddedChunks.documents,\n vectorDocuments,\n entities: embeddedEntities.documents,\n relationships: facts.output.relationships,\n mentions: facts.output.mentions,\n usage: facts.usage,\n };\n}\n\nfunction validatePortableMetadata(documents: readonly TextDocument<TextDocumentMetadata>[]): void {\n for (const document of documents) {\n if (document.metadata === undefined) {\n continue;\n }\n const metadata = parseGraphProperties(\n document.metadata,\n `Text document ${document.id} metadata`,\n );\n for (const [key, value] of Object.entries(metadata)) {\n if (Array.isArray(value)) {\n throw new TypeError(\n `Text document ${document.id} metadata.${key} must be a portable primitive value`,\n );\n }\n }\n }\n}\n\nfunction groupVectorDocuments(\n documents: readonly TextDocument<TextDocumentMetadata>[],\n chunks: readonly EmbeddedDocument<GraphChunk<TextDocumentMetadata>, TextDocumentMetadata>[],\n): readonly EmbeddedDocument<TextDocument<TextDocumentMetadata>, TextDocumentMetadata>[] {\n const chunksByDocument = new Map<\n string,\n EmbeddedDocument<GraphChunk<TextDocumentMetadata>, TextDocumentMetadata>[]\n >();\n for (const chunk of chunks) {\n const documentChunks = chunksByDocument.get(chunk.document.documentId);\n if (documentChunks === undefined) {\n chunksByDocument.set(chunk.document.documentId, [chunk]);\n } else {\n documentChunks.push(chunk);\n }\n }\n return documents.map((document) => {\n const documentChunks = chunksByDocument.get(document.id);\n if (documentChunks === undefined) {\n throw new TypeError(`Text document ${document.id} has no embedded graph chunks`);\n }\n const embeddedDocument: EmbeddedDocument<\n TextDocument<TextDocumentMetadata>,\n TextDocumentMetadata\n > = {\n id: document.id,\n document,\n embeddings: documentChunks.flatMap((chunk) => chunk.embeddings),\n };\n if (document.metadata !== undefined) {\n embeddedDocument.metadata = document.metadata;\n }\n return embeddedDocument;\n });\n}\n\nfunction graphDocument(document: TextDocument<TextDocumentMetadata>): GraphDocument {\n if (document.metadata === undefined) {\n return { id: document.id };\n }\n return { id: document.id, properties: document.metadata };\n}\n\nfunction graphChunk(\n chunk: TextDocumentChunk<TextDocumentMetadata>,\n): GraphChunk<TextDocumentMetadata> {\n if (chunk.metadata === undefined) {\n return {\n id: chunk.id,\n documentId: chunk.documentId,\n index: chunk.index,\n text: chunk.text,\n };\n }\n return {\n id: chunk.id,\n documentId: chunk.documentId,\n index: chunk.index,\n text: chunk.text,\n metadata: chunk.metadata,\n };\n}\n\nfunction defaultGraphEntityText(entity: GraphEntity<GraphSchemaLike>): string {\n const properties = Object.entries(entity.properties)\n .sort(([left], [right]) => left.localeCompare(right))\n .map(([key, value]) => `${key}: ${formatGraphProperty(value)}`)\n .join(\"\\n\");\n return properties.length === 0 ? entity.type : `${entity.type}\\n${properties}`;\n}\n\nfunction formatGraphProperty(value: GraphProperties[string]): string {\n if (Array.isArray(value)) {\n return value.join(\", \");\n }\n return String(value);\n}\n","import { createTool } from \"@anvia/core/tool\";\nimport { z } from \"zod\";\nimport type {\n CreateGraphSearchToolOptions,\n GraphContextRetriever,\n GraphSchemaLike,\n GraphSearchTool,\n} from \"./types.js\";\n\nconst primitive = z.union([z.string(), z.number().finite(), z.boolean()]);\nconst propertyValue = z.union([\n primitive,\n z.array(z.string()),\n z.array(z.number().finite()),\n z.array(z.boolean()),\n]);\nconst properties = z.record(z.string(), propertyValue);\nconst contextSchema = z.object({\n seeds: z.array(\n z.object({\n key: z.string(),\n type: z.string(),\n score: z.number().finite(),\n properties,\n sourceChunkIds: z.array(z.string()),\n }),\n ),\n nodes: z.array(\n z.object({\n key: z.string(),\n type: z.string(),\n identity: z.record(z.string(), primitive),\n properties,\n sourceChunkIds: z.array(z.string()),\n }),\n ),\n relationships: z.array(\n z.object({\n key: z.string(),\n type: z.string(),\n from: z.string(),\n to: z.string(),\n properties,\n sourceChunkIds: z.array(z.string()),\n }),\n ),\n evidence: z.array(\n z.object({\n chunkId: z.string(),\n documentId: z.string(),\n index: z.number().int(),\n text: z.string(),\n metadata: properties,\n }),\n ),\n});\n\nexport function createGraphSearchTool<\n Schema extends GraphSchemaLike,\n Retriever extends GraphContextRetriever<Schema>,\n>(options: CreateGraphSearchToolOptions<Schema, Retriever>): GraphSearchTool {\n return createTool({\n name: options.name,\n description: options.description,\n inputSchema: z.object({\n query: z.string().min(1).describe(\"The question or concept to search for in the graph.\"),\n }),\n outputSchema: contextSchema,\n execute: async ({ query }, context) =>\n (await options.graph.retrieve({\n model: options.model,\n query,\n search: options.search,\n traversal: options.traversal,\n evidence: options.evidence,\n retries: options.retries,\n abortSignal: context.abortSignal,\n })) as unknown as z.input<typeof contextSchema>,\n }) as unknown as GraphSearchTool;\n}\n"],"mappings":";;;;;AAAA,SAAS,aAAa;AACtB,SAAS,eAAe;AACxB,SAAS,KAAAA,UAAS;;;ACFlB,SAAS,SAAS;AASX,IAAM,8BAA8B;AAEpC,SAAS,kBACd,SACsB;AACtB,6BAA2B,OAAO;AAClC,SAAO,kBAAkB,SAAS,cAAc;AAClD;AAEO,SAAS,2BAA2B,SAAmC;AAC5E,MAAI,OAAO,KAAK,QAAQ,KAAK,EAAE,WAAW,GAAG;AAC3C,UAAM,IAAI,UAAU,iDAAiD;AAAA,EACvE;AACA,aAAW,CAAC,MAAM,UAAU,KAAK,OAAO,QAAQ,QAAQ,KAAK,GAAG;AAC9D,oBAAgB,MAAM,WAAW;AACjC,sBAAkB,WAAW,aAAa,QAAQ,IAAI,EAAE;AACxD,QAAI,EAAE,WAAW,sBAAsB,EAAE,YAAY;AACnD,YAAM,IAAI,UAAU,uB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ACH;","names":["z","z","properties","properties","z"]}
|
package/package.json
CHANGED
|
@@ -1,15 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anvia/graph",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.0.4",
|
|
4
|
+
"description": "Provider-neutral knowledge graph primitives for Anvia.",
|
|
5
|
+
"author": "anvia",
|
|
6
|
+
"maintainer": "Indra Zulfi",
|
|
5
7
|
"license": "MIT",
|
|
6
|
-
"type": "module",
|
|
7
8
|
"repository": {
|
|
8
9
|
"type": "git",
|
|
9
|
-
"url": "https://github.com/anvia-hq/anvia
|
|
10
|
+
"url": "https://github.com/anvia-hq/anvia",
|
|
10
11
|
"directory": "packages/graph"
|
|
11
12
|
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
12
16
|
"publishConfig": {
|
|
13
17
|
"access": "public"
|
|
18
|
+
},
|
|
19
|
+
"type": "module",
|
|
20
|
+
"main": "./dist/index.js",
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"import": "./dist/index.js"
|
|
26
|
+
},
|
|
27
|
+
"./explore": {
|
|
28
|
+
"types": "./dist/explore.d.ts",
|
|
29
|
+
"import": "./dist/explore.js"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"zod": "^4.4.3"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@types/node": "^24.9.1",
|
|
37
|
+
"tsup": "^8.5.0",
|
|
38
|
+
"typescript": "^5.9.3",
|
|
39
|
+
"vitest": "^4.0.8",
|
|
40
|
+
"@anvia/core": "1.0.3"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"@anvia/core": "1.0.3"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "tsup src/index.ts src/explore.ts --format esm --dts --sourcemap --clean",
|
|
47
|
+
"test": "vitest run",
|
|
48
|
+
"typecheck": "tsc --noEmit"
|
|
14
49
|
}
|
|
15
|
-
}
|
|
50
|
+
}
|
package/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|