You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I added a very descriptive title to this question.
I searched the LangChain documentation with the integrated search.
I used the GitHub search to find a similar question and didn't find it.
Commit to Help
I commit to help with one of those options 👆
Example Code
import{createClient}from"@libsql/client";importpathfrom"node:path";import{LlamaCppEmbeddings}from"@langchain/community/embeddings/llama_cpp";import{join}from"path";import{PDFLoader}from"@langchain/community/document_loaders/fs/pdf";import{RecursiveCharacterTextSplitter}from"@langchain/textsplitters";import{Document}from'@langchain/core/documents';import{fileURLToPath}from"node:url";import{LibSQLVectorStore}from"@langchain/community/vectorstores/libsql";// we need this function to pad the embeddings to the correct size, somehow vectorstres addDocument function does not do thisfunctionpadOrTruncateEmbedding(embedding: number[],targetSize: number): number[]{if(embedding.length<targetSize){return[...embedding, ...newArray(targetSize-embedding.length).fill(0)];}returnembedding;}// create DB and indexes, the vector size for llamacpp is 4096constclient=createClient({url: 'file:local.db'});awaitclient.batch([`CREATE TABLE IF NOT EXISTS vectors ( id INTEGER PRIMARY KEY AUTOINCREMENT, content TEXT, metadata TEXT, embedding F32_BLOB(4096) );`,`CREATE INDEX IF NOT EXISTS vector_idx ON vectors (libsql_vector_idx(embedding));`,],'write');// create embeddingmodelconst__filename=fileURLToPath(import.meta.url);const__dirname=path.dirname(__filename);constllamaEmbeddings=awaitLlamaCppEmbeddings.initialize({modelPath: path.join(join(__dirname,'/llm-model'),'Mistral-7B-Instruct-v0.3.Q4_K_M.gguf')});// get pdfloader and split the pdf into chunksconstloader=newPDFLoader('testpdf');constdocs=awaitloader.load();consttextSplitter=newRecursiveCharacterTextSplitter({chunkSize: 2000,chunkOverlap: 500});constsplits: Document[]=awaittextSplitter.splitDocuments(docs);console.log('Splits:',splits.length);// create the vectorstore and embed the documentconsttestVectorStore=newLibSQLVectorStore(llamaEmbeddings,{db: client,});constembeddings=awaitllamaEmbeddings.embedDocuments(splits.map((doc)=>doc.pageContent));embeddings.forEach((embedding,i)=>{embeddings[i]=padOrTruncateEmbedding(embedding,4096);});awaittestVectorStore.addVectors(embeddings,splits);constquestion='give me all words in the documents that relate to the word drugs'console.log('Retrieving documents for question:',question);constretrievedDocs=awaittestVectorStore.similaritySearch(question);console.log(retrievedDocs)
A similar discussion regarding the error "vector index(search): failed to parse vector index parameters" when using LibSQL with LangChain can be found here[1].
To resolve this error, ensure the following:
Table and Column Setup: Verify that the table and embedding column are correctly defined. The embedding column should match the dimensions of your vector model. For example, if using LlamaCpp embeddings with a vector size of 4096, the column should be defined as F32_BLOB(4096).
CREATETABLEIF NOT EXISTS vectors (
id INTEGERPRIMARY KEY AUTOINCREMENT,
content TEXT,
metadata TEXT,
embedding F32_BLOB(4096)
);
Index Creation: Ensure the index on the embedding column is created correctly. The index should use the libsql_vector_idx function.
CREATEINDEXIF NOT EXISTS vector_idx ON vectors (libsql_vector_idx(embedding));
Configuration: Check that your vector store configuration matches the expected parameters, including the vector size and index usage.
By following these steps, you should be able to resolve the parsing error related to vector index parameters [2].
Discussed in #7531
Originally posted by binaryArrow January 15, 2025
Checked other resources
Commit to Help
Example Code
Description
I am trying to use Libsql vectorstore to embed pdf content into it and do a RAG on the documents. It fails to even do the similaritysearch. I get the following Error:
Error: vector index(search): failed to parse vector index parameters
.For the code to work you need the LLM Model, i opened a repo reproducing this error https://github.com/binaryArrow/libsql-index-error-reproduction.
The code does create the database and creates the embeddings, but using it fails.
My resources i used are:
https://js.langchain.com/docs/integrations/vectorstores/libsql/
https://docs.turso.tech/features/ai-and-embeddings#vector-index
System Info
The text was updated successfully, but these errors were encountered: