Skip to content

Vector index for Pandas dataframe like shown in Advanced text to sql. #14855

Answered by dosubot bot
mraguth asked this question in Q&A
Discussion options

You must be logged in to vote

To fix the AttributeError: 'str' object has no attribute 'text' error, you need to ensure that the documents being passed to VectorStoreIndex are in the correct format and not just plain strings. Here is an example of how you can load documents correctly and index them:

import pandas as pd
from llama_index.core.schema import TextNode
from llama_index.core.storage import StorageContext
from llama_index.core import VectorStoreIndex
import os
from pathlib import Path

def index_dataframe(df: pd.DataFrame, index_dir: str = "dataframe_index_dir") -> VectorStoreIndex:
    """Index a Pandas DataFrame."""
    if not Path(index_dir).exists():
        os.makedirs(index_dir)

    # Convert DataFram…

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@mraguth
Comment options

@dosubot
Comment options

@mraguth
Comment options

@dosubot
Comment options

Answer selected by mraguth
@mraguth
Comment options

@dosubot
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant