Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ function isSignificantKnowledge(content: string): boolean {
return false;
}

if (process.env.DISABLE_SIGNIFICANCE_FILTER === 'true') {
return true;
}

const text = content.toLowerCase().trim();

// Skip trivial tool results and non-technical content
Expand Down
4 changes: 4 additions & 0 deletions src/core/brain/tools/definitions/memory/workspace_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ function isWorkspaceSignificantContent(content: string): boolean {
return false;
}

if (process.env.DISABLE_SIGNIFICANCE_FILTER === 'true') {
return true;
}

const text = content.toLowerCase().trim();

// Skip patterns that are not workspace-relevant
Expand Down
4 changes: 4 additions & 0 deletions src/core/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ const envSchema = z.object({
USE_WORKSPACE_MEMORY: z.boolean().default(false),
WORKSPACE_SEARCH_THRESHOLD: z.number().default(0.4),
DISABLE_DEFAULT_MEMORY: z.boolean().default(false),
DISABLE_SIGNIFICANCE_FILTER: z.boolean().default(false),
WORKSPACE_VECTOR_STORE_TYPE: z
.enum(['qdrant', 'milvus', 'chroma', 'pinecone', 'pgvector', 'in-memory'])
.optional(),
Expand Down Expand Up @@ -350,6 +351,8 @@ export const env: EnvSchema = new Proxy({} as EnvSchema, {
: 0.4;
case 'DISABLE_DEFAULT_MEMORY':
return process.env.DISABLE_DEFAULT_MEMORY === 'true';
case 'DISABLE_SIGNIFICANCE_FILTER':
return process.env.DISABLE_SIGNIFICANCE_FILTER === 'true';
case 'WORKSPACE_VECTOR_STORE_TYPE':
return process.env.WORKSPACE_VECTOR_STORE_TYPE;
case 'WORKSPACE_VECTOR_STORE_HOST':
Expand Down Expand Up @@ -553,6 +556,7 @@ export const validateEnv = () => {
? parseFloat(process.env.WORKSPACE_SEARCH_THRESHOLD)
: 0.4,
DISABLE_DEFAULT_MEMORY: process.env.DISABLE_DEFAULT_MEMORY === 'true',
DISABLE_SIGNIFICANCE_FILTER: process.env.DISABLE_SIGNIFICANCE_FILTER === 'true',
WORKSPACE_VECTOR_STORE_TYPE: process.env.WORKSPACE_VECTOR_STORE_TYPE,
WORKSPACE_VECTOR_STORE_HOST: process.env.WORKSPACE_VECTOR_STORE_HOST,
WORKSPACE_VECTOR_STORE_PORT: process.env.WORKSPACE_VECTOR_STORE_PORT
Expand Down
126 changes: 62 additions & 64 deletions src/core/knowledge_graph/backend/neo4j.ts
Original file line number Diff line number Diff line change
Expand Up @@ -931,70 +931,68 @@ export class Neo4jBackend implements KnowledgeGraph {
return converted;
}

private buildFilterConstraints(
filters: NodeFilters | EdgeFilters,
prefix: string,
params: any
): string {
const constraints: string[] = [];

for (const [rawKey, filter] of Object.entries(filters)) {
const propertyKey = this.escapePropertyKey(rawKey);
const paramKey = `${prefix}_${Object.keys(params).length}`;

if (typeof filter === 'object' && filter !== null && !Array.isArray(filter)) {
// Range filters
if ('gte' in filter) {
constraints.push(`${prefix}.${propertyKey} >= $${paramKey}_gte`);
params[`${paramKey}_gte`] = filter.gte;
}
if ('gt' in filter) {
constraints.push(`${prefix}.${propertyKey} > $${paramKey}_gt`);
params[`${paramKey}_gt`] = filter.gt;
}
if ('lte' in filter) {
constraints.push(`${prefix}.${propertyKey} <= $${paramKey}_lte`);
params[`${paramKey}_lte`] = filter.lte;
}
if ('lt' in filter) {
constraints.push(`${prefix}.${propertyKey} < $${paramKey}_lt`);
params[`${paramKey}_lt`] = filter.lt;
}

// Array filters
if ('any' in filter && Array.isArray(filter.any)) {
constraints.push(`${prefix}.${propertyKey} IN $${paramKey}`);
params[paramKey] = filter.any;
}
if ('all' in filter && Array.isArray(filter.all)) {
// For 'all' filter, check if the property (assumed to be array) contains all values
constraints.push(
`all(x IN $${paramKey} WHERE x IN ${prefix}.${propertyKey})`
);
params[paramKey] = filter.all;
}
} else {
// Direct equality
constraints.push(`${prefix}.${propertyKey} = $${paramKey}`);
params[paramKey] = filter;
}
}

return constraints.join(' AND ');
}

private escapePropertyKey(key: string): string {
if (key.trim().length === 0) {
throw new Error('Filter property names must not be empty.');
}

if (/^[A-Za-z_][A-Za-z0-9_]*$/.test(key)) {
return key;
}

const escapedKey = key.replace(/`/g, '``');
return `\`${escapedKey}\``;
}
private buildFilterConstraints(
filters: NodeFilters | EdgeFilters,
prefix: string,
params: any
): string {
const constraints: string[] = [];

for (const [rawKey, filter] of Object.entries(filters)) {
const propertyKey = this.escapePropertyKey(rawKey);
const paramKey = `${prefix}_${Object.keys(params).length}`;

if (typeof filter === 'object' && filter !== null && !Array.isArray(filter)) {
// Range filters
if ('gte' in filter) {
constraints.push(`${prefix}.${propertyKey} >= $${paramKey}_gte`);
params[`${paramKey}_gte`] = filter.gte;
}
if ('gt' in filter) {
constraints.push(`${prefix}.${propertyKey} > $${paramKey}_gt`);
params[`${paramKey}_gt`] = filter.gt;
}
if ('lte' in filter) {
constraints.push(`${prefix}.${propertyKey} <= $${paramKey}_lte`);
params[`${paramKey}_lte`] = filter.lte;
}
if ('lt' in filter) {
constraints.push(`${prefix}.${propertyKey} < $${paramKey}_lt`);
params[`${paramKey}_lt`] = filter.lt;
}

// Array filters
if ('any' in filter && Array.isArray(filter.any)) {
constraints.push(`${prefix}.${propertyKey} IN $${paramKey}`);
params[paramKey] = filter.any;
}
if ('all' in filter && Array.isArray(filter.all)) {
// For 'all' filter, check if the property (assumed to be array) contains all values
constraints.push(`all(x IN $${paramKey} WHERE x IN ${prefix}.${propertyKey})`);
params[paramKey] = filter.all;
}
} else {
// Direct equality
constraints.push(`${prefix}.${propertyKey} = $${paramKey}`);
params[paramKey] = filter;
}
}

return constraints.join(' AND ');
}

private escapePropertyKey(key: string): string {
if (key.trim().length === 0) {
throw new Error('Filter property names must not be empty.');
}

if (/^[A-Za-z_][A-Za-z0-9_]*$/.test(key)) {
return key;
}

const escapedKey = key.replace(/`/g, '``');
return `\`${escapedKey}\``;
}

private async createIndexes(): Promise<void> {
const session = this.getSession();
Expand Down
Loading