Find answers from the community

Updated 6 months ago

I am exploring property graph index.

At a glance

The community member is exploring property graph index and has provided code for the Implicit Extraction Method, which seems to work with Azure OpenAI LLM Settings. However, the community member encountered an issue with the Schema-Guided Extraction Method, receiving an AuthenticationError related to the OpenAI API key. The community member confirmed that the API key is correct and works for creating a normal vector store.

The community members discussed potential issues with the Settings.llm and Settings.embed_model configurations, and the need for a stack trace to further investigate the problem. The issue was eventually fixed, but the community members are still discussing whether multiple vector indexes are required for different extraction methods or if a single vector index can be used with changes in the property graph store.

Useful resources
I am exploring property graph index.

This code seems to work with Azure OpenAI LLM Settings.
Plain Text
# Property Graph Construction: Implicit Extraction Method
from llama_index.core.indices.property_graph import ImplicitPathExtractor
import nest_asyncio
from llama_index.core import PropertyGraphIndex

# Apply nest_asyncio to avoid runtime errors in async environments
nest_asyncio.apply()

# Initialize Azure AI Search vector store
vector_store = AzureAISearchVectorStore(
    search_or_index_client=index_client,
    index_name=INDEX_NAME,
    index_management=IndexManagement.CREATE_IF_NOT_EXISTS,
    id_field_key="id",
    chunk_field_key="text",
    embedding_field_key="embedding",
    embedding_dimensionality=3072,  # Adjust to match embedding model output (like ada-002)
    metadata_string_field_key="metadata",
    doc_id_field_key="doc_id",
    language_analyzer="en.lucene",
    vector_algorithm_type="exhaustiveKnn",
    compression_type="binary"
)

# Construct the property graph index with implicit path extraction
index = PropertyGraphIndex.from_documents(
    documents,
    llm=llm,
    embed_model=embed_model,
    vector_store=vector_store,
    show_progress=True,
)

I can confirm my vector store in Azure AI SEarch looks correct.
f
L
10 comments
But this code using schema-guided extraction fails:

Plain Text
# Schema-Guided Extraction Method
from typing import Literal
from llama_index.core.indices.property_graph import SchemaLLMPathExtractor

# Define the schema for entity types and relationships
entities = Literal["PERSON", "PLACE", "THING"]
relations = Literal["PART_OF", "HAS", "IS_A"]
schema = {
    "PERSON": ["HAS", "IS_A"],
    "PLACE": ["PART_OF", "HAS"],
    "THING": ["IS_A"],
}

# Initialize the schema-based extractor
kg_extractor = SchemaLLMPathExtractor(
    llm=llm,
    possible_entities=entities,
    possible_relations=relations,
    kg_validation_schema=schema,
    strict=True,  # Disallow extractions outside the schema
)

# Construct the property graph index using the schema-guided extractor
index_schema = PropertyGraphIndex.from_documents(
    documents,
    kg_extractors=[kg_extractor],
    vector_store=vector_store,
    show_progress=True,
)


AuthenticationError: Error code: 401 - {'error': {'message': 'Incorrect API key provided: c39162c5**5418. You can find your API key at https://platform.openai.com/account/api-keys.', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_api_key'}

---
It seems like the Settings.llm isn't being applied and is looking for an openai key vs azure openai key?
I can 100% confirm tis API key is correct as it works for creating a normal vector store.
Did you set Settings.llm and Settings.embed_model ? Hard to say if this error is from the LLM or the embed model
The stack trace would probably be helpful
On another note @Logan M , do I need to create multiple vector indexes (eg. llamaindex-simplellmpathextractor, llamaindex-schema-guidedextractor, llamaindex-free-formextractor,etc) or do I only need a single vector index and the changes on the type are on the property graph store?
I think you need a vector store (or collection/table in your vector store) for each PropertyGraphIndex you want to create
Not following exactly, here is what a node looks like inside of my search index after I run this:

Plain Text
# Free-Form Extraction Method
from llama_index.core.indices.property_graph import SimpleLLMPathExtractor

# Initialize the free-form extractor
kg_extractor_free = SimpleLLMPathExtractor()

# Construct the property graph index using free-form extraction
index_free_form = PropertyGraphIndex.from_documents(
    documents,
    kg_extractors=[kg_extractor_free],
    vector_store=vector_store,
    show_progress=True,
)
Attachment
image.png
That looks fine to me? πŸ‘€
Add a reply
Sign up and join the conversation on Discord