0

I have this code where I am able to create an index in Opensearch Elasticsearch:

def openes_initiate(file):
    

    endpoint = getenv("OPENSEARCH_ENDPOINT", "http://localhost:9200")
    # index to demonstrate the VectorStore impl
    idx = getenv("OPENSEARCH_INDEX", "llama-osindex-demo")
    
    UnstructuredReader = download_loader("UnstructuredReader")

    loader = UnstructuredReader()
    documents = loader.load_data(file=Path(file))

    # OpensearchVectorClient stores text in this field by default
    text_field = "content"
    # OpensearchVectorClient stores embeddings in this field by default
    embedding_field = "embedding"
    # OpensearchVectorClient encapsulates logic for a
    # single opensearch index with vector search enabled
    client = OpensearchVectorClient(endpoint, idx, 1536, embedding_field=embedding_field, text_field=text_field)
    # initialize vector store
    vector_store = OpensearchVectorStore(client)
    storage_context = StorageContext.from_defaults(vector_store=vector_store)
    # initialize an index using our sample data and the client we just created
    index = GPTVectorStoreIndex.from_documents(documents=documents,storage_context=storage_context)

Issue I am having is that once I have indexed the data, I am unable to reload it and serve a query against it. I tried to do this:

def query(index,question):
    query_engine = index.as_query_engine()
    res = query_engine.query(question)
    print(res.response)

Where index is the one I created in first piece of code, but it returns None

user2966197
  • 2,793
  • 10
  • 45
  • 77

1 Answers1

0

you need to create open-search client and load index with VectorStoreIndex.from_vector_store() before you can run query on it,

index object is null which will not generate null result.