代码之家  ›  专栏  ›  技术社区  ›  arun

LangChain:XML文件的索引和查询

  •  0
  • arun  · 技术社区  · 2 年前

    我使用了UnstructuredXMLLoader API( https://python.langchain.com/docs/integrations/document_loaders/xml )用于加载示例XML文件[https://learn.microsoft.com/en-us/previous-versions/windows/desktop/ms762271(v=vs.85)]。

    我能够成功地加载内容,但是我不确定索引查询XML文档的最佳方式。VectorStoreIndexCreator适用于XML文件吗?

    如果有任何建议/指示,我将不胜感激。

    0 回复  |  直到 2 年前
        1
  •  0
  •   jdweng    2 年前

    请尝试以下操作:

    using assembly System.Xml.Linq
    $filename = "c:\temp\test.xml"
    
    $doc = [System.Xml.Linq.XDocument]::Load($filename)
    
    $books = $doc.Descendants("book")
    $table =  [System.Collections.ArrayList]@()
    foreach($book in $books)
    {
     
       $id =  $book.Attribute("id").Value
       $author = $book.Element("author").Value
       $title = $book.Element("title").Value
       $genre = $book.Element("genre").Value
       $price = $book.Element("price").Value
       $date = $book.Element("publish_date").Value
       $description = $book.Element("description").Value
       $row = [psobject]@{
          ID = $id
          Author=$author
          Title=$title
          Genre=$genre
          Price=$price
          Date=$date
          Description=$description
        }
        $table.Add($row) | out-null
    }
    $table | Format-Table