Skip to content

Commit

Permalink
Merge pull request #385 from twinnydotdev/fix/embeddings-database
Browse files Browse the repository at this point in the history
Fix embeddings database update lancedb
  • Loading branch information
rjmacarthy authored Nov 12, 2024
2 parents f4229a4 + 331fcd4 commit a57566c
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 124 deletions.
93 changes: 31 additions & 62 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "twinny",
"displayName": "twinny - AI Code Completion and Chat",
"description": "Locally hosted AI code completion plugin for vscode",
"version": "3.18.12",
"version": "3.19.0",
"icon": "assets/icon.png",
"keywords": [
"code-inference",
Expand Down Expand Up @@ -464,7 +464,7 @@
"web-tree-sitter": "^0.22.1"
},
"dependencies": {
"@lancedb/lancedb": "^0.9.0",
"@lancedb/lancedb": "^0.12.0",
"@tiptap/extension-mention": "^2.5.9",
"@tiptap/extension-placeholder": "^2.5.9",
"@tiptap/pm": "^2.5.9",
Expand Down
4 changes: 0 additions & 4 deletions src/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ export const EXTENSION_CONTEXT_NAME = {
twinnyOverlapSize: "twinnyOverlapSize",
twinnyRelevantFilePaths: "twinnyRelevantFilePaths",
twinnyRelevantCodeSnippets: "twinnyRelevantCodeSnippets",
twinnyVectorSearchMetric: "twinnyVectorSearchMetric",
twinnySymmetryTab: "twinnySymmetryTab",
twinnyEnableRag: "twinnyEnableRag",
}
Expand Down Expand Up @@ -338,9 +337,6 @@ export const WASM_LANGUAGES: { [key: string]: string } = {

export const DEFAULT_RELEVANT_FILE_COUNT = 10
export const DEFAULT_RELEVANT_CODE_COUNT = 5
export const DEFAULT_VECTOR_SEARCH_METRIC = "l2"

export const EMBEDDING_METRICS = ["cosine", "l2", "dot"]

export const MULTILINE_OUTSIDE = [
"class_body",
Expand Down
2 changes: 1 addition & 1 deletion src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ export interface ChunkOptions {
}

export type Embedding = {
embeddings: number[]
embeddings: [number[]]
}

export type EmbeddedDocument = {
Expand Down
15 changes: 0 additions & 15 deletions src/extension/chat-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
DEFAULT_RELEVANT_CODE_COUNT,
DEFAULT_RELEVANT_FILE_COUNT,
DEFAULT_RERANK_THRESHOLD,
DEFAULT_VECTOR_SEARCH_METRIC,
EVENT_NAME,
EXTENSION_CONTEXT_NAME,
EXTENSION_SESSION_NAME,
Expand Down Expand Up @@ -118,18 +117,11 @@ export class ChatService extends Base {
) as number
const relevantFileCount = Number(stored) || DEFAULT_RELEVANT_FILE_COUNT

const storedMetric = this._context?.globalState.get(
`${EVENT_NAME.twinnyGlobalContext}-${EXTENSION_CONTEXT_NAME.twinnyVectorSearchMetric}`
) as number

const metric = storedMetric || DEFAULT_VECTOR_SEARCH_METRIC

const filePaths =
(await this._db.getDocuments(
embedding,
relevantFileCount,
table,
metric as "cosine" | "l2" | "dot"
)) || []

if (!filePaths.length) return []
Expand Down Expand Up @@ -226,11 +218,6 @@ export class ChatService extends Base {

if (!embedding) return ""

const storedMetric = this._context?.globalState.get(
`${EVENT_NAME.twinnyGlobalContext}-${EXTENSION_CONTEXT_NAME.twinnyVectorSearchMetric}`
) as number
const metric = storedMetric || DEFAULT_VECTOR_SEARCH_METRIC

const query = relevantFiles?.length
? `file IN ("${relevantFiles.map((file) => file[0]).join("\",\"")}")`
: ""
Expand All @@ -240,7 +227,6 @@ export class ChatService extends Base {
embedding,
Math.round(relevantCodeCount / 2),
table,
metric as "cosine" | "l2" | "dot",
query
)) || []

Expand All @@ -249,7 +235,6 @@ export class ChatService extends Base {
embedding,
Math.round(relevantCodeCount / 2),
table,
metric as "cosine" | "l2" | "dot"
)) || []

const documents = [...embeddedDocuments, ...queryEmbeddedDocuments]
Expand Down
Loading

0 comments on commit a57566c

Please sign in to comment.