W
Wasp6d ago
NEROX

ERROR: extension "vector" is not available

Database error: ERROR: extension "vector" is not available DETAIL: Could not open extension control file "/usr/share/postgresql/16/extension/vector.control": No such file or directory. HINT: The extension must first be installed on the system where PostgreSQL is running. DbError { severity: "ERROR", parsedseverity: Some(Error), code: SqlState(E0A000), message: "extension "vector" is not available", detail: Some("Could not open extension control file "/usr/share/postgresql/16/extension/vector.control": No such file or directory."), hint: l: Some("Could not Some("The extension must first be installed on the system where PostgreSQL is running."), position: None, where: None, schema: None, tabl must first be inste: None, column: None, datatype: None, constraint: None, file: Some("extension.c"), line: Some(543), routine: Some("parse_extension_contro constraint: None, l_file") }
13 Replies
kapa.ai
kapa.ai6d ago
Hi @NEROX. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- This error is related to using the PostgreSQL vector extension with Wasp. The error indicates that the vector extension is not installed on your PostgreSQL system. To resolve this issue, you need to install the pgvector extension on your PostgreSQL database. Here are some steps to help you: 1. First, make sure you have enabled PostgreSQL extensions in your Wasp project. You can do this by adding the following configuration to your main.wasp file:
app MyApp {
// ...
db: {
system: PostgreSQL,
prisma: {
clientPreviewFeatures: ["postgresqlExtensions"]
}
}
}
app MyApp {
// ...
db: {
system: PostgreSQL,
prisma: {
clientPreviewFeatures: ["postgresqlExtensions"]
}
}
}
2. Then, you need to specify the pgvector extension in your Wasp configuration:
app MyApp {
// ...
db: {
system: PostgreSQL,
prisma: {
clientPreviewFeatures: ["postgresqlExtensions"],
dbExtensions: [
{ name: "vector" }
]
}
}
}
app MyApp {
// ...
db: {
system: PostgreSQL,
prisma: {
clientPreviewFeatures: ["postgresqlExtensions"],
dbExtensions: [
{ name: "vector" }
]
}
}
}
3. After configuring Wasp, you need to install the pgvector extension on your PostgreSQL database. The exact steps may vary depending on your setup, but generally, you'll need to: a. Install the pgvector extension on your system. b. Enable the extension in your PostgreSQL database. 4. Once the extension is installed and enabled, try running your Wasp application again. If you're using a cloud database provider like Supabase, you may need to enable the pgvector extension through their interface. For more detailed information on configuring PostgreSQL extensions in Wasp, you can refer to the Wasp documentation on Prisma Configuration. If you continue to face issues, you may need to consult your PostgreSQL system administrator or the documentation of your database hosting provider for specific instructions on installing and enabling the pgvector extension. Wasp Docs: Prisma Configuration ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @NEROX, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
NEROX
NEROXOP6d ago
you are on drugs Kapa @kapa.ai [ Wasp ] ext-src/server/documents/operations.ts(24,42): error TS2339: Property 'create' does not exist on type 'DocumentChunkDelegate<DefaultArgs>'. operations.ts: import { Document } from 'wasp/entities' import { createDocumentChunks, generateEmbedding } from '../utils/documentProcessing' import type { ProcessDocument } from 'wasp/server/operations' export const processDocument: ProcessDocument<{ documentId: number }, void> = async (args, context) => { const { documentId } = args;
const document = await context.entities.Document.findUnique({ where: { id: documentId } }); if (!document || !document.content) { throw new Error('Document not found or has no content'); } // Create chunks const chunks = createDocumentChunks(document.content); // Process each chunk for (const chunk of chunks) { const embedding = await generateEmbedding(chunk.content);
// Store chunk and embedding usando entities await context.entities.DocumentChunk.create({ data: { content: chunk.content, embedding: embedding, metadata: chunk.metadata, documentId: document.id } }); } // Update document status usando entities await context.entities.Document.update({ where: { id: document.id }, data: { status: 'completed' } }); }
kapa.ai
kapa.ai6d ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- The error you're encountering suggests that the DocumentChunk entity is not properly set up or recognized in your Wasp project. This could be due to a few reasons: 1. The DocumentChunk entity might not be defined in your main.wasp file. 2. There might be a mismatch between your entity definitions and the generated Prisma schema. 3. The Wasp compiler might not have updated the generated files after recent changes. To resolve this issue, try the following steps: 1. Make sure you have defined the DocumentChunk entity in your main.wasp file. It should look something like this:
entity DocumentChunk {=psl
id Int @id @default(autoincrement())
content String
embedding Json
metadata Json
document Document @relation(fields: [documentId], references: [id])
documentId Int
psl=}
entity DocumentChunk {=psl
id Int @id @default(autoincrement())
content String
embedding Json
metadata Json
document Document @relation(fields: [documentId], references: [id])
documentId Int
psl=}
2. After defining or updating the entity, run wasp db migrate-dev to create a new migration and update your database schema. 3. Restart your Wasp development server with wasp start to ensure all generated files are up to date. If the problem persists, you might need to use the Prisma Client directly instead of the context.entities API. You can do this by importing the Prisma client in your operations file:
import { prisma } from 'wasp/server'

// ...

await prisma.documentChunk.create({
data: {
content: chunk.content,
embedding: embedding,
metadata: chunk.metadata,
documentId: document.id
}
});
import { prisma } from 'wasp/server'

// ...

await prisma.documentChunk.create({
data: {
content: chunk.content,
embedding: embedding,
metadata: chunk.metadata,
documentId: document.id
}
});
Remember to update your main.wasp file to include the DocumentChunk entity in the processDocument action:
action processDocument {
fn: import { processDocument } from "@server/documents/operations.js",
entities: [Document, DocumentChunk]
}
action processDocument {
fn: import { processDocument } from "@server/documents/operations.js",
entities: [Document, DocumentChunk]
}
If you're still facing issues, it might be helpful to check the generated Prisma schema in .wasp/out/server/prisma/schema.prisma to ensure all your entities are correctly defined. For more information on working with entities in Wasp, you can refer to the Wasp documentation on Entities. Wasp Docs: Entities ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @NEROX, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
NEROX
NEROXOP6d ago
@kapa.ai [ Wasp ] ext-src/server/documents/operations.ts(25,32): error TS2339: Property 'upsert' does not exist on type 'DocumentChunkDelegate<DefaultArgs>'. [ Wasp ] ext-src/server/documents/operations.ts(27,19): error TS2339: Property 'id' does not exist on type '{ content: string; metadata: ChunkMetadata; }'. import { Document } from 'wasp/entities' import { createDocumentChunks, generateEmbedding } from '../utils/documentProcessing' import type { ProcessDocument } from 'wasp/server/operations' import { prisma } from 'wasp/server' export const processDocument: ProcessDocument<{ documentId: number }, void> = async (args, context) => { const { documentId } = args;
const document = await prisma.document.findUnique({ where: { id: documentId } }); if (!document !document.content) { throw new Error('Document not found or has no content'); } // Create chunks const chunks = createDocumentChunks(document.content); // Process each chunk for (const chunk of chunks) { const embedding = await generateEmbedding(chunk.content);
// Store chunk and embedding usando upsert await prisma.documentChunk.upsert({ where: { id: chunk.id
'temp-id', // necesitamos un id para upsert }, create: { content: chunk.content, embedding: embedding, metadata: chunk.metadata, documentId: document.id }, update: { content: chunk.content, embedding: embedding, metadata: chunk.metadata, } }); } // Update document status await prisma.document.update({ where: { id: document.id }, data: { status: 'completed' } }); }
kapa.ai
kapa.ai6d ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- The errors you're encountering are related to the structure of your DocumentChunk entity and the createDocumentChunks function. Let's address these issues: 1. The upsert operation is available on Prisma Client, but it seems that the DocumentChunk entity might not be properly defined in your Wasp project. 2. The id property doesn't exist on the chunks created by createDocumentChunks, which is causing the second error. To resolve these issues, try the following: 1. Make sure your DocumentChunk entity is properly defined in your main.wasp file:
entity DocumentChunk {=psl
id String @id @default(uuid())
content String
embedding Json
metadata Json
document Document @relation(fields: [documentId], references: [id])
documentId Int
psl=}
entity DocumentChunk {=psl
id String @id @default(uuid())
content String
embedding Json
metadata Json
document Document @relation(fields: [documentId], references: [id])
documentId Int
psl=}
2. Update your processDocument function to handle chunks without an id:
import { Document } from 'wasp/entities'
import { createDocumentChunks, generateEmbedding } from '../utils/documentProcessing'
import type { ProcessDocument } from 'wasp/server/operations'
import { prisma } from 'wasp/server'

export const processDocument: ProcessDocument<{ documentId: number }, void> = async (args, context) => {
const { documentId } = args;

const document = await prisma.document.findUnique({
where: { id: documentId }
});

if (!document || !document.content) {
throw new Error('Document not found or has no content');
}

// Create chunks
const chunks = createDocumentChunks(document.content);
// Process each chunk
for (const chunk of chunks) {
const embedding = await generateEmbedding(chunk.content);

// Store chunk and embedding using create
await prisma.documentChunk.create({
data: {
content: chunk.content,
embedding: embedding,
metadata: chunk.metadata,
documentId: document.id
}
});
}

// Update document status
await prisma.document.update({
where: { id: document.id },
data: { status: 'completed' }
});
}
import { Document } from 'wasp/entities'
import { createDocumentChunks, generateEmbedding } from '../utils/documentProcessing'
import type { ProcessDocument } from 'wasp/server/operations'
import { prisma } from 'wasp/server'

export const processDocument: ProcessDocument<{ documentId: number }, void> = async (args, context) => {
const { documentId } = args;

const document = await prisma.document.findUnique({
where: { id: documentId }
});

if (!document || !document.content) {
throw new Error('Document not found or has no content');
}

// Create chunks
const chunks = createDocumentChunks(document.content);
// Process each chunk
for (const chunk of chunks) {
const embedding = await generateEmbedding(chunk.content);

// Store chunk and embedding using create
await prisma.documentChunk.create({
data: {
content: chunk.content,
embedding: embedding,
metadata: chunk.metadata,
documentId: document.id
}
});
}

// Update document status
await prisma.document.update({
where: { id: document.id },
data: { status: 'completed' }
});
}
In this updated version, we're using create instead of upsert since we're always creating new chunks. If you need to update existing chunks, you'll need to implement a way to identify unique chunks, possibly by using a hash of the content or some other unique identifier. After making these changes: 1. Run wasp db migrate-dev to update your database schema. 2. Restart your Wasp development server with wasp start. If you're still facing issues, double-check that your main.wasp file includes the DocumentChunk entity in the processDocument action:
action processDocument {
fn: import { processDocument } from "@server/documents/operations.js",
entities: [Document, DocumentChunk]
}
action processDocument {
fn: import { processDocument } from "@server/documents/operations.js",
entities: [Document, DocumentChunk]
}
For more information on working with entities and Prisma in Wasp, you can refer to the Wasp documentation on Entities. Wasp Docs: Entities ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @NEROX, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
NEROX
NEROXOP5d ago
@kapa.ai [ Server!] Unknown argument embedding. Available options are marked with ?.
kapa.ai
kapa.ai5d ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- This error suggests that there's a mismatch between your Prisma schema and the data you're trying to insert into the DocumentChunk entity. Specifically, the embedding field is not recognized in your Prisma schema for the DocumentChunk model. To resolve this issue, you need to ensure that the embedding field is properly defined in your DocumentChunk entity in the main.wasp file. Here's what you should do: 1. Open your main.wasp file and locate the DocumentChunk entity definition. 2. Make sure the embedding field is included in the entity definition. It should look something like this:
entity DocumentChunk {=psl
id String @id @default(uuid())
content String
embedding Json // Make sure this line is present
metadata Json
document Document @relation(fields: [documentId], references: [id])
documentId Int
psl=}
entity DocumentChunk {=psl
id String @id @default(uuid())
content String
embedding Json // Make sure this line is present
metadata Json
document Document @relation(fields: [documentId], references: [id])
documentId Int
psl=}
3. After updating the entity definition, you need to create a new migration to apply these changes to your database schema. Run the following command:
wasp db migrate-dev
wasp db migrate-dev
4. Once the migration is complete, restart your Wasp development server:
wasp start
wasp start
If you've made these changes and are still encountering the error, double-check that the embedding field in your processDocument function matches the type defined in your schema (in this case, Json). For more information on defining entities and working with Prisma in Wasp, you can refer to the Wasp documentation on Entities. Wasp Docs: Entities If you continue to face issues after following these steps, please provide more details about your main.wasp file and the processDocument function, so I can offer more specific guidance. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @NEROX, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
NEROX
NEROXOP5d ago
I've made it work, thx Kapa @kapa.ai Is it possible in Wasp Apps: - Implement Re-ranking using crossencoders after initial search - Use Hybrid Search (combine semantic search with BM25) - Implement MMR (Maximal Marginal Relevance) to diversify results ??
kapa.ai
kapa.ai5d ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- Based on the knowledge sources provided, there isn't specific information about implementing re-ranking using cross-encoders, hybrid search combining semantic search with BM25, or implementing MMR (Maximal Marginal Relevance) in Wasp apps. However, Wasp is a framework that allows you to build full-stack web applications using React, Node.js, and Prisma. This means that while Wasp doesn't provide these features out-of-the-box, you can likely implement them yourself using custom JavaScript/TypeScript code in your Wasp project. Wasp does have some support for working with embeddings and vector similarity search. For example, there's a Vector Similarity Search Template that includes features for embeddings and vector similarity search using OpenAI Embeddings API and a Vector DB (Pinecone). Additionally, there's an example RAG (Retrieval-Augmented Generation) app built with Wasp that uses Pinecone for vector search: Ask the Documents. To implement the specific features you're asking about (re-ranking, hybrid search, MMR), you would likely need to: 1. Use the appropriate libraries or APIs in your Node.js backend code. 2. Integrate these with your database and search infrastructure. 3. Create the necessary queries and actions in your Wasp app to expose these features to your frontend. While it's possible to implement these features in a Wasp app, you would need to handle much of the implementation yourself, as Wasp doesn't provide built-in support for these specific search and ranking algorithms. If you need more detailed guidance on implementing these features in Wasp, you might want to consult the Wasp documentation or reach out to the Wasp community for more specific advice. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @NEROX, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
NEROX
NEROXOP5d ago
HAH, I did without pinecone:smugboi:
Vinny (@Wasp)
Vinny (@Wasp)5d ago
are you getting it working?
NEROX
NEROXOP5d ago
Yes Now I'm adding improvements But too many trial and error with Cursor, a lot of hours to add small features, IDK how to improve my development @kapa.ai Type error: Unexpected dictionary field 'middleware' -> For dictionary field 'server' 97 | 98 | server: { 99 | middleware: import { initializeMiddleware } from "@src/server/middleware.js" 100 | }, 101 | } ❌ --- [Error] Recompilation on file change failed.: ------------------------------ 1 errors found main.wasp: server: { middleware: import { initializeMiddleware } from "@src/server/middleware.js" }, } middleware.ts: import { Application } from 'express'; export default function initializeMiddleware(app: Application) { // Aumentar el límite del payload a 50MB app.use(express.json({ limit: '50mb' })); app.use(express.urlencoded({ extended: true, limit: '50mb' })); } whats wrong?
kapa.ai
kapa.ai5d ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- The error you're encountering is due to an incorrect configuration in your main.wasp file. The server dictionary in Wasp doesn't have a middleware field. Instead, Wasp uses a middlewareConfigFn for configuring middleware. Let's correct this: 1. Update your main.wasp file: Replace:
server: {
middleware: import { initializeMiddleware } from "@src/server/middleware.js"
},
server: {
middleware: import { initializeMiddleware } from "@src/server/middleware.js"
},
With:
server: {
middlewareConfigFn: import { serverMiddlewareFn } from "@src/server/middleware.js"
},
server: {
middlewareConfigFn: import { serverMiddlewareFn } from "@src/server/middleware.js"
},
2. Update your middleware.ts file: Change the function name and its signature to match the expected MiddlewareConfigFn type:
import express from 'express';
import { MiddlewareConfigFn } from 'wasp/server';

export const serverMiddlewareFn: MiddlewareConfigFn = (middlewareConfig) => {
// Increase payload limit to 50MB
middlewareConfig.set('express.json', express.json({ limit: '50mb' }));
middlewareConfig.set('express.urlencoded', express.urlencoded({ extended: true, limit: '50mb' }));

return middlewareConfig;
}
import express from 'express';
import { MiddlewareConfigFn } from 'wasp/server';

export const serverMiddlewareFn: MiddlewareConfigFn = (middlewareConfig) => {
// Increase payload limit to 50MB
middlewareConfig.set('express.json', express.json({ limit: '50mb' }));
middlewareConfig.set('express.urlencoded', express.urlencoded({ extended: true, limit: '50mb' }));

return middlewareConfig;
}
These changes should resolve the type error you're seeing. The middlewareConfigFn is the correct way to configure global middleware in Wasp. For more information on configuring middleware in Wasp, you can refer to the Wasp documentation on Configuring Middleware. Wasp Docs: Configuring Middleware After making these changes, try running your Wasp application again. If you encounter any further issues, please let me know. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @NEROX, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?

Did you find this page helpful?