Code Monkey home page Code Monkey logo

code-search-ai's Introduction

AI Code Search

Repo to explore approaches to code search

/specs

contains ideas, implementation strategies, use cases, test cases, and more

/chatcraft.org

tested some of the code search ideas using chatcraft.org, contains:

  • script to generate a mermaid chart of the full codebase & files, this is fed back to chatcraft to be used in prompts
  • gpt prompt to tell gpt to navigate to the correct files given a query & mermaid chart
  • script to copy/format/truncate code files to copy/paste into chatcraft

demo:

Demo

TODO

  • test cosine similarity search on codefile summaries as a way to find the revelant code files faster
  • write some code that takes all the files from a codebase and store it in a codebase for usage on the above cosine similarity search retrieval

code-search-ai's People

Contributors

steven4354 avatar

Stargazers

 avatar

Watchers

 avatar

code-search-ai's Issues

store code files into postgres

I am a helpful assistant! How can I help?


i want to store file path info into a database along with the code for each file

what are some good ways i could do this?

the database could be mongodb or postgres


There are several ways to store file path information and code in a database. I'll provide examples for both MongoDB and PostgreSQL.

MongoDB

MongoDB is a NoSQL database, which stores data in a flexible, JSON-like format called BSON. You can use the following schema to store file path information and code:

{
  "file_path": "path/to/your/file.ext",
  "file_name": "file.ext",
  "code": "your code here"
}

To insert a document with this schema, you can use the following code snippet:

const MongoClient = require('mongodb').MongoClient;
const uri = "mongodb+srv://<username>:<password>@cluster0.mongodb.net/test?retryWrites=true&w=majority";
const client = new MongoClient(uri, { useNewUrlParser: true, useUnifiedTopology: true });

client.connect(err => {
  const collection = client.db("test").collection("file_info");
  const fileInfo = {
    file_path: "path/to/your/file.ext",
    file_name: "file.ext",
    code: "your code here"
  };
  collection.insertOne(fileInfo, (err, res) => {
    if (err) throw err;
    console.log("File info inserted");
    client.close();
  });
});

PostgreSQL

PostgreSQL is a powerful, open-source object-relational database system. You can create a table to store file path information and code like this:

CREATE TABLE file_info (
  id SERIAL PRIMARY KEY,
  file_path VARCHAR(255) NOT NULL,
  file_name VARCHAR(255) NOT NULL,
  code TEXT NOT NULL
);

To insert a row with file path information and code, you can use the following SQL query:

INSERT INTO file_info (file_path, file_name, code)
VALUES ('path/to/your/file.ext', 'file.ext', 'your code here');

Here's a code snippet using node-postgres to insert file information into the PostgreSQL database:

const { Client } = require('pg');

const client = new Client({
  connectionString: "postgres://<username>:<password>@localhost:5432/<database>"
});

client.connect();

const fileInfo = {
  file_path: "path/to/your/file.ext",
  file_name: "file.ext",
  code: "your code here"
};

const query = `
  INSERT INTO file_info (file_path, file_name, code)
  VALUES ($1, $2, $3)
`;

client.query(query, [fileInfo.file_path, fileInfo.file_name, fileInfo.code], (err, res)...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.