Find answers from the community

Updated 3 months ago

Hi I m trying to design and utilize a

Hi, I'm trying to design and utilize a Document type with metadata which also permits hybrid/filtered queries. I was unable to find a good tutorial on this unfortunately and I'm not exactly sure how to proceed. My use case is pretty simple: I have a JSON doc which encapsulates a conversation between 2 or more parties. I want to encode the doc so that it includes metadata like date, speaker, timestamps, and then make it possible restrict the target of the vector-based retrieval to a traditional query. For example, index 10 conversations, then formulate a complex query: "tell me about conversations from yesterday". Here "yesterday" can be transliterated into a timestamp, and then the retrieval process should focus on only the subset of documents with timestamps in that range. I can't see a way to easily do this at the moment, except maybe using OpenSearch somehow?
1
T
c
k
11 comments
Metadata filtering at least was just added to SimpleVectorIndex, did you get a chance to look at it yet? https://gpt-index.readthedocs.io/en/stable/examples/vector_stores/SimpleIndexDemo.html
There are also some similar implementations here if you need inspiration for the time part: https://gpt-index.readthedocs.io/en/stable/examples/node_postprocessor/TimeWeightedPostprocessorDemo.html
@Teemu thank you for the response! Yes I looked at the SimpleIndexDemo and the custom document builder:
The one thing I couldn't find was a way to utilize the MetaDataFilters with a range query. But it looks like if I use OpenSearch as the vectorstore I can just piggypack my queries on the traditional ES/OS search filters. Maybe this is the best overall strategy?
This should make it comparatively easy to also do things like ask about 'start' and 'end' or even timestamps or replies. For example if I index individual dialog turns or chunks along with timestamps, I can ask about 'the beginning' of the conversation, or 'how speaker B ended the conversation'
The recency example you shared is also really interesting.
I'm going to try and cook up something with the OpenSearch demo as a base for now and see if I can achieve my goals with that. I guess this also makes it possible to deduplicate results based on 'complete' document? E.g., if we return top-5 based on filter plus vector similarity search, then those top-5 should be 5 separate documents, and not 5 snippets from one document.
@Teemu one last question, just in case you know the answer. I tried with ask-kapa bot but it wasn't sure:I'm not performing text generation at the moment, I'm just trying to run the indexing subroutine. I'm using the following code snippet. I don't think there should be any calls being made to Llama.cpp, however even with the below the program complains: Could not import llama_cpp library.:

Plain Text
###Setup the embedding model
embed_model = HuggingFaceEmbeddings(
    model_name="sentence-transformers/all-mpnet-base-v2"
)
service_context = ServiceContext.from_defaults(embed_model=embed_model)
# optionally set a global service context
set_global_service_context(service_context)



# http endpoint for your cluster (opensearch required for vector index usage)
endpoint = getenv("OPENSEARCH_ENDPOINT", "http://localhost:9200")
# index to demonstrate the VectorStore impl
idx = getenv("OPENSEARCH_INDEX", "gpt-index-demo")
# load some sample data
documents = SimpleDirectoryReader("../paul_graham_essay/data").load_data()

# 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
)

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 = VectorStoreIndex.from_documents(
    documents=documents,
    storage_context=storage_context,
    service_context=service_context
)
Let me check the knowledge base for you. One moment! :books:
----------------------
Based on the code snippet you provided, it seems like you're trying to create a VectorStoreIndex using the OpensearchVectorStore with the HuggingFaceEmbeddings model. The error message you're encountering, Could not import llama_cpp library, is typically thrown when the LlamaIndex tries to use the LlamaCPP model, which is not the case here.

However, it's important to note that the LlamaIndex might still try to import the llama_cpp library as part of its initialization process, even if you're not explicitly using the LlamaCPP model. If the llama_cpp library is not installed in your environment, this could lead to the error you're seeing.

Unfortunately, the extracts provided do not contain specific information on how to resolve this issue. I would recommend ensuring that the llama_cpp library is correctly installed in your environment, even if you're not directly using it.

For more detailed information, you might want to refer to the LlamaIndex documentation ().
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Set the llm to None here

Plain Text
service_context = ServiceContext.from_defaults(embed_model=embed_model, llm=None)


Otherwise it defaults to openai/local models
Add a reply
Sign up and join the conversation on Discord