run-llama / LlamaIndexTS

Data framework for your LLM applications. Focus on server side solution
https://ts.llamaindex.ai
MIT License
1.92k stars 355 forks source link

LlamaIndexTS - MongoDB - 2_load_and_index.ts #1104

Open TiUh opened 3 months ago

TiUh commented 3 months ago

The MongoDB Node.js example has a problem in the second demo script: 2_load_and_index.ts

Here the creating of a search index is defined as following:

  const index = {
    name: indexName,
    definition: {
      mappings: {
        dynamic: true,
        fields: [
          {
            type: "vector",
            path: "embedding",
            numDimensions: 1536,
            similarity: "cosine",
          },
        ],
      },
    },
  };

but this fails with an exception. The solution is creating the index as following:

const index = {
    name: indexName,
    type: "vectorSearch",
    definition: {
      "fields": [
        {
          "type": "vector",
          "path": "embedding",
          "numDimensions": 1536,
          "similarity": "cosine"
        }
      ]
    }

Reference: https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-type/

marcusschiesser commented 3 months ago

@TiUh great catch! Mind to to send a PR for this?